mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🎈 pref: 扩展copyFiles
逻辑 & 扩展小飞机文件支持
This commit is contained in:
parent
87ebabda3c
commit
be65e150cc
@ -72,7 +72,7 @@ import {
|
|||||||
testProxy,
|
testProxy,
|
||||||
truncateString
|
truncateString
|
||||||
} from "../utils/common.js";
|
} 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 GeneralLinkAdapter from "../utils/general-link-adapter.js";
|
||||||
import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
|
import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
|
||||||
import { contentEstimator } from "../utils/link-share-summary-util.js";
|
import { contentEstimator } from "../utils/link-share-summary-util.js";
|
||||||
@ -1791,7 +1791,7 @@ export class tools extends plugin {
|
|||||||
await deleteFolderRecursive(tgSavePath);
|
await deleteFolderRecursive(tgSavePath);
|
||||||
await startTDL(url, tgSavePath, isOversea, this.myProxy, this.videoDownloadConcurrency);
|
await startTDL(url, tgSavePath, isOversea, this.myProxy, this.videoDownloadConcurrency);
|
||||||
// 过滤当前文件
|
// 过滤当前文件
|
||||||
const mediaFiles = await getMediaFiles(tgSavePath);
|
const mediaFiles = await getMediaFilesAndOthers(tgSavePath);
|
||||||
if (mediaFiles.images.length > 0) {
|
if (mediaFiles.images.length > 0) {
|
||||||
const imagesData = mediaFiles.images.map(item => {
|
const imagesData = mediaFiles.images.map(item => {
|
||||||
const fileContent = fs.readFileSync(`${tgSavePath}/${item}`);
|
const fileContent = fs.readFileSync(`${tgSavePath}/${item}`);
|
||||||
@ -1806,6 +1806,10 @@ export class tools extends plugin {
|
|||||||
for (const item of mediaFiles.videos) {
|
for (const item of mediaFiles.videos) {
|
||||||
await this.sendVideoToUpload(e, `${tgSavePath}/${item}`);
|
await this.sendVideoToUpload(e, `${tgSavePath}/${item}`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (let other of mediaFiles.others) {
|
||||||
|
await this.uploadGroupFile(e, `${ tgSavePath }/${ other }`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ function getMimeType(filePath) {
|
|||||||
* @param {string} folderPath - 要检测的文件夹路径
|
* @param {string} folderPath - 要检测的文件夹路径
|
||||||
* @returns {Promise<Object>} 包含图片和视频文件名的对象
|
* @returns {Promise<Object>} 包含图片和视频文件名的对象
|
||||||
*/
|
*/
|
||||||
export async function getMediaFiles(folderPath) {
|
export async function getMediaFilesAndOthers(folderPath) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 定义图片和视频的扩展名
|
// 定义图片和视频的扩展名
|
||||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
|
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
|
||||||
@ -170,6 +170,7 @@ export async function getMediaFiles(folderPath) {
|
|||||||
// 初始化存储图片和视频的数组
|
// 初始化存储图片和视频的数组
|
||||||
const images = [];
|
const images = [];
|
||||||
const videos = [];
|
const videos = [];
|
||||||
|
const others = [];
|
||||||
|
|
||||||
// 读取文件夹中的所有文件
|
// 读取文件夹中的所有文件
|
||||||
fs.readdir(folderPath, (err, files) => {
|
fs.readdir(folderPath, (err, files) => {
|
||||||
@ -184,11 +185,13 @@ export async function getMediaFiles(folderPath) {
|
|||||||
images.push(file);
|
images.push(file);
|
||||||
} else if (videoExtensions.includes(ext)) {
|
} else if (videoExtensions.includes(ext)) {
|
||||||
videos.push(file);
|
videos.push(file);
|
||||||
|
} else {
|
||||||
|
others.push(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 返回包含图片和视频的对象
|
// 返回包含图片和视频的对象
|
||||||
resolve({ images, videos });
|
resolve({ images, videos, others });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user