Skip to content

Commit

Permalink
Add media endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbeckman committed May 10, 2018
1 parent f906c17 commit 844c3b3
Show file tree
Hide file tree
Showing 4 changed files with 631 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const config = {
syndicateTo: parseJSONList(env[prefix + 'SITE_SYNDICATE_TO'])
},
sites: parseJSON(env[prefix + 'SITES_JSON']) || false,
mediaEndpoint: env[prefix + 'MEDIA_ENDPOINT'],
token: env[prefix + 'TOKEN_ENDPOINT']
? [{
endpoint: env[prefix + 'TOKEN_ENDPOINT'],
Expand Down
28 changes: 25 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ app.use('/micropub/:targetsite', micropub({
tokenReference: req => (req.targetsite.token || []).concat(config.token),
queryHandler: (q, req) => {
if (q === 'config') {
const config = {};

if (req.targetsite.syndicateTo) { config['syndicate-to'] = req.targetsite.syndicateTo; }
let config = {};
if (req.targetsite.syndicateTo) {
config['syndicate-to'] = req.targetsite.syndicateTo;
}
if (req.targetsite.mediaEndpoint) {
config['media-endpoint'] = req.targetsite.mediaEndpoint;
}

return config;
} else if (q === 'syndicate-to') {
Expand All @@ -61,6 +65,24 @@ app.use('/micropub/:targetsite', micropub({
req.targetsite.url,
options
).then(function (url) {
logger.debug('Redirecting to post URL', url || '_');
if (url) {
return { url: url };
}
});
},
mediaHandler: (micropubDocument, req) => {
logger.debug({ micropubDocument: JSON.stringify(micropubDocument, null, 2) }, 'Received a Micropub media document');

const options = Object.assign({}, config.handlerOptions, req.targetsite.options || {});

return handler(
Object.assign({}, config.github, req.targetsite.github),
micropubDocument,
req.targetsite.url,
options
).then(function (url) {
logger.debug('Redirecting to media URL', url || '_');
if (url) {
return { url: url };
}
Expand Down
Loading

0 comments on commit 844c3b3

Please sign in to comment.