const config = require('@/config').value;
const got = require('@/utils/got');
const wait = require('@/utils/wait');
let cacheIndex = 0;
module.exports = async (ctx) => {
if (ctx.params.id === 'error') {
throw new Error('Error test');
}
if (ctx.params.id === 'httperror') {
await got({
method: 'get',
url: 'https://httpbingo.org/status/404',
});
}
let item = [];
switch (ctx.params.id) {
case 'filter':
item = [
{
title: 'Filter Title1',
description: 'Description1',
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/-1`,
author: `DIYgod0`,
category: ['Category0', 'Category1'],
},
{
title: 'Filter Title2',
description: 'Description2',
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/0`,
author: `DIYgod0`,
category: ['Category0', 'Category1', 'Category2'],
},
{
title: 'Filter Title3',
description: 'Description3',
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/1`,
author: `DIYgod0`,
category: 'Category3',
},
];
break;
case 'filter-illegal-category':
item.push({
title: 'TitleIllegal',
description: 'DescriptionIllegal',
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/1`,
author: `DIYgod0`,
category: [1, 'CategoryIllegal', true, null, undefined, { type: 'object' }],
});
break;
case 'long':
item.push({
title: `Long Title `.repeat(50),
description: `Long Description `.repeat(10),
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/0`,
author: `DIYgod0`,
});
break;
case 'cache': {
const description = await ctx.cache.tryGet(
'test',
() => ({
text: `Cache${++cacheIndex}`,
}),
config.cache.routeExpire * 2
);
item.push({
title: 'Cache Title',
description: description.text,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/0`,
author: `DIYgod0`,
});
break;
}
case 'refreshCache': {
let refresh = await ctx.cache.get('refreshCache');
let noRefresh = await ctx.cache.get('noRefreshCache', false);
if (!refresh) {
refresh = '0';
await ctx.cache.set('refreshCache', '1');
}
if (!noRefresh) {
noRefresh = '0';
await ctx.cache.set('noRefreshCache', '1', undefined);
}
item.push({
title: 'Cache Title',
description: refresh + ' ' + noRefresh,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/0`,
author: `DIYgod0`,
});
break;
}
case 'cacheUrlKey': {
const description = await ctx.cache.tryGet(
new URL('https://rsshub.app'),
() => ({
text: `Cache${++cacheIndex}`,
}),
config.cache.routeExpire * 2
);
item.push({
title: 'Cache Title',
description: description.text,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://github.com/DIYgod/RSSHub/issues/0`,
author: `DIYgod0`,
});
break;
}
case 'complicated':
item.push(
{
title: `Complicated Title`,
description: `
`,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `//mock.com/DIYgod/RSSHub`,
author: `DIYgod`,
},
{
title: `Complicated Title`,
description: `
`,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://mock.com/DIYgod/RSSHub`,
author: `DIYgod`,
}
);
break;
case 'multimedia':
item.push({
title: `Multimedia Title`,
description: `
`,
pubDate: new Date(`2019-3-1`).toUTCString(),
link: `https://mock.com/DIYgod/RSSHub`,
author: `DIYgod`,
});
break;
case 'sort':
item.push(
{
title: `Sort Title 0`,
link: `https://github.com/DIYgod/RSSHub/issues/s1`,
author: `DIYgod0`,
},
{
title: `Sort Title 1`,
link: `https://github.com/DIYgod/RSSHub/issues/s1`,
author: `DIYgod0`,
},
{
title: `Sort Title 2`,
link: `https://github.com/DIYgod/RSSHub/issues/s2`,
pubDate: new Date(1_546_272_000_000 - 10 * 10 * 1000).toUTCString(),
author: `DIYgod0`,
},
{
title: `Sort Title 3`,
link: `https://github.com/DIYgod/RSSHub/issues/s3`,
pubDate: new Date(1_546_272_000_000).toUTCString(),
author: `DIYgod0`,
}
);
break;
case 'mess':
item.push({
title: `Mess Title`,
link: `/DIYgod/RSSHub/issues/0`,
pubDate: 1_546_272_000_000,
author: `DIYgod0`,
});
break;
case 'opencc':
item.push({
title: '小可愛',
description: '宇宙無敵',
link: `/DIYgod/RSSHub/issues/0`,
pubDate: new Date(1_546_272_000_000).toUTCString(),
author: `DIYgod0`,
});
break;
case 'brief':
item.push({
title: '小可愛',
description: '
宇宙無敵