mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-10-14 13:29:19 +00:00
Compare commits
No commits in common. "8d62d0a9799eb970d916e5d2bcaa976dbd2301f1" and "ff08a56d5107271598b7075bd534936e22ffdf1b" have entirely different histories.
8d62d0a979
...
ff08a56d51
@ -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
|
||||
|
||||
|
@ -42,40 +42,31 @@ export class FilesService {
|
||||
* @param localPath 本地路径
|
||||
* @param localFiles 本地文件列表
|
||||
* @param remoteFiles 远程文件列表
|
||||
* @param remoteApiPath 远程基准路径
|
||||
* @param replacPath 替换的目录,例: `\\crystelf\\meme`
|
||||
* @param remoteMemePath 远程基准路径
|
||||
* @param replacPath 替换的目录,例: `\crystelf\meme`
|
||||
* @private
|
||||
*/
|
||||
public async compareAndDownloadFiles(
|
||||
localPath: string,
|
||||
localFiles: string[],
|
||||
remoteFiles: any[],
|
||||
remoteApiPath: string,
|
||||
remoteMemePath: 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(remoteApiPath, remoteFile.path);
|
||||
let relativePath = path.relative(remoteMemePath, 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(`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}`);
|
||||
this.logger.debug(`relativePath: ${relativePath}`);
|
||||
this.logger.debug(`remoteRelativePath: ${remoteRelativePath}`);
|
||||
const localFilePath = path.join(
|
||||
localPath,
|
||||
relativePath.replace(/\\/g, '/'),
|
||||
);
|
||||
if (remoteFile.is_dir) {
|
||||
try {
|
||||
//const localDirPath = path.dirname(localFilePath);
|
||||
@ -87,9 +78,9 @@ export class FilesService {
|
||||
if (subRemoteFiles.code === 200 && subRemoteFiles.data.content) {
|
||||
await this.compareAndDownloadFiles(
|
||||
localPath,
|
||||
normalizedLocalFiles,
|
||||
[],
|
||||
subRemoteFiles.data.content,
|
||||
remoteApiPath,
|
||||
remoteMemePath,
|
||||
replacPath,
|
||||
);
|
||||
}
|
||||
@ -97,14 +88,7 @@ export class FilesService {
|
||||
this.logger.error(`递归处理文件夹失败: ${localFilePath}`, error);
|
||||
}
|
||||
} else {
|
||||
const normalizedLocalFiles = localFiles.map((f) =>
|
||||
path.normalize(f).replace(/\\/g, '/'),
|
||||
);
|
||||
//this.logger.debug(
|
||||
//`normalizedLocalFiles: ${JSON.stringify(normalizedLocalFiles)}`,
|
||||
//);
|
||||
|
||||
if (!normalizedLocalFiles.includes(localFilePath)) {
|
||||
if (!localFiles.includes(localFilePath)) {
|
||||
this.logger.log(`文件缺失: ${localFilePath}, 开始下载..`);
|
||||
try {
|
||||
await this.openListService.downloadFile(
|
||||
@ -112,15 +96,9 @@ 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 {
|
||||
|
@ -10,7 +10,7 @@ import { FilesService } from '../../core/files/files.service';
|
||||
export class CdnService {
|
||||
private readonly logger = new Logger(CdnService.name);
|
||||
private filePath: string;
|
||||
private readonly updateMs = 15 * 60 * 1000; // 15min
|
||||
private readonly updateMs = 1 * 60 * 100; // 15min
|
||||
@Inject(PathService)
|
||||
private readonly paths: PathService;
|
||||
constructor(
|
||||
@ -29,24 +29,23 @@ export class CdnService {
|
||||
|
||||
private startAutoUpdate() {
|
||||
setInterval(async () => {
|
||||
const cdnPath = path.join(this.pathService.get('public')); //baseDir/public
|
||||
const cdnPath = path.join(this.pathService.get('private'));
|
||||
const remoteCdnPath = this.configService.get('OPENLIST_API_CDN_PATH');
|
||||
if (remoteCdnPath) {
|
||||
this.logger.log('定时检查晶灵cdn更新..');
|
||||
try {
|
||||
const remoteFiles =
|
||||
await this.openListService.listFiles(remoteCdnPath); //crystelf/cdn
|
||||
await this.openListService.listFiles(remoteCdnPath);
|
||||
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}`);
|
||||
|
@ -33,7 +33,6 @@ 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 =
|
||||
@ -44,7 +43,7 @@ export class MemeService {
|
||||
localFiles,
|
||||
remoteFileList,
|
||||
remoteMemePath,
|
||||
'\\crystelf\\meme',
|
||||
'\crystelf\meme',
|
||||
);
|
||||
} else {
|
||||
this.logger.error('获取远程表情仓库文件失败..');
|
||||
|
Loading…
x
Reference in New Issue
Block a user