rsshub
Version:
Make RSS Great Again!
94 lines (92 loc) • 3.14 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import { t as logger_default } from "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./render-BQo6B4tL.mjs";
import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs";
import { i as processWork, t as baseUrl } from "./utils-BrYAWfDx.mjs";
//#region lib/routes/skeb/works.ts
const route = {
path: "/works/:username",
categories: ["picture"],
example: "/skeb/works/@brm2_1925",
parameters: { username: "Skeb Username with @" },
features: {
requireConfig: [{
name: "SKEB_BEARER_TOKEN",
optional: false,
description: "在瀏覽器開發者工具(F12)的主控台中輸入 `localStorage.getItem(\"token\")` 獲取"
}],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
nsfw: true
},
name: "Creator Works",
maintainers: ["SnowAgar25"],
handler,
radar: [{
title: "Creator Works",
source: ["skeb.jp/:username"],
target: "/works/:username"
}],
description: "Get the latest works of a specific creator on Skeb"
};
async function handler(ctx) {
const username = ctx.req.param("username");
if (!config.skeb || !config.skeb.bearerToken) throw new config_not_found_default("Skeb works RSS is disabled due to the lack of <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config</a>");
const url = `${baseUrl}/api/users/${username.replace("@", "")}/works`;
await ensureRequestKey(url);
const items = await cache_default.tryGet(url, async () => {
const data = await ofetch_default(url, {
retry: 0,
method: "GET",
query: {
role: "creator",
sort: "date",
offset: "0"
},
headers: {
"User-Agent": config.ua,
Cookie: `request_key=${await cache_default.get("skeb:request_key")}`,
Authorization: `Bearer ${config.skeb.bearerToken}`
}
});
if (!data || !Array.isArray(data)) throw new Error("Invalid data received from API");
return data.map((item) => processWork(item)).filter(Boolean);
});
return {
title: `Skeb - ${username}'s Works`,
link: `${baseUrl}/${username}`,
item: items
};
}
function hasResponseData(error) {
return error !== null && typeof error === "object" && "response" in error && typeof error.response?._data === "string";
}
async function ensureRequestKey(url) {
if (await cache_default.get("skeb:request_key")) return;
try {
await ofetch_default(url, {
retry: 0,
headers: {
"User-Agent": config.ua,
Authorization: `Bearer ${config.skeb.bearerToken}`
}
});
} catch (error) {
if (hasResponseData(error)) {
const newRequestKey = error.response?._data?.match(/request_key=(.*?);/)?.[1];
if (newRequestKey) {
cache_default.set("skeb:request_key", newRequestKey);
logger_default.debug(`Retrieved new request_key: ${newRequestKey}`);
} else logger_default.error("Failed to extract request_key from error response");
}
}
}
//#endregion
export { route };