Compare commits

..

2 Commits

Author SHA1 Message Date
8d62d0a979 fix:下载修好力 2025-09-22 16:26:05 +08:00
a187ecc8d8 fix:修改时间 2025-09-22 13:05:24 +08:00
4 changed files with 44 additions and 20 deletions

View File

@ -5,7 +5,7 @@ TOKEN=
OPENLIST_API_BASE_URL=http://127.0.0.1:5244 OPENLIST_API_BASE_URL=http://127.0.0.1:5244
OPENLIST_API_BASE_USERNAME= OPENLIST_API_BASE_USERNAME=
OPENLIST_API_BASE_PASSWORD= OPENLIST_API_BASE_PASSWORD=
OPENLIST_API_MEME_PATH=/crystelf/meme OPENLIST_API_MEME_PATH=//crystelf//meme
OPENLIST_API_CDN_PATH=/crystelf/cdn OPENLIST_API_CDN_PATH=//crystelf//cdn
OPENLIST_API_BASE_PATH=D:\alist OPENLIST_API_BASE_PATH=D:\alist

View File

@ -42,31 +42,40 @@ export class FilesService {
* @param localPath * @param localPath
* @param localFiles * @param localFiles
* @param remoteFiles * @param remoteFiles
* @param remoteMemePath * @param remoteApiPath
* @param replacPath ,: `\crystelf\meme` * @param replacPath ,: `\\crystelf\\meme`
* @private * @private
*/ */
public async compareAndDownloadFiles( public async compareAndDownloadFiles(
localPath: string, localPath: string,
localFiles: string[], localFiles: string[],
remoteFiles: any[], remoteFiles: any[],
remoteMemePath: string, remoteApiPath: string,
replacPath: string, replacPath: string,
) { ) {
const remoteBasePath = this.configService.get(`OPENLIST_API_BASE_PATH`); const remoteBasePath = this.configService.get(`OPENLIST_API_BASE_PATH`);
const normalizedLocalFiles = localFiles.map((f) =>
path.normalize(f).replace(/\\/g, '/'),
);
for (const remoteFile of remoteFiles) { for (const remoteFile of remoteFiles) {
let relativePath = path.relative(remoteMemePath, remoteFile.path); let relativePath = path.relative(remoteApiPath, remoteFile.path);
//this.logger.debug(`relativePath: ${relativePath}`); //this.logger.debug(`relativePath: ${relativePath}`);
//this.logger.debug(remoteBasePath); //this.logger.debug(remoteBasePath);
if (remoteBasePath) { if (remoteBasePath) {
let remoteRelativePath = relativePath.replace(remoteBasePath, ''); //服务器下载用目录 let remoteRelativePath = relativePath.replace(remoteBasePath, ''); //服务器下载用目录
//this.logger.debug(`remoteRelativePath: ${remoteRelativePath}`); //√\
remoteRelativePath = path
.normalize(remoteRelativePath)
.replace(/\\/g, '/');
replacPath = path.normalize(replacPath).replace(/\\/g, '/');
relativePath = remoteRelativePath.replace(replacPath, ''); //本地储存用 relativePath = remoteRelativePath.replace(replacPath, ''); //本地储存用
this.logger.debug(`relativePath: ${relativePath}`); this.logger.debug(`replacPath: ${relativePath}`);
this.logger.debug(`remoteRelativePath: ${remoteRelativePath}`); relativePath = path.normalize(relativePath).replace(/\\/g, '/');
const localFilePath = path.join( this.logger.debug(`relativePathEd: ${relativePath}`);
localPath, const localFilePath = path
relativePath.replace(/\\/g, '/'), .normalize(path.join(localPath, relativePath))
); .replace(/\\/g, '/');
//this.logger.debug(`localFilePath: ${localFilePath}`);
if (remoteFile.is_dir) { if (remoteFile.is_dir) {
try { try {
//const localDirPath = path.dirname(localFilePath); //const localDirPath = path.dirname(localFilePath);
@ -78,9 +87,9 @@ export class FilesService {
if (subRemoteFiles.code === 200 && subRemoteFiles.data.content) { if (subRemoteFiles.code === 200 && subRemoteFiles.data.content) {
await this.compareAndDownloadFiles( await this.compareAndDownloadFiles(
localPath, localPath,
[], normalizedLocalFiles,
subRemoteFiles.data.content, subRemoteFiles.data.content,
remoteMemePath, remoteApiPath,
replacPath, replacPath,
); );
} }
@ -88,7 +97,14 @@ export class FilesService {
this.logger.error(`递归处理文件夹失败: ${localFilePath}`, error); this.logger.error(`递归处理文件夹失败: ${localFilePath}`, error);
} }
} else { } else {
if (!localFiles.includes(localFilePath)) { const normalizedLocalFiles = localFiles.map((f) =>
path.normalize(f).replace(/\\/g, '/'),
);
//this.logger.debug(
//`normalizedLocalFiles: ${JSON.stringify(normalizedLocalFiles)}`,
//);
if (!normalizedLocalFiles.includes(localFilePath)) {
this.logger.log(`文件缺失: ${localFilePath}, 开始下载..`); this.logger.log(`文件缺失: ${localFilePath}, 开始下载..`);
try { try {
await this.openListService.downloadFile( await this.openListService.downloadFile(
@ -96,9 +112,15 @@ export class FilesService {
localFilePath, localFilePath,
); );
this.logger.log(`文件下载成功: ${localFilePath}`); this.logger.log(`文件下载成功: ${localFilePath}`);
normalizedLocalFiles.push(localFilePath);
this.logger.debug(
`localFilePath: ${JSON.stringify(normalizedLocalFiles)}`,
);
} catch (error) { } catch (error) {
this.logger.error(`下载文件失败: ${localFilePath}`, error); this.logger.error(`下载文件失败: ${localFilePath}`, error);
} }
} else {
this.logger.log('本地文件已是最新..');
} }
} }
} else { } else {

View File

@ -10,7 +10,7 @@ import { FilesService } from '../../core/files/files.service';
export class CdnService { export class CdnService {
private readonly logger = new Logger(CdnService.name); private readonly logger = new Logger(CdnService.name);
private filePath: string; private filePath: string;
private readonly updateMs = 1 * 60 * 100; // 15min private readonly updateMs = 15 * 60 * 1000; // 15min
@Inject(PathService) @Inject(PathService)
private readonly paths: PathService; private readonly paths: PathService;
constructor( constructor(
@ -29,23 +29,24 @@ export class CdnService {
private startAutoUpdate() { private startAutoUpdate() {
setInterval(async () => { setInterval(async () => {
const cdnPath = path.join(this.pathService.get('private')); const cdnPath = path.join(this.pathService.get('public')); //baseDir/public
const remoteCdnPath = this.configService.get('OPENLIST_API_CDN_PATH'); const remoteCdnPath = this.configService.get('OPENLIST_API_CDN_PATH');
if (remoteCdnPath) { if (remoteCdnPath) {
this.logger.log('定时检查晶灵cdn更新..'); this.logger.log('定时检查晶灵cdn更新..');
try { try {
const remoteFiles = const remoteFiles =
await this.openListService.listFiles(remoteCdnPath); await this.openListService.listFiles(remoteCdnPath); //crystelf/cdn
if (remoteFiles.code === 200 && remoteFiles.data.content) { if (remoteFiles.code === 200 && remoteFiles.data.content) {
let remoteFileList = remoteFiles.data.content; let remoteFileList = remoteFiles.data.content;
const localFiles = const localFiles =
await this.filesService.getLocalFileList(cdnPath); await this.filesService.getLocalFileList(cdnPath);
this.logger.debug(`localFlies: ${JSON.stringify(localFiles)}`);
await this.filesService.compareAndDownloadFiles( await this.filesService.compareAndDownloadFiles(
cdnPath, cdnPath,
localFiles, localFiles,
remoteFileList, remoteFileList,
remoteCdnPath, remoteCdnPath,
'\crystelf\cdn', '\\crystelf\\cdn',
); );
} else { } else {
this.logger.error(`晶灵cdn检查更新失败: ${remoteFiles.code}`); this.logger.error(`晶灵cdn检查更新失败: ${remoteFiles.code}`);

View File

@ -33,6 +33,7 @@ export class MemeService {
try { try {
const remoteFiles = const remoteFiles =
await this.openListService.listFiles(remoteMemePath); await this.openListService.listFiles(remoteMemePath);
//this.logger.debug(`remoteFiles: ${remoteFiles}`);
if (remoteFiles.code === 200 && remoteFiles.data.content) { if (remoteFiles.code === 200 && remoteFiles.data.content) {
let remoteFileList = remoteFiles.data.content; let remoteFileList = remoteFiles.data.content;
const localFiles = const localFiles =
@ -43,7 +44,7 @@ export class MemeService {
localFiles, localFiles,
remoteFileList, remoteFileList,
remoteMemePath, remoteMemePath,
'\crystelf\meme', '\\crystelf\\meme',
); );
} else { } else {
this.logger.error('获取远程表情仓库文件失败..'); this.logger.error('获取远程表情仓库文件失败..');