rsshub
Version:
Make RSS Great Again!
77 lines (75 loc) • 2.75 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import { t as isValidHost } from "./valid-host-C-u5eW3j.mjs";
//#region lib/routes/lofter/user.ts
const route = {
path: "/user/:name?",
categories: ["social-media"],
example: "/lofter/user/i",
view: ViewType.Articles,
parameters: { name: "Lofter user name, can be found in the URL" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "User",
maintainers: [
"hondajojo",
"nczitzk",
"LucunJi"
],
handler
};
async function handler(ctx) {
const name = ctx.req.param("name") ?? "i";
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : "50";
if (!isValidHost(name)) throw new invalid_parameter_default("Invalid name");
const rootUrl = `${name}.lofter.com`;
const response = await got_default({
method: "post",
url: `http://api.lofter.com/v2.0/blogHomePage.api?product=lofter-iphone-10.0.0`,
body: new URLSearchParams({
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 new Error("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) => {
if (photo.raw?.match(/\/\/nos\.netease\.com\//)) photo.raw = `https://${photo.raw.match(/(imglf\d)/)[0]}.lf127.net${photo.raw.match(/\/\/nos\.netease\.com\/imglf\d(.*)/)[1]}`;
return `<img src="${photo.raw || photo.orign}">`;
}).join("") + JSON.parse(item.post.embed ? `[${item.post.embed}]` : `[]`).map((video) => `<video src="${video.originUrl}" poster="${video.video_img_url}" controls="controls"></video>`).join("") + item.post.content,
pubDate: parseDate(item.post.publishTime),
author: item.post.blogInfo.blogNickName,
category: item.post.tag.split(",")
}));
return {
title: `${items[0].author} | LOFTER`,
link: `https://${rootUrl}`,
item: items,
description: response.data.response.posts[0].post.blogInfo.selfIntro
};
}
//#endregion
export { route };