From cb8298a8bfc25430b2244e843489d2610f7ab141 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=99=8E=E6=95=85=E6=B4=9E?=
<55782476+TigerCubDen@users.noreply.github.com>
Date: Sun, 14 Feb 2021 21:25:26 +0800
Subject: [PATCH] Create submission_comments.js
---
lib/routes/furaffinity/submission_comments.js | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 lib/routes/furaffinity/submission_comments.js
diff --git a/lib/routes/furaffinity/submission_comments.js b/lib/routes/furaffinity/submission_comments.js
new file mode 100644
index 0000000000..2bcd454d54
--- /dev/null
+++ b/lib/routes/furaffinity/submission_comments.js
@@ -0,0 +1,50 @@
+const got = require('@/utils/got');
+
+module.exports = async (ctx) => {
+ //传入参数
+ const id = String(ctx.params.id);
+
+ // 发起 HTTP GET 请求
+ const response = await got({
+ method: 'get',
+ url: `https://faexport.spangle.org.uk/submission/${id}/comments.json`,
+ headers: {
+ Referer: `https://faexport.spangle.org.uk/`,
+ },
+ });
+
+ //发起第二个 HTTP GET 请求,用于获取该作品的标题
+ const response2 = await got({
+ method: 'get',
+ url: `https://faexport.spangle.org.uk/submission/${id}.json`,
+ headers: {
+ Referer: `https://faexport.spangle.org.uk/`,
+ },
+ });
+
+ const data = response.data;
+ const data2 = response2.data;
+
+ ctx.state.data = {
+ // 源标题
+ title: `${data2.title} - Submission Comments`,
+ // 源链接
+ link: `https://www.furaffinity.net/view/${id}/`,
+ // 源说明
+ description: `Fur Affinity ${data2.title} - Submission Comments`,
+
+ //遍历此前获取的数据
+ item: data.map((item) => ({
+ // 标题
+ title: item.text,
+ // 正文
+ description: `
${item.name}: ${item.text}`,
+ // 链接
+ link: `https://www.furaffinity.net/view/${id}/`,
+ //作者
+ author: item.name,
+ //日期
+ pubDate: new Date(item.posted_at).toUTCString(),
+ })),
+ }
+};