moved speech url parser to own file

This commit is contained in:
bill bittner 2018-07-30 16:50:36 -07:00
parent e22b676581
commit 76a3af4522
3 changed files with 25 additions and 25 deletions

View file

@ -1,8 +1,6 @@
const logger = require('winston');
const db = require('../../../models');
const getOEmbedDataForChannel = (channelName, channelClaimId) => {
logger.debug('get oembed for channel:', `${channelName}:${channelClaimId}`);
return db.Certificate
.findOne({
where: {

View file

@ -3,29 +3,7 @@ const lbryUri = require('../../utils/lbryUri');
const getOEmbedDataForChannel = require('./getOEmbedDataForChannel');
const getOEmbedDataForAsset = require('./getOEmbedDataForAsset');
const parseSpeechUrl = (url) => {
// parse the request url
const componentsRegex = new RegExp(
'([^:/?#]+:\/\/)'+
'([^/?#]*)' +
'(\/)' +
'([^/?#]*)' +
'(\/)' +
'([^/?#]*)'
);
const [proto, protocol, domain, slashOne, paramOne, slashTwo, paramTwo] = componentsRegex
.exec(url)
.map(match => match || null);
logger.debug(`${protocol}, ${domain}, ${slashOne}, ${paramOne}, ${slashTwo}, ${paramTwo}`);
return {
paramOne,
paramTwo,
}
};
const parseSpeechUrl = require('./parseSpeechUrl');
const getOEmbedData = (req, res) => {

View file

@ -0,0 +1,24 @@
const logger = require('winston');
const parseSpeechUrl = (url) => {
const componentsRegex = new RegExp(
'([^:/?#]+://)' +
'([^/?#]*)' +
'(/)' +
'([^/?#]*)' +
'(/)' +
'([^/?#]*)'
);
const [, , , , paramOne, , paramTwo] = componentsRegex
.exec(url)
.map(match => match || null);
logger.debug(`params from speech url: ${paramOne} ${paramTwo}`);
return {
paramOne,
paramTwo,
};
};
module.exports = parseSpeechUrl;