fix:下载修好力

This commit is contained in:
Jerry 2025-09-22 16:26:05 +08:00
parent a187ecc8d8
commit 8d62d0a979
4 changed files with 43 additions and 19 deletions

View File

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

View File

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

View File

@ -29,23 +29,24 @@ export class CdnService {
private startAutoUpdate() {
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');
if (remoteCdnPath) {
this.logger.log('定时检查晶灵cdn更新..');
try {
const remoteFiles =
await this.openListService.listFiles(remoteCdnPath);
await this.openListService.listFiles(remoteCdnPath); //crystelf/cdn
if (remoteFiles.code === 200 && remoteFiles.data.content) {
let remoteFileList = remoteFiles.data.content;
const localFiles =
await this.filesService.getLocalFileList(cdnPath);
this.logger.debug(`localFlies: ${JSON.stringify(localFiles)}`);
await this.filesService.compareAndDownloadFiles(
cdnPath,
localFiles,
remoteFileList,
remoteCdnPath,
'\crystelf\cdn',
'\\crystelf\\cdn',
);
} else {
this.logger.error(`晶灵cdn检查更新失败: ${remoteFiles.code}`);

View File

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