Compare commits

..

No commits in common. "8d62d0a9799eb970d916e5d2bcaa976dbd2301f1" and "ff08a56d5107271598b7075bd534936e22ffdf1b" have entirely different histories.

4 changed files with 20 additions and 44 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,40 +42,31 @@ export class FilesService {
* @param localPath * @param localPath
* @param localFiles * @param localFiles
* @param remoteFiles * @param remoteFiles
* @param remoteApiPath * @param remoteMemePath
* @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[],
remoteApiPath: string, remoteMemePath: 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(remoteApiPath, remoteFile.path); let relativePath = path.relative(remoteMemePath, 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(`replacPath: ${relativePath}`); this.logger.debug(`relativePath: ${relativePath}`);
relativePath = path.normalize(relativePath).replace(/\\/g, '/'); this.logger.debug(`remoteRelativePath: ${remoteRelativePath}`);
this.logger.debug(`relativePathEd: ${relativePath}`); const localFilePath = path.join(
const localFilePath = path localPath,
.normalize(path.join(localPath, relativePath)) relativePath.replace(/\\/g, '/'),
.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);
@ -87,9 +78,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,
remoteApiPath, remoteMemePath,
replacPath, replacPath,
); );
} }
@ -97,14 +88,7 @@ export class FilesService {
this.logger.error(`递归处理文件夹失败: ${localFilePath}`, error); this.logger.error(`递归处理文件夹失败: ${localFilePath}`, error);
} }
} else { } else {
const normalizedLocalFiles = localFiles.map((f) => if (!localFiles.includes(localFilePath)) {
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(
@ -112,15 +96,9 @@ 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 = 15 * 60 * 1000; // 15min private readonly updateMs = 1 * 60 * 100; // 15min
@Inject(PathService) @Inject(PathService)
private readonly paths: PathService; private readonly paths: PathService;
constructor( constructor(
@ -29,24 +29,23 @@ export class CdnService {
private startAutoUpdate() { private startAutoUpdate() {
setInterval(async () => { 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'); 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); //crystelf/cdn await this.openListService.listFiles(remoteCdnPath);
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,7 +33,6 @@ 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 =
@ -44,7 +43,7 @@ export class MemeService {
localFiles, localFiles,
remoteFileList, remoteFileList,
remoteMemePath, remoteMemePath,
'\\crystelf\\meme', '\crystelf\meme',
); );
} else { } else {
this.logger.error('获取远程表情仓库文件失败..'); this.logger.error('获取远程表情仓库文件失败..');