const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const name = ctx.params.name ?? 'i';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : '50';
const rootUrl = `${name}.lofter.com`;
const response = await got({
method: 'post',
url: `http://api.lofter.com/v2.0/blogHomePage.api?product=lofter-iphone-10.0.0`,
form: {
blogdomain: rootUrl,
checkpwd: '1',
following: '0',
limit,
method: 'getPostLists',
needgetpoststat: '1',
offset: '0',
postdigestnew: '1',
supportposttypes: '1,2,3,4,5,6',
},
});
if (!response.data.response || response.data.response.posts.length === 0) {
throw 'Blog Not Found';
}
const items = response.data.response.posts.map((item) => ({
title: item.post.title || item.post.noticeLinkTitle,
link: item.post.blogPageUrl,
description:
JSON.parse(item.post.photoLinks || `[]`)
.map((photo) => `
`)
.join('') +
JSON.parse(item.post.embed ? `[${item.post.embed}]` : `[]`)
.map((video) => ``)
.join('') +
item.post.content,
pubDate: parseDate(item.post.publishTime),
author: item.post.blogInfo.blogNickName,
category: item.post.tag.split(','),
}));
ctx.state.data = {
title: `${items[0].author} | LOFTER`,
link: rootUrl,
item: items,
description: response.data.response.posts[0].post.blogInfo.selfIntro,
};
};