Homepage API: add ?format=roku
support (#1655)
Formatting changes for Roku to parse the data properly. `https://github.com/OdyseeTeam/odysee-homepages/issues/1570`
This commit is contained in:
parent
e5bea1d0c4
commit
baf1058510
2 changed files with 16 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const memo = {};
|
const memo = {};
|
||||||
|
|
||||||
|
const FORMAT = { ROKU: 'roku' };
|
||||||
|
|
||||||
const loadAnnouncements = (homepageKeys) => {
|
const loadAnnouncements = (homepageKeys) => {
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const announcements = {};
|
const announcements = {};
|
||||||
|
@ -44,7 +46,15 @@ const getHomepageJsonV1 = () => {
|
||||||
return v1;
|
return v1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getHomepageJsonV2 = () => {
|
const reformatV2Categories = (categories, format) => {
|
||||||
|
if (format === FORMAT.ROKU) {
|
||||||
|
return categories && Object.entries(categories).map(([key, value]) => value);
|
||||||
|
} else {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHomepageJsonV2 = (format) => {
|
||||||
if (!memo.homepageData) {
|
if (!memo.homepageData) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -53,7 +63,8 @@ const getHomepageJsonV2 = () => {
|
||||||
const homepageKeys = Object.keys(memo.homepageData);
|
const homepageKeys = Object.keys(memo.homepageData);
|
||||||
homepageKeys.forEach((hp) => {
|
homepageKeys.forEach((hp) => {
|
||||||
v2[hp] = {
|
v2[hp] = {
|
||||||
...memo.homepageData[hp],
|
categories: reformatV2Categories(memo.homepageData[hp].categories, format),
|
||||||
|
meme: memo.homepageData[hp].meme,
|
||||||
announcement: memo.announcements[hp],
|
announcement: memo.announcements[hp],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,8 +8,10 @@ async function getHomepage(ctx, version) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const format = ctx?.request?.query?.format;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = version === 1 ? getHomepageJsonV1() : getHomepageJsonV2();
|
const content = version === 1 ? getHomepageJsonV1() : getHomepageJsonV2(format);
|
||||||
ctx.set('Content-Type', 'application/json');
|
ctx.set('Content-Type', 'application/json');
|
||||||
ctx.set('Access-Control-Allow-Origin', '*');
|
ctx.set('Access-Control-Allow-Origin', '*');
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
|
Loading…
Reference in a new issue