mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: 增加短链接服务
This commit is contained in:
parent
f4fae9d8b6
commit
b638350d03
@ -76,7 +76,7 @@ import {
|
|||||||
retryAxiosReq, saveJsonToFile,
|
retryAxiosReq, saveJsonToFile,
|
||||||
secondsToTime,
|
secondsToTime,
|
||||||
testProxy,
|
testProxy,
|
||||||
truncateString
|
truncateString, urlTransformShortLink
|
||||||
} from "../utils/common.js";
|
} from "../utils/common.js";
|
||||||
import { checkAndRemoveFile, deleteFolderRecursive, getMediaFilesAndOthers, mkdirIfNotExists } from "../utils/file.js";
|
import { checkAndRemoveFile, deleteFolderRecursive, getMediaFilesAndOthers, mkdirIfNotExists } from "../utils/file.js";
|
||||||
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
|
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
|
||||||
@ -637,20 +637,22 @@ export class tools extends plugin {
|
|||||||
headers: BILI_HEADER
|
headers: BILI_HEADER
|
||||||
})).json();
|
})).json();
|
||||||
const result = resp.result;
|
const result = resp.result;
|
||||||
|
const { views, danmakus, likes, coins, favorites, favorite } = result.stat;
|
||||||
|
// 封装成可以format的数据
|
||||||
const dataProcessMap = {
|
const dataProcessMap = {
|
||||||
"播放": result.stat.views,
|
"播放": views,
|
||||||
"弹幕": result.stat.danmakus,
|
"弹幕": danmakus,
|
||||||
"点赞": result.stat.likes,
|
"点赞": likes,
|
||||||
"分享": result.stat.coins,
|
"分享": coins,
|
||||||
"追番": result.stat.favorites,
|
"追番": favorites,
|
||||||
"收藏": result.stat.favorite,
|
"收藏": favorite,
|
||||||
};
|
};
|
||||||
e.reply([
|
e.reply([
|
||||||
segment.image(resp.result.cover),
|
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`,
|
`${ 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) }`,
|
`${ formatBiliInfo(dataProcessMap) }`,
|
||||||
`\n\n在线观看: ${ANIME_SERIES_SEARCH_LINK}${encodeURI(result.title)}`
|
`\n\n在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + result.title) }`
|
||||||
], true)
|
], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,4 +150,10 @@ export const MESSAGE_RECALL_TIME = 60;
|
|||||||
* 针对 Aria2 和 Alex 的下载检测文件时间
|
* 针对 Aria2 和 Alex 的下载检测文件时间
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
export const DOWNLOAD_WAIT_DETECT_FILE_TIME = 3000;
|
export const DOWNLOAD_WAIT_DETECT_FILE_TIME = 3000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短链接接口
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const SHORT_LINKS = "https://smolurl.com/api/links";
|
@ -1,14 +1,14 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { exec } from "child_process";
|
import { exec } from "child_process";
|
||||||
|
import https from 'https';
|
||||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from 'path';
|
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";
|
import { mkdirIfNotExists } from "./file.js";
|
||||||
|
|
||||||
|
|
||||||
export function generateRandomStr(randomlength = 16) {
|
export function generateRandomStr(randomlength = 16) {
|
||||||
const base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789='
|
const base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789='
|
||||||
let random_str = ''
|
let random_str = ''
|
||||||
@ -469,4 +469,25 @@ export function checkToolInCurEnv(someCommand) {
|
|||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换短链接
|
||||||
|
* @param url
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
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;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user