🎈 pref: 扩展copyFiles逻辑 & 扩展小飞机文件支持

This commit is contained in:
zhiyu1998 2024-08-15 10:13:20 +08:00
parent 87ebabda3c
commit be65e150cc
2 changed files with 11 additions and 4 deletions

View File

@ -72,7 +72,7 @@ import {
testProxy,
truncateString
} from "../utils/common.js";
import { checkAndRemoveFile, deleteFolderRecursive, getMediaFiles, mkdirIfNotExists } from "../utils/file.js";
import { checkAndRemoveFile, deleteFolderRecursive, getMediaFilesAndOthers, mkdirIfNotExists } from "../utils/file.js";
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
import { contentEstimator } from "../utils/link-share-summary-util.js";
@ -1791,7 +1791,7 @@ export class tools extends plugin {
await deleteFolderRecursive(tgSavePath);
await startTDL(url, tgSavePath, isOversea, this.myProxy, this.videoDownloadConcurrency);
// 过滤当前文件
const mediaFiles = await getMediaFiles(tgSavePath);
const mediaFiles = await getMediaFilesAndOthers(tgSavePath);
if (mediaFiles.images.length > 0) {
const imagesData = mediaFiles.images.map(item => {
const fileContent = fs.readFileSync(`${tgSavePath}/${item}`);
@ -1806,6 +1806,10 @@ export class tools extends plugin {
for (const item of mediaFiles.videos) {
await this.sendVideoToUpload(e, `${tgSavePath}/${item}`);
}
} else {
for (let other of mediaFiles.others) {
await this.uploadGroupFile(e, `${ tgSavePath }/${ other }`);
}
}
return true;
}

View File

@ -161,7 +161,7 @@ function getMimeType(filePath) {
* @param {string} folderPath - 要检测的文件夹路径
* @returns {Promise<Object>} 包含图片和视频文件名的对象
*/
export async function getMediaFiles(folderPath) {
export async function getMediaFilesAndOthers(folderPath) {
return new Promise((resolve, reject) => {
// 定义图片和视频的扩展名
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
@ -170,6 +170,7 @@ export async function getMediaFiles(folderPath) {
// 初始化存储图片和视频的数组
const images = [];
const videos = [];
const others = [];
// 读取文件夹中的所有文件
fs.readdir(folderPath, (err, files) => {
@ -184,11 +185,13 @@ export async function getMediaFiles(folderPath) {
images.push(file);
} else if (videoExtensions.includes(ext)) {
videos.push(file);
} else {
others.push(file);
}
});
// 返回包含图片和视频的对象
resolve({ images, videos });
resolve({ images, videos, others });
});
});
}