moved speech url parser to own file
This commit is contained in:
parent
e22b676581
commit
76a3af4522
3 changed files with 25 additions and 25 deletions
|
@ -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: {
|
||||
|
|
|
@ -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) => {
|
||||
|
||||
|
|
24
server/controllers/api/oEmbed/parseSpeechUrl.js
Normal file
24
server/controllers/api/oEmbed/parseSpeechUrl.js
Normal 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;
|
Loading…
Reference in a new issue