feat: 新增豆瓣新片榜 & add ESLint
This commit is contained in:
parent
813e88c993
commit
6330914d09
19
.eslintrc.json
Normal file
19
.eslintrc.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": ["eslint:recommended", "plugin:vue/vue3-essential"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["vue"],
|
||||
"rules": {},
|
||||
"globals": {
|
||||
"require": true,
|
||||
"module": true,
|
||||
"process": true,
|
||||
"__dirname": true
|
||||
}
|
||||
}
|
8
.prettierrc.json
Normal file
8
.prettierrc.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/prettierrc",
|
||||
"singleQuote": false,
|
||||
"trailingComma": "all",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"printWidth": 100
|
||||
}
|
@ -24,9 +24,10 @@
|
||||
| 百度 | 热搜榜 | baidu | 🟢 |
|
||||
| 抖音 | 热点榜 | douyin / douyin_new | 🟢 |
|
||||
| 抖音 | 热歌榜 | douyin_music | 🟢 |
|
||||
| 豆瓣 | 新片榜 | douban_new | 🟢 |
|
||||
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
||||
| 少数派 | 热榜 | sspai | 🟢 |
|
||||
| IT 之家 | 热榜 | ithome | 🟢 |
|
||||
| IT 之家 | 热榜 | ithome | 🟠 |
|
||||
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
||||
| 今日头条 | 热榜 | toutiao | 🟢 |
|
||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
||||
@ -59,7 +60,7 @@ GET https://example.com/calendar/date?month=06&day=01
|
||||
|
||||
## 部署
|
||||
|
||||
```js
|
||||
```bash
|
||||
// 安装依赖
|
||||
pnpm install
|
||||
|
||||
|
2
index.js
2
index.js
@ -24,7 +24,7 @@ app.use(views(__dirname + "/public"));
|
||||
app.use(
|
||||
cors({
|
||||
origin: domain,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
app.use(async (ctx, next) => {
|
||||
|
@ -4,6 +4,8 @@
|
||||
"description": "一个今日热榜",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||
"start": "node index.js",
|
||||
"dev": "npx nodemon index.js",
|
||||
"prd": "pm2 start index.js",
|
||||
@ -22,6 +24,9 @@
|
||||
"koa-views": "^8.0.0",
|
||||
"koa2-cors": "^2.0.6",
|
||||
"node-cache": "^5.1.2",
|
||||
"nodemon": "^2.0.22"
|
||||
"nodemon": "^2.0.22",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-plugin-vue": "^9.17.0",
|
||||
"prettier": "^3.0.2"
|
||||
}
|
||||
}
|
||||
|
1970
pnpm-lock.yaml
1970
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>404 | Linkbook API</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
href="https://img.imsyy.top/logo/imsyy.png"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
<link rel="shortcut icon" href="https://img.imsyy.top/logo/imsyy.png" type="image/x-icon" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
||||
@ -38,7 +34,9 @@
|
||||
background-color: var(--text-color-hover);
|
||||
color: var(--text-color);
|
||||
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
||||
transition: background-color 0.5s, color 0.5s;
|
||||
transition:
|
||||
background-color 0.5s,
|
||||
color 0.5s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@ -149,16 +147,12 @@
|
||||
<a href="https://imsyy.top/" target="_blank">無名</a>
|
||||
</div>
|
||||
<div class="icp">
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"
|
||||
>豫ICP备2022018134号-1</a
|
||||
>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2022018134号-1</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script>
|
||||
// 跟随系统主题
|
||||
const darkModeMediaQuery = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const toggleDarkMode = (darkModeMediaQuery) => {
|
||||
if (darkModeMediaQuery.matches) {
|
||||
document.documentElement.classList.add("dark-mode");
|
||||
|
@ -1,13 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>DailyHot API</title>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
href="./favicon.svg"
|
||||
type="image/x-icon"
|
||||
/>
|
||||
<link rel="shortcut icon" href="./favicon.svg" type="image/x-icon" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
||||
@ -38,7 +34,9 @@
|
||||
background-color: var(--text-color-hover);
|
||||
color: var(--text-color);
|
||||
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
||||
transition: background-color 0.5s, color 0.5s;
|
||||
transition:
|
||||
background-color 0.5s,
|
||||
color 0.5s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@ -155,16 +153,12 @@
|
||||
<a href="https://imsyy.top/" target="_blank">無名</a>
|
||||
</div>
|
||||
<div class="icp">
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"
|
||||
>豫ICP备2022018134号-1</a
|
||||
>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2022018134号-1</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script>
|
||||
// 跟随系统主题
|
||||
const darkModeMediaQuery = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const toggleDarkMode = (darkModeMediaQuery) => {
|
||||
if (darkModeMediaQuery.matches) {
|
||||
document.documentElement.classList.add("dark-mode");
|
||||
|
@ -20,7 +20,7 @@ const getData = (data) => {
|
||||
if (!data) return [];
|
||||
const dataList = [];
|
||||
try {
|
||||
const pattern = /<\!--s-data:(.*?)-->/s;
|
||||
const pattern = /<!--s-data:(.*?)-->/s;
|
||||
const matchResult = data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
|
||||
jsonObject.forEach((v) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const Router = require("koa-router");
|
||||
const calendarRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
const { get, set } = require("../utils/cacheData");
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "calendarData";
|
||||
@ -96,7 +96,7 @@ calendarRouter.get("/calendar/date", async (ctx) => {
|
||||
}
|
||||
// 从服务器拉取最新数据
|
||||
const response = await axios.get(
|
||||
`https://baike.baidu.com/cms/home/eventsOnHistory/${month}.json`
|
||||
`https://baike.baidu.com/cms/home/eventsOnHistory/${month}.json`,
|
||||
);
|
||||
const newData = getData(response.data[month][month + day]);
|
||||
updateTime = new Date().toISOString();
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* @author: MyFaith
|
||||
* @date: 2023-09-06
|
||||
* @customEditors: imsyy
|
||||
* @lastEditTime: 2023-09-06
|
||||
*/
|
||||
|
||||
const Router = require("koa-router");
|
||||
const doubanNewRouter = new Router();
|
||||
const axios = require("axios");
|
||||
@ -8,7 +15,7 @@ const { get, set, del } = require("../utils/cacheData");
|
||||
const routerInfo = {
|
||||
name: "douban",
|
||||
title: "豆瓣",
|
||||
subtitle: "新片榜"
|
||||
subtitle: "新片榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
@ -20,7 +27,8 @@ let updateTime = new Date().toISOString();
|
||||
// 调用路径
|
||||
const url = "https://movie.douban.com/chart/";
|
||||
const headers = {
|
||||
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1"
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
|
||||
};
|
||||
|
||||
// 豆瓣新片榜单特殊处理 - 标题
|
||||
@ -45,7 +53,7 @@ const getData = (data) => {
|
||||
comments: $(item).find("span.pl").text().match(/\d+/)[0] ?? "",
|
||||
pic: $(item).find("img").attr("src") ?? "",
|
||||
url: $(item).find("a").attr("href") ?? "",
|
||||
mobileUrl: `https://m.douban.com/movie/subject/${id}`
|
||||
mobileUrl: `https://m.douban.com/movie/subject/${id}`,
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
@ -73,7 +81,7 @@ doubanNewRouter.get("/douban_new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败"
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
}
|
||||
@ -87,14 +95,14 @@ doubanNewRouter.get("/douban_new", async (ctx) => {
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
data
|
||||
data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败"
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
@ -116,7 +124,7 @@ doubanNewRouter.get("/douban_new/new", async (ctx) => {
|
||||
...routerInfo,
|
||||
updateTime,
|
||||
total: newData.length,
|
||||
data: newData
|
||||
data: newData,
|
||||
};
|
||||
|
||||
// 删除旧数据
|
||||
@ -134,14 +142,14 @@ doubanNewRouter.get("/douban_new/new", async (ctx) => {
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData
|
||||
data: cachedData,
|
||||
};
|
||||
} else {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败"
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ const url =
|
||||
"https://www.douyin.com/aweme/v1/web/hot/search/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&detail_list=1&round_trip_time=50";
|
||||
|
||||
// Token 获取路径
|
||||
const cookisUrl =
|
||||
"https://www.douyin.com/passport/general/login_guiding_strategy/?aid=6383";
|
||||
const cookisUrl = "https://www.douyin.com/passport/general/login_guiding_strategy/?aid=6383";
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
@ -37,9 +36,7 @@ const getData = (data) => {
|
||||
pic: `${v.word_cover.url_list[0]}`,
|
||||
hot: Number(v.hot_value),
|
||||
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(
|
||||
v.sentence_id
|
||||
)}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
|
@ -46,9 +46,7 @@ const getData = (data) => {
|
||||
pic: `${v.word_cover.url_list[0]}`,
|
||||
hot: Number(v.hot_value),
|
||||
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(
|
||||
v.sentence_id
|
||||
)}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
|
@ -129,7 +129,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
||||
...routerInfo,
|
||||
updateTime,
|
||||
total: newData.length,
|
||||
data: newData
|
||||
data: newData,
|
||||
};
|
||||
|
||||
// 删除旧数据
|
||||
@ -147,7 +147,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData
|
||||
data: cachedData,
|
||||
};
|
||||
} else {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
|
@ -17,8 +17,7 @@ const cacheKey = "juejinData";
|
||||
let updateTime = new Date().toISOString();
|
||||
|
||||
// 调用路径
|
||||
const url =
|
||||
"https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot";
|
||||
const url = "https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot";
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
|
@ -29,7 +29,7 @@ const url = "https://www.kuaishou.com/?isHome=1";
|
||||
// Unicode 解码
|
||||
const decodedString = (encodedString) => {
|
||||
return encodedString.replace(/\\u([\d\w]{4})/gi, (match, grp) =>
|
||||
String.fromCharCode(parseInt(grp, 16))
|
||||
String.fromCharCode(parseInt(grp, 16)),
|
||||
);
|
||||
};
|
||||
|
||||
@ -44,8 +44,7 @@ const getData = (data) => {
|
||||
const jsonObject = JSON.parse(matchResult[1])["defaultClient"];
|
||||
|
||||
// 获取所有分类
|
||||
const allItems =
|
||||
jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']["items"];
|
||||
const allItems = jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']["items"];
|
||||
// 遍历所有分类
|
||||
allItems.forEach((v) => {
|
||||
// 基础数据
|
||||
|
@ -34,12 +34,8 @@ const getData = (data) => {
|
||||
desc: v.sAuthor,
|
||||
pic: `https:${v.sIMG}`,
|
||||
hot: Number(v.iTotalPlay),
|
||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
||||
v.iDocID
|
||||
)}`,
|
||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
||||
v.iDocID
|
||||
)}`,
|
||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
|
@ -30,11 +30,9 @@ const getData = (data) => {
|
||||
title: v.word,
|
||||
desc: key,
|
||||
hot: v.raw_hot,
|
||||
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
||||
key
|
||||
)}&t=31&band_rank=1&Refer=top`,
|
||||
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
|
||||
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
||||
key
|
||||
key,
|
||||
)}&t=31&band_rank=1&Refer=top`,
|
||||
};
|
||||
});
|
||||
|
@ -33,9 +33,7 @@ const getData = (data) => {
|
||||
hot: v.readingCount,
|
||||
author: book.author,
|
||||
url: `https://weread.qq.com/web/bookDetail/${getWereadID(book.bookId)}`,
|
||||
mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(
|
||||
book.bookId
|
||||
)}`,
|
||||
mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(book.bookId)}`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
@ -2,7 +2,6 @@ const Router = require("koa-router");
|
||||
const zhihuRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
const router = require(".");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
@ -28,8 +27,7 @@ const getData = (data) => {
|
||||
if (!data) return [];
|
||||
const dataList = [];
|
||||
try {
|
||||
const pattern =
|
||||
/<script id="js-initialData" type="text\/json">(.*?)<\/script>/;
|
||||
const pattern = /<script id="js-initialData" type="text\/json">(.*?)<\/script>/;
|
||||
const matchResult = data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).initialState.topstory.hotList;
|
||||
jsonObject.forEach((v) => {
|
||||
|
@ -47,8 +47,7 @@ const getWereadID = (bookId) => {
|
||||
const subLength = sub.length.toString(16);
|
||||
|
||||
// 如果长度只有一位数,则在前面添加0
|
||||
const subLengthPadded =
|
||||
subLength.length === 1 ? "0" + subLength : subLength;
|
||||
const subLengthPadded = subLength.length === 1 ? "0" + subLength : subLength;
|
||||
|
||||
// 将长度和子字符串添加到初始值中
|
||||
strSub += subLengthPadded + sub;
|
||||
|
Loading…
Reference in New Issue
Block a user