From b638350d0361182073a7b96d6b2470f5af65268a Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Mon, 19 Aug 2024 17:49:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0=E7=9F=AD?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 20 +++++++++++--------- constants/constant.js | 8 +++++++- utils/common.js | 25 +++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 9a10055..22b320f 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -76,7 +76,7 @@ import { retryAxiosReq, saveJsonToFile, secondsToTime, testProxy, - truncateString + truncateString, urlTransformShortLink } from "../utils/common.js"; import { checkAndRemoveFile, deleteFolderRecursive, getMediaFilesAndOthers, mkdirIfNotExists } from "../utils/file.js"; import GeneralLinkAdapter from "../utils/general-link-adapter.js"; @@ -637,20 +637,22 @@ export class tools extends plugin { headers: BILI_HEADER })).json(); const result = resp.result; + const { views, danmakus, likes, coins, favorites, favorite } = result.stat; + // 封装成可以format的数据 const dataProcessMap = { - "播放": result.stat.views, - "弹幕": result.stat.danmakus, - "点赞": result.stat.likes, - "分享": result.stat.coins, - "追番": result.stat.favorites, - "收藏": result.stat.favorite, + "播放": views, + "弹幕": danmakus, + "点赞": likes, + "分享": coins, + "追番": favorites, + "收藏": favorite, }; e.reply([ segment.image(resp.result.cover), `${ this.identifyPrefix }识别:哔哩哔哩番剧,${ result.title }\n🎯 评分: ${ result?.rating?.score ?? '-' } / ${ result?.rating?.count ?? '-' }\n📺 ${ result.new_ep.desc }, ${ result.seasons[0].new_ep.index_show }\n`, `${ formatBiliInfo(dataProcessMap) }`, - `\n\n在线观看: ${ANIME_SERIES_SEARCH_LINK}${encodeURI(result.title)}` - ], true) + `\n\n在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + result.title) }` + ], true); } /** diff --git a/constants/constant.js b/constants/constant.js index 113e2eb..baf6fd1 100644 --- a/constants/constant.js +++ b/constants/constant.js @@ -150,4 +150,10 @@ export const MESSAGE_RECALL_TIME = 60; * 针对 Aria2 和 Alex 的下载检测文件时间 * @type {number} */ -export const DOWNLOAD_WAIT_DETECT_FILE_TIME = 3000; \ No newline at end of file +export const DOWNLOAD_WAIT_DETECT_FILE_TIME = 3000; + +/** + * 短链接接口 + * @type {string} + */ +export const SHORT_LINKS = "https://smolurl.com/api/links"; \ No newline at end of file diff --git a/utils/common.js b/utils/common.js index fb23bd6..9cb7658 100644 --- a/utils/common.js +++ b/utils/common.js @@ -1,14 +1,14 @@ import axios from "axios"; import { exec } from "child_process"; +import https from 'https'; import { HttpsProxyAgent } from 'https-proxy-agent'; import fetch from "node-fetch"; import fs from "node:fs"; import os from "os"; import path from 'path'; -import { BILI_DOWNLOAD_METHOD, COMMON_USER_AGENT, TEN_THOUSAND } from "../constants/constant.js"; +import { BILI_DOWNLOAD_METHOD, COMMON_USER_AGENT, SHORT_LINKS, TEN_THOUSAND } from "../constants/constant.js"; import { mkdirIfNotExists } from "./file.js"; - export function generateRandomStr(randomlength = 16) { const base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789=' let random_str = '' @@ -469,4 +469,25 @@ export function checkToolInCurEnv(someCommand) { resolve(true); }); }); +} + +/** + * 转换短链接 + * @param url + * @returns {Promise} + */ +export async function urlTransformShortLink(url) { + const data = { + url: `${encodeURI(url)}` + }; + + const resp = await fetch(SHORT_LINKS, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data) + }).then(response => response.json()); + return await resp.data.short_url; } \ No newline at end of file