fixed regex and oebed url creator

This commit is contained in:
bill bittner 2018-07-27 15:56:56 -07:00
parent 99cdfc0c8d
commit 67e7a6f5b9
4 changed files with 35 additions and 4 deletions

View file

@ -8,7 +8,7 @@ var rel = 'alternate';
var title = 'spee.ch oEmbed profile';
var formatUrlForQuery = function formatUrlForQuery(url) {
return url.replace(/\/+/, '%2F').replace(/:/, '%3A');
return url.replace(/\//g, '%2F').replace(/:/g, '%3A');
};
var createJsonLinkData = function createJsonLinkData(host, canonicalUrl) {
@ -24,7 +24,7 @@ var createXmlLinkData = function createXmlLinkData(host, canonicalUrl) {
return {
rel: rel,
type: 'application/xml+oembed',
href: "".concat(host, "/api/oembed?").concat(formatUrlForQuery(canonicalUrl), "%2F&format=xml"),
href: "".concat(host, "/api/oembed?url=").concat(formatUrlForQuery(canonicalUrl), "%2F&format=xml"),
title: title
};
};

View file

@ -2,7 +2,7 @@ const rel = 'alternate';
const title = 'spee.ch oEmbed profile';
const formatUrlForQuery = (url) => {
return url.replace(/\/+/, '%2F').replace(/:/, '%3A');
return url.replace(/\//g, '%2F').replace(/:/g, '%3A');
};
const createJsonLinkData = (host, canonicalUrl) => {
@ -18,7 +18,7 @@ const createXmlLinkData = (host, canonicalUrl) => {
return {
rel,
type: 'application/xml+oembed',
href: `${host}/api/oembed?${formatUrlForQuery(canonicalUrl)}%2F&format=xml`,
href: `${host}/api/oembed?url=${formatUrlForQuery(canonicalUrl)}%2F&format=xml`,
title,
};
};

View file

@ -0,0 +1,28 @@
const logger = require('winston');
const db = require('../../../models');
const getOEmbedData = (req, res) => {
logger.debug('req', req.query);
res.status(200).json({
success: true,
message: 'hello',
data: req.query,
});
// db.Blocked.refreshTable()
// .then(data => {
// logger.info('finished updating blocked content list');
// res.status(200).json({
// success: true,
// data,
// });
// })
// .catch(error => {
// logger.error(error);
// res.status(500).json({
// success: false,
// error,
// });
// });
};
module.exports = getOEmbedData;

View file

@ -19,6 +19,7 @@ const userPassword = require('../../controllers/api/user/password');
const publishingConfig = require('../../controllers/api/config/site/publishing');
const getTorList = require('../../controllers/api/tor');
const getBlockedList = require('../../controllers/api/blocked');
const getOEmbedData = require('../../controllers/api/oEmbed');
module.exports = (app) => {
@ -46,4 +47,6 @@ module.exports = (app) => {
app.get('/api/tor', torCheckMiddleware, getTorList);
// blocked
app.get('/api/blocked', torCheckMiddleware, getBlockedList);
// open embed
app.get('/api/oembed', torCheckMiddleware, getOEmbedData)
};