2023-01-13 05:40:33 +01:00
|
|
|
import Parser from "rss-parser";
|
|
|
|
import { getResponse } from "@/misc/fetch.js";
|
|
|
|
import config from "@/config/index.js";
|
|
|
|
import define from "../define.js";
|
2022-07-02 14:26:33 +02:00
|
|
|
|
|
|
|
const rssParser = new Parser();
|
|
|
|
|
|
|
|
export const meta = {
|
2023-01-13 05:40:33 +01:00
|
|
|
tags: ["meta"],
|
2022-07-02 14:26:33 +02:00
|
|
|
|
|
|
|
requireCredential: false,
|
|
|
|
allowGet: true,
|
|
|
|
cacheSec: 60 * 3,
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export const paramDef = {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
2022-07-02 14:26:33 +02:00
|
|
|
properties: {
|
2023-01-13 05:40:33 +01:00
|
|
|
url: { type: "string" },
|
2022-07-02 14:26:33 +02:00
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
required: ["url"],
|
2022-07-02 14:26:33 +02:00
|
|
|
} as const;
|
|
|
|
|
|
|
|
export default define(meta, paramDef, async (ps) => {
|
|
|
|
const res = await getResponse({
|
|
|
|
url: ps.url,
|
2023-01-13 05:40:33 +01:00
|
|
|
method: "GET",
|
2022-07-02 14:26:33 +02:00
|
|
|
headers: Object.assign({
|
2023-01-13 05:40:33 +01:00
|
|
|
"User-Agent": config.userAgent,
|
|
|
|
Accept: "application/rss+xml, */*",
|
2022-07-02 14:26:33 +02:00
|
|
|
}),
|
|
|
|
timeout: 5000,
|
|
|
|
});
|
|
|
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
|
|
|
return rssParser.parseString(text);
|
|
|
|
});
|