lbry-desktop/web/src/homepageApi.js
infinite-persistence 45bb9ad0fa Homepage API v2: includes meme
Ticket: 1318

Had to create v2 as there is no backward-compatible location in the v1 json to place it.

v2 allows any future expansion beyond 'categories' and 'meme'.

One-meme-per-homepage is also supported, but not enabled for now.
2022-04-15 09:25:08 -04:00

27 lines
702 B
JavaScript

const { CUSTOM_HOMEPAGE } = require('../../config');
const { getHomepageJsonV1, getHomepageJsonV2 } = require('./getHomepageJSON');
async function getHomepage(ctx, version) {
if (!CUSTOM_HOMEPAGE) {
ctx.status = 404;
ctx.body = { message: 'Not Found' };
return;
}
try {
const content = version === 1 ? getHomepageJsonV1() : getHomepageJsonV2();
ctx.set('Content-Type', 'application/json');
ctx.set('Access-Control-Allow-Origin', '*');
ctx.body = {
status: 'success',
data: content,
};
} catch (err) {
ctx.status = err.statusCode || err.status || 500;
ctx.body = {
message: err.message,
};
}
}
module.exports = { getHomepage };