From 6a90dfe233018028dc55b66bfaf331fa39e96f61 Mon Sep 17 00:00:00 2001 From: yiyun Date: Sun, 14 Apr 2024 00:01:03 +0800 Subject: [PATCH] feat(src/search-app): deleted --- src/search-app/README.md | 31 ----- src/search-app/hono-app/.gitignore | 13 -- src/search-app/hono-app/README.md | 23 ---- src/search-app/hono-app/package.json | 14 -- src/search-app/hono-app/src/index.ts | 65 ---------- .../hono-app/src/plugins/bilibili-user.ts | 121 ------------------ .../hono-app/src/plugins/game4399account.ts | 89 ------------- .../hono-app/src/types/baseReponseModel.ts | 7 - src/search-app/hono-app/tsconfig.json | 16 --- src/search-app/hono-app/wrangler.toml | 24 ---- 10 files changed, 403 deletions(-) delete mode 100644 src/search-app/README.md delete mode 100644 src/search-app/hono-app/.gitignore delete mode 100644 src/search-app/hono-app/README.md delete mode 100644 src/search-app/hono-app/package.json delete mode 100644 src/search-app/hono-app/src/index.ts delete mode 100644 src/search-app/hono-app/src/plugins/bilibili-user.ts delete mode 100644 src/search-app/hono-app/src/plugins/game4399account.ts delete mode 100644 src/search-app/hono-app/src/types/baseReponseModel.ts delete mode 100644 src/search-app/hono-app/tsconfig.json delete mode 100644 src/search-app/hono-app/wrangler.toml diff --git a/src/search-app/README.md b/src/search-app/README.md deleted file mode 100644 index 6eab70ffa..000000000 --- a/src/search-app/README.md +++ /dev/null @@ -1,31 +0,0 @@ - -## 聚合搜索 API - -> 在一个地方搜索一切 - -- [x] 4399 用户名查询 -- [x] 哔哩哔哩用户查询 - - -## 部署 - -### Deploy to Cloudflare Workers - -> 点击下方按钮一键部署到 `Cloudflare Workers` - -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/yiyungent/KnifeHub/tree/main/src/search-app/hono-app) - - - - - - - - - - - - - - - diff --git a/src/search-app/hono-app/.gitignore b/src/search-app/hono-app/.gitignore deleted file mode 100644 index ffd328520..000000000 --- a/src/search-app/hono-app/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -node_modules -dist -.wrangler -.dev.vars - -# Change them to your taste: -package-lock.json -yarn.lock -pnpm-lock.yaml -bun.lockb - - - diff --git a/src/search-app/hono-app/README.md b/src/search-app/hono-app/README.md deleted file mode 100644 index f5817640d..000000000 --- a/src/search-app/hono-app/README.md +++ /dev/null @@ -1,23 +0,0 @@ - -## 聚合搜索 API - -``` -pnpm install -pnpm run dev -``` - - -> 部署到 `Cloudflare Workers` - -``` -pnpm run deploy -``` - - - -## 参考 - -- [honojs/hono: Fast, Lightweight, Web-standards](https://github.com/honojs/hono) - - - diff --git a/src/search-app/hono-app/package.json b/src/search-app/hono-app/package.json deleted file mode 100644 index eadae9740..000000000 --- a/src/search-app/hono-app/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "scripts": { - "dev": "wrangler dev src/index.ts", - "deploy": "wrangler deploy --minify src/index.ts" - }, - "dependencies": { - "@hono/swagger-ui": "^0.2.1", - "hono": "^4.2.3" - }, - "devDependencies": { - "@cloudflare/workers-types": "^4.20240403.0", - "wrangler": "^3.47.0" - } -} diff --git a/src/search-app/hono-app/src/index.ts b/src/search-app/hono-app/src/index.ts deleted file mode 100644 index b1ac53dfd..000000000 --- a/src/search-app/hono-app/src/index.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Hono } from "hono"; -import { cors } from "hono/cors"; -import { env } from "hono/adapter"; -import { swaggerUI } from "@hono/swagger-ui"; -import game4399account from "./plugins/game4399account"; -import bilibiliUser from "./plugins/bilibili-user"; - -const app = new Hono(); -// https://hono.dev/middleware/builtin/cors -app.use("/*", cors()); -// https://github.com/honojs/middleware/tree/main/packages/swagger-ui -// Use the middleware to serve Swagger UI at /ui -// app.get('/ui', swaggerUI({ url: '/doc' })) - -app.get("/", (c) => { - return c.json({ - name: "搜索 API", - version: "1.0.0", - plugins: [ - { - name: "4399 用户名查询", - url: "/api/plugins/game4399account?q={q}", - test: "/api/plugins/game4399account?q=21434", - }, - { - name: "哔哩哔哩用户查询", - url: "/api/plugins/bilibili-user?q={q}", - test: "/api/plugins/bilibili-user?q=测试用户", - }, - ], - }); -}); - -app.get("/api/plugins/game4399account", async (c) => { - const q = c.req.query("q"); - if (!q) { - return c.json({ - code: -1, - message: "参数错误", - data: [], - }); - } - const res = await game4399account(q); - - return c.json(res); -}); - -app.get("/api/plugins/bilibili-user", async (c) => { - const q = c.req.query("q"); - if (!q) { - return c.json({ - code: -1, - message: "参数错误", - data: [], - }); - } - const { PLUGINS_BILIBILI_USER_COOKIE } = env<{ - PLUGINS_BILIBILI_USER_COOKIE: string; - }>(c); - const res = await bilibiliUser(q, PLUGINS_BILIBILI_USER_COOKIE); - - return c.json(res); -}); - -export default app; diff --git a/src/search-app/hono-app/src/plugins/bilibili-user.ts b/src/search-app/hono-app/src/plugins/bilibili-user.ts deleted file mode 100644 index 5a1730e3b..000000000 --- a/src/search-app/hono-app/src/plugins/bilibili-user.ts +++ /dev/null @@ -1,121 +0,0 @@ -import type { BaseResponseModel } from "../types/baseReponseModel"; - - -interface BilibiliUserDataItemModel { - /** - * 用户名 - */ - 用户名: string; - /** - * 头像 - */ - 头像: string; - - /** - * 签名 - */ - 签名: string; - - /** - * 投稿视频个数 - */ - 投稿视频数: number; - - /** - * 粉丝个数 - */ - 粉丝数: number; - - /** - * 等级 - */ - 用户等级: number; - - /** - * https://space.bilibili.com/25057459 - */ - 个人空间: string; -} - -export default async function query( - query: string, - cookie: string, -): Promise> { - const responseModel: BaseResponseModel = { - code: -1, - message: "失败", - data: [], - }; - try { - const res = await fetch( - `https://api.bilibili.com/x/web-interface/wbi/search/type?` + - new URLSearchParams({ - category_id: "", - search_type: "bili_user", - ad_resource: "5646", - __refresh__: "true", - page: "1", - page_size: "36", - platform: "pc", - highlight: "1", - single_column: "0", - keyword: query.trim(), - qv_id: "drhuMbLFmLakkilY2NVwvZlCArwuxzso", - source_tag: "3", - order_sort: "0", - user_type: "0", - dynamic_offset: "0", - web_location: "1430654", - w_rid: "c69cf3c4599ba1fcd0429dcfad83f2e8", - wts: "1712952282", - }), - { - method: "GET", - headers: { - "Content-Type": "application/json", - "User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36`, - Referer: - `https://search.bilibili.com/upuser?` + - new URLSearchParams({ - keyword: query.trim(), - search_source: "5", - }), - Accept: "application/json, text/plain, */*", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", - Origin: "https://search.bilibili.com", - "Sec-Ch-Ua": `"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"`, - Cookie: `${cookie}` - }, - } - ); - - console.log("res", res); - - if (res.ok) { - responseModel.code = 1; - responseModel.message = "成功"; - const resJson: any = await res.json(); - if ( - resJson.code === 0 && - resJson.data?.result && - resJson.data?.result.length > 0 - ) { - resJson.data.result.forEach((item: any) => { - responseModel.data.push({ - 用户名: item.uname, - 头像: `${item.upic.replace("//", "http://")}`, - 签名: item.usign, - 投稿视频数: item.videos, - 粉丝数: item.fans, - 用户等级: item.level, - 个人空间: `https://space.bilibili.com/${item.mid}`, - }); - }); - } - } - } catch (error) { - console.log("error", error); - } - - return responseModel; -} diff --git a/src/search-app/hono-app/src/plugins/game4399account.ts b/src/search-app/hono-app/src/plugins/game4399account.ts deleted file mode 100644 index 158846c63..000000000 --- a/src/search-app/hono-app/src/plugins/game4399account.ts +++ /dev/null @@ -1,89 +0,0 @@ -import type { BaseResponseModel } from "../types/baseReponseModel"; - -interface Gamme4399AccountDataItemModel { - /** - * 4399账号 - */ - 账号: string; - /** - * 此账号在4399平台不存在 - * 此账号在4399平台已存在 - */ - 提示: string; - - /** - * https://www.4399.com - */ - 来源: string; -} - -/** - * https://u.4399.com/anquan/pwd/?from=u&sfrom= - * @param query - * @returns - */ -export default async function query( - query: string -): Promise> { - const responseModel: BaseResponseModel = { - code: -1, - message: "失败", - data: [], - }; - try { - // 创建一个新的 Date 对象 - const date = new Date(); - // 获得以毫秒为单位的时间戳 - const timeStamp = date.getTime(); - const res = await fetch( - `https://u.4399.com/anquan/pwd/?` + - new URLSearchParams({ - _c: "verify", - _a: "userAllowFind", - userName: query.trim(), - jsoncallback: "jQuery110206197225005545752_1712947018019", - _: `${timeStamp}`, - }), - { - method: "GET", - headers: { - "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", - Referer: "https://u.4399.com/anquan/pwd/?from=u&sfrom=", - "Content-Type": "application/x-www-form-urlencoded", - Accept: `text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01`, - "X-Requested-With": "XMLHttpRequest", - "Sec-Ch-Ua-Platform": `"Windows"`, - }, - } - ); - - if (res.ok) { - responseModel.code = 1; - responseModel.message = "成功"; - const text = await res.text(); - // decoded: jQuery110206197225005545752_1712947018007({status: false, msg: "此账号在4399平台不存在"}) - // jQuery110206197225005545752_1712947018007({"status":false,"msg":"\u6b64\u8d26\u53f7\u57284399\u5e73\u53f0\u4e0d\u5b58\u5728"}) - // jQuery110206197225005545752_1712947018007({"status":true}) - if (text.indexOf(`"status":true`) > 0) { - responseModel.message = "成功"; - responseModel.data = [ - { - 账号: query.trim(), - 提示: "此账号在4399平台已存在", - 来源: "https://www.4399.com", - }, - ]; - } else if (text.indexOf(`"status":false`) > 0) { - responseModel.message = `成功: 此账号 (${query.trim()}) 在4399平台不存在`; - // 不存在就不需要展示列表了 - responseModel.data = []; - } else { - responseModel.code = -1; - responseModel.message = "未知错误"; - } - } - } catch (error) {} - - return responseModel; -} diff --git a/src/search-app/hono-app/src/types/baseReponseModel.ts b/src/search-app/hono-app/src/types/baseReponseModel.ts deleted file mode 100644 index f975a77aa..000000000 --- a/src/search-app/hono-app/src/types/baseReponseModel.ts +++ /dev/null @@ -1,7 +0,0 @@ - -export interface BaseResponseModel { - code: number - message: string - data: TDataItem[] -} - diff --git a/src/search-app/hono-app/tsconfig.json b/src/search-app/hono-app/tsconfig.json deleted file mode 100644 index 33a96fd08..000000000 --- a/src/search-app/hono-app/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "ESNext", - "module": "ESNext", - "moduleResolution": "Bundler", - "strict": true, - "lib": [ - "ESNext" - ], - "types": [ - "@cloudflare/workers-types" - ], - "jsx": "react-jsx", - "jsxImportSource": "hono/jsx" - }, -} \ No newline at end of file diff --git a/src/search-app/hono-app/wrangler.toml b/src/search-app/hono-app/wrangler.toml deleted file mode 100644 index 0d107a9e6..000000000 --- a/src/search-app/hono-app/wrangler.toml +++ /dev/null @@ -1,24 +0,0 @@ -name = "search-hub" -compatibility_date = "2023-12-01" - -# [vars] -# MY_VAR = "my-variable" -PLUGINS_BILIBILI_USER_COOKIE = "buvid4=98FCD548-69A9-1455-69CF-6A64B36BC4A000607-024031218-HyYFmR0Ivh2P1Xfp2yjdqg%3D%3D; buvid3=C63D509D-FF05-8A4E-8574-3343C6A9FBD216132infoc; b_nut=1712955316" - - -# [[kv_namespaces]] -# binding = "MY_KV_NAMESPACE" -# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - -# [[r2_buckets]] -# binding = "MY_BUCKET" -# bucket_name = "my-bucket" - -# [[d1_databases]] -# binding = "DB" -# database_name = "my-database" -# database_id = "" - -# [ai] -# binding = "AI" -