mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🎈 pref:提升云盘失败后再次上传性能;增加一个判断是否存在的函数checkFileExists
This commit is contained in:
parent
af05434436
commit
cacd10e32b
@ -8,7 +8,7 @@ import { NETEASE_API_CN, NETEASE_SONG_DOWNLOAD, NETEASE_TEMP_API } from "../cons
|
||||
import { COMMON_USER_AGENT, REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_SONGINFO, REDIS_YUNZAI_CLOUDSONGLIST } from "../constants/constant.js";
|
||||
import { downloadAudio, retryAxiosReq } from "../utils/common.js";
|
||||
import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
||||
import { checkAndRemoveFile, splitPaths } from "../utils/file.js";
|
||||
import { checkAndRemoveFile, checkFileExists, splitPaths } from "../utils/file.js";
|
||||
import { sendMusicCard, getGroupFileUrl } from "../utils/yunzai-util.js";
|
||||
import config from "../model/config.js";
|
||||
import FormData from 'form-data';
|
||||
@ -416,9 +416,18 @@ export class songRequest extends plugin {
|
||||
const fileIdMatch = file_id.match(/\.(.*?)\.(\w+)$/);
|
||||
const songName = fileIdMatch[1]; // 提取的歌曲名称
|
||||
const fileFormat = fileIdMatch[2]; // 提取的文件格式
|
||||
// 检测文件是否存在 已提升性能
|
||||
if (await checkFileExists(cleanPath)) {
|
||||
// 如果文件已存在
|
||||
logger.mark(`[R插件][云盘] 上传路径审计:已存在下载文件`);
|
||||
cleanPath = `${this.getCurDownloadPath(e)}/${songName}.${fileFormat}`;
|
||||
} else {
|
||||
// 如果文件不存在
|
||||
logger.mark(`[R插件][云盘] 上传路径审计:不存在下载文件,将进行下载...`);
|
||||
cleanPath = await downloadAudio(cleanPath, this.getCurDownloadPath(e), songName, "manual", fileFormat);
|
||||
}
|
||||
logger.info(cleanPath);
|
||||
}
|
||||
logger.info(`[R插件][云盘] 上传路径审计: ${ cleanPath }`);
|
||||
// 使用 splitPaths 提取信息
|
||||
const [{ dir: dirPath, fileName, extension, baseFileName }] = splitPaths(cleanPath);
|
||||
// 文件名拆解为两部分
|
||||
|
@ -12,12 +12,29 @@ const mimeTypes = {
|
||||
// 添加其他文件类型和MIME类型的映射
|
||||
};
|
||||
|
||||
// 通用错误处理函数
|
||||
/**
|
||||
* 通用错误处理函数
|
||||
* @param err
|
||||
*/
|
||||
function handleError(err) {
|
||||
logger.error(`错误: ${ err.message }\n堆栈: ${ err.stack }`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步的方式检查文件是否存在
|
||||
* @param filePath
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export async function checkFileExists(filePath) {
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
return true; // 文件存在
|
||||
} catch (error) {
|
||||
return false; // 文件不存在
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否存在并且删除
|
||||
* @param {string} file - 文件路径
|
||||
@ -188,8 +205,13 @@ export async function getMediaFilesAndOthers(folderPath) {
|
||||
|
||||
/**
|
||||
* 将输入统一为数组形式,方便处理单个和多个路径
|
||||
* @param input
|
||||
* @returns {{fileName: *, dir: *}[]}
|
||||
* @param {string|string[]} input - 一个或多个文件路径
|
||||
*
|
||||
* fileName:文件的完整名称,包括文件名和扩展名
|
||||
* extension:文件的扩展名
|
||||
* dir:文件所在的目录路径
|
||||
* baseFileName:不包含扩展名的文件名
|
||||
* @returns {{fileName: string, extension: string, dir: string, baseFileName: string}[]} - 一个包含文件信息的对象数组
|
||||
*/
|
||||
export function splitPaths(input) {
|
||||
const paths = Array.isArray(input) ? input : [input];
|
||||
|
Loading…
x
Reference in New Issue
Block a user