spee.ch/server/controllers/api/oEmbed/index.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-07-28 00:56:56 +02:00
const logger = require('winston');
const db = require('../../../models');
const getOEmbedData = (req, res) => {
2018-07-28 03:40:57 +02:00
const CHANNEL_CHAR = '@';
const { query: { url, format } } = req;
logger.debug('req url', url);
logger.debug('req format', format);
// parse the request url
const componentsRegex = new RegExp(
'([^:/?#]+:\/\/)'+
'([^/?#]*)' +
'(\/)' +
2018-07-30 19:02:08 +02:00
'([^/?#]*)' +
2018-07-28 03:40:57 +02:00
'(\/)' +
2018-07-30 19:02:08 +02:00
'([^/?#]*)'
2018-07-28 03:40:57 +02:00
);
const [proto, protocol, domain, slashOne, paramOne, slashTwo, paramTwo] = componentsRegex
.exec(url)
.map(match => match || null);
logger.debug(`${protocol}, ${domain}, ${slashOne}, ${paramOne}, ${slashTwo}, ${paramTwo}`);
// parse the request url's pieces
// is there an identifier?
// if there is an identifier, is it a channel or a claim_id?
// if it is a channel, does it have a channel id?
// if no identifier, is the claim a channel?
// get the data
const data = {
version: 1.0 ,
author_name: 'Spee.ch',
author_url: 'https://spee.ch',
provider_name: 'Spee.ch',
provider_url: 'https://spee.ch',
cache_age: 86400, // one day in seconds
};
// set type
// if (fileType.substring(0, fileType.indexOf('/') === 'video')) {
// data['type'] = 'video';
// } else {
// data['type'] = 'picture';
// }
data['title'] = '';
data['thumbnail_url'] = '';
data['thumbnail_width'] = '';
data['thumbnail_height'] = '';
2018-07-28 00:56:56 +02:00
res.status(200).json({
success: true,
message: 'hello',
2018-07-28 03:40:57 +02:00
data,
2018-07-28 00:56:56 +02:00
});
};
module.exports = getOEmbedData;