mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🐞 fix: 修复 napcat 无法上传云盘的问题 for patch-1
This commit is contained in:
parent
ca12caa75e
commit
079ef66f33
@ -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 { COMMON_USER_AGENT, REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_SONGINFO, REDIS_YUNZAI_CLOUDSONGLIST } from "../constants/constant.js";
|
||||||
import { downloadAudio, retryAxiosReq } from "../utils/common.js";
|
import { downloadAudio, retryAxiosReq } from "../utils/common.js";
|
||||||
import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
||||||
import { checkAndRemoveFile } from "../utils/file.js";
|
import { checkAndRemoveFile, splitPaths } from "../utils/file.js";
|
||||||
import { sendMusicCard, getGroupFileUrl } from "../utils/yunzai-util.js";
|
import { sendMusicCard, getGroupFileUrl } from "../utils/yunzai-util.js";
|
||||||
import config from "../model/config.js";
|
import config from "../model/config.js";
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
@ -355,7 +355,7 @@ export class songRequest extends plugin {
|
|||||||
}
|
}
|
||||||
this.songCloudUpdate(e);
|
this.songCloudUpdate(e);
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('上传失败,响应不正确');
|
throw new Error('上传失败,响应不正确');
|
||||||
}
|
}
|
||||||
@ -409,17 +409,22 @@ export class songRequest extends plugin {
|
|||||||
|
|
||||||
// 群文件上传云盘
|
// 群文件上传云盘
|
||||||
async getLatestDocument(e) {
|
async getLatestDocument(e) {
|
||||||
const autoSelectNeteaseApi = await this.pickApi()
|
const autoSelectNeteaseApi = await this.pickApi();
|
||||||
const cleanPath = await getGroupFileUrl(e)
|
let { cleanPath, file_id } = await getGroupFileUrl(e);
|
||||||
// 拓展名
|
// Napcat 解决方案
|
||||||
const extension = cleanPath.match(/\.\w+$/);
|
if (cleanPath.startsWith("https")) {
|
||||||
// 获取文件路径
|
const fileIdMatch = file_id.match(/\.(.*?)\.(\w+)$/);
|
||||||
const dirPath = cleanPath.substring(0, cleanPath.lastIndexOf('/'));
|
const songName = fileIdMatch[1]; // 提取的歌曲名称
|
||||||
// 获取文件名
|
const fileFormat = fileIdMatch[2]; // 提取的文件格式
|
||||||
const fileName = cleanPath.split('/').pop().replace(/\.\w+$/, '');
|
cleanPath = await downloadAudio(cleanPath, this.getCurDownloadPath(e), songName, "manual", fileFormat);
|
||||||
// 进行文件名拆解
|
}
|
||||||
const parts = fileName.trim().match(/^([\s\S]+)\s*-\s*([\s\S]+)$/);
|
logger.info(cleanPath);
|
||||||
const newFileName = dirPath + '/' + parts[2].replace(/^\s+|\s+$/g, '') + extension
|
// 使用 splitPaths 提取信息
|
||||||
|
const [{ dir: dirPath, fileName, extension, baseFileName }] = splitPaths(cleanPath);
|
||||||
|
// 文件名拆解为两部分
|
||||||
|
const parts = baseFileName.trim().match(/^([\s\S]+)\s*-\s*([\s\S]+)$/);
|
||||||
|
// 生成新文件名
|
||||||
|
const newFileName = `${dirPath}/${parts[2].trim()}${extension}`;
|
||||||
// 进行元数据编辑
|
// 进行元数据编辑
|
||||||
if (parts) {
|
if (parts) {
|
||||||
const tags = {
|
const tags = {
|
||||||
@ -680,4 +685,4 @@ export class songRequest extends plugin {
|
|||||||
await e.group.sendFile(path);
|
await e.group.sendFile(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,3 +185,20 @@ export async function getMediaFilesAndOthers(folderPath) {
|
|||||||
handleError(err);
|
handleError(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将输入统一为数组形式,方便处理单个和多个路径
|
||||||
|
* @param input
|
||||||
|
* @returns {{fileName: *, dir: *}[]}
|
||||||
|
*/
|
||||||
|
export function splitPaths(input) {
|
||||||
|
const paths = Array.isArray(input) ? input : [input];
|
||||||
|
|
||||||
|
return paths.map(filePath => {
|
||||||
|
const dir = path.dirname(filePath);
|
||||||
|
const fileName = path.basename(filePath);
|
||||||
|
const extension = path.extname(fileName);
|
||||||
|
const baseFileName = path.basename(fileName, extension); // 去除扩展名的文件名
|
||||||
|
return { dir, fileName, extension, baseFileName };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -16,8 +16,8 @@ export function textArrayToMakeForward(e, textArray) {
|
|||||||
/**
|
/**
|
||||||
* 发送群组音乐卡片
|
* 发送群组音乐卡片
|
||||||
* @param e
|
* @param e
|
||||||
* @param platformType 音乐平台
|
* @param platformType 音乐平台
|
||||||
* @param musicId 音乐id
|
* @param musicId 音乐id
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function sendMusicCard(e, platformType, musicId) {
|
export async function sendMusicCard(e, platformType, musicId) {
|
||||||
@ -65,7 +65,27 @@ export async function getGroupFileUrl(e, count = 10) {
|
|||||||
"group_id": e.group_id,
|
"group_id": e.group_id,
|
||||||
"file_id": file_id
|
"file_id": file_id
|
||||||
});
|
});
|
||||||
let path = decodeURIComponent(latestFileUrl.data.url)
|
let cleanPath = decodeURIComponent(latestFileUrl.data.url)
|
||||||
const cleanPath = path.startsWith('file:///') ? path.replace('file:///', '') : path;
|
// 适配 低版本 Napcat 例如:3.6.4
|
||||||
return cleanPath
|
if (cleanPath.startsWith("https")) {
|
||||||
}
|
// https://njc-download.ftn.qq.com/....
|
||||||
|
const urlObj = new URL(cleanPath);
|
||||||
|
// 检查URL中是否包含 fname 参数
|
||||||
|
if (urlObj.searchParams.has('fname')) {
|
||||||
|
// 获取 fname 参数的值
|
||||||
|
const originalFname = urlObj.searchParams.get('fname');
|
||||||
|
|
||||||
|
// 提取 file_id(第一个"."后面的内容)
|
||||||
|
const fileId = file_id.split('.').slice(1).join('.'); // 分割并去掉第一个部分
|
||||||
|
urlObj.searchParams.set('fname', `${originalFname}${fileId}`);
|
||||||
|
return {
|
||||||
|
cleanPath: urlObj.toString(),
|
||||||
|
file_id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (cleanPath.startsWith('file:///')) {
|
||||||
|
cleanPath.replace('file:///', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
return { cleanPath, file_id };
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user