feat: 添加上传飞机劫持下载

This commit is contained in:
zhiyu1998 2024-08-25 20:56:42 +08:00
parent 3bf7329299
commit 7f318779ea
2 changed files with 44 additions and 6 deletions

View File

@ -90,7 +90,7 @@ import { contentEstimator } from "../utils/link-share-summary-util.js";
import { getDS } from "../utils/mihoyo.js";
import { OpenaiBuilder } from "../utils/openai-builder.js";
import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
import { saveTDL, startTDL } from "../utils/tdl-util.js";
import { saveTDL, startTDL, uploadTDL } from "../utils/tdl-util.js";
import Translate from "../utils/trans-strategy.js";
import { mid2id } from "../utils/weibo.js";
import { ytDlpGetTilt, ytDlpHelper } from "../utils/yt-dlp-util.js";
@ -2409,6 +2409,14 @@ export class tools extends plugin {
}
const stats = fs.statSync(path);
const videoSize = Math.floor(stats.size / (1024 * 1024));
// 顺便发送一份到小飞机
if (e.msg.startsWith("上传飞机")) {
this.queue.add(async () => {
await uploadTDL(path, this.isOverseasServer(), this.proxyAddr);
e.reply("✈️ 已发送一份到您的小飞机收藏夹了!");
})
}
// 正常发送视频
if (videoSize > videoSizeLimit) {
e.reply(`当前视频大小:${ videoSize }MB\n大于设置的最大限制:${ videoSizeLimit }MB\n改为上传群文件`);
await this.uploadGroupFile(e, path);

View File

@ -31,20 +31,50 @@ export async function startTDL(url, curPath, isOversea, proxyAddr, videoDownload
})
}
export async function saveTDL(urk, isOversea, proxyAddr) {
/**
* 保存小飞机内容到小飞机的收藏
* @param url
* @param isOversea
* @param proxyAddr
* @returns {Promise<unknown>}
*/
export async function saveTDL(url, isOversea, proxyAddr) {
return new Promise((resolve, reject) => {
const proxyStr = isOversea ? `` : `--proxy ${ proxyAddr }`;
const command = `tdl forward --from ${urk} ${proxyStr}`
const command = `tdl forward --from ${url} ${proxyStr}`
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`[R插件][TDL]执行出错: ${error.message}`);
reject(`[R插件][TDL保存]执行出错: ${error.message}`);
return;
}
if (stderr) {
reject(`[R插件][TDL]错误信息: ${stderr}`);
reject(`[R插件][TDL保存]错误信息: ${stderr}`);
return;
}
resolve(stdout);
})
})
}
/**
* 上传文件到飞机收藏夹
* @param filePath
* @param isOversea
* @param proxyAddr
* @returns {Promise<void>}
*/
export async function uploadTDL(filePath, isOversea, proxyAddr) {
const proxyStr = isOversea ? `` : `--proxy ${ proxyAddr }`;
const command = `tdl up -p ${ filePath } ${ proxyStr }`;
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`[R插件][TDL上传]执行出错: ${error.message}`);
return;
}
if (stderr) {
reject(`[R插件][TDL上传]错误信息: ${stderr}`);
return;
}
resolve(stdout);
})
}