mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-12-05 10:31:56 +00:00
fix:meme服务修复
This commit is contained in:
parent
beebcc14f9
commit
5c062172f3
@ -5,20 +5,18 @@ export interface FsList {
|
|||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
data: {
|
data: {
|
||||||
content:
|
content: Array<{
|
||||||
| [
|
name: string;
|
||||||
name: string,
|
size: number;
|
||||||
size: number,
|
is_dir: boolean;
|
||||||
is_dir: boolean,
|
modified: string; // 修改时间
|
||||||
modified: string, //修改时间
|
sign: string; // 签名
|
||||||
sign: string, //签名
|
thumb: string; // 略缩图
|
||||||
thumb: string, //略缩图
|
type: number; // 类型
|
||||||
type: number, //类型
|
}> | null; // 可能为空数组
|
||||||
]
|
total: number; // 总数
|
||||||
| null;
|
readme: string; // 说明?
|
||||||
total: number; //总数
|
write: boolean; // 是否可写入
|
||||||
readme: string; //说明?
|
|
||||||
write: boolean; //是否可写入
|
|
||||||
provider: string;
|
provider: string;
|
||||||
header: string;
|
header: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -106,6 +106,7 @@ export class OpenListUtils {
|
|||||||
try {
|
try {
|
||||||
const fileInfo = await this.getFileInfo(token, filePath);
|
const fileInfo = await this.getFileInfo(token, filePath);
|
||||||
const rawUrl = fileInfo.data.raw_url;
|
const rawUrl = fileInfo.data.raw_url;
|
||||||
|
this.logger.debug(`rawUrl: ${rawUrl}`);
|
||||||
if (!rawUrl) {
|
if (!rawUrl) {
|
||||||
this.logger.error('文件没有找到 raw_url 地址..');
|
this.logger.error('文件没有找到 raw_url 地址..');
|
||||||
throw new Error('文件没有找到 raw_url 地址..');
|
throw new Error('文件没有找到 raw_url 地址..');
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { AppConfigService } from '../../config/config.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class MemeService {
|
export class MemeService {
|
||||||
private readonly logger = new Logger(MemeService.name);
|
private readonly logger = new Logger(MemeService.name);
|
||||||
private readonly updateMs = 1 * 60 * 1000; // 15min
|
private readonly updateMs = 150 * 60 * 1000; // 15min
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(PathService)
|
@Inject(PathService)
|
||||||
@ -30,14 +30,15 @@ export class MemeService {
|
|||||||
try {
|
try {
|
||||||
const remoteFiles =
|
const remoteFiles =
|
||||||
await this.openListService.listFiles(remoteMemePath);
|
await this.openListService.listFiles(remoteMemePath);
|
||||||
this.logger.debug(remoteFiles);
|
|
||||||
if (remoteFiles.code === 200 && remoteFiles.data.content) {
|
if (remoteFiles.code === 200 && remoteFiles.data.content) {
|
||||||
const remoteFileList = remoteFiles.data.content;
|
let remoteFileList = remoteFiles.data.content;
|
||||||
const localFiles = await this.getLocalFileList(memePath);
|
const localFiles = await this.getLocalFileList(memePath);
|
||||||
|
//this.logger.debug(localFiles);
|
||||||
await this.compareAndDownloadFiles(
|
await this.compareAndDownloadFiles(
|
||||||
memePath,
|
memePath,
|
||||||
localFiles,
|
localFiles,
|
||||||
remoteFileList,
|
remoteFileList,
|
||||||
|
remoteMemePath,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.logger.error('获取远程表情仓库文件失败..');
|
this.logger.error('获取远程表情仓库文件失败..');
|
||||||
@ -57,8 +58,8 @@ export class MemeService {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private async getLocalFileList(dir: string): Promise<string[]> {
|
private async getLocalFileList(dir: string): Promise<string[]> {
|
||||||
const files: string[] = []; //文件
|
const files: string[] = [];
|
||||||
const dirs: string[] = []; //目录
|
const dirs: string[] = [];
|
||||||
try {
|
try {
|
||||||
const entries = await fs.readdir(dir, { withFileTypes: true });
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
@ -80,37 +81,57 @@ export class MemeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比较本地文件和远程文件,并下载缺失的文件
|
* 比较本地文件和远程文件 下载缺失的文件
|
||||||
* @param localPath 本地路径
|
* @param localPath 本地路径
|
||||||
* @param localFiles 本地文件列表
|
* @param localFiles 本地文件列表
|
||||||
* @param remoteFiles 远程文件列表
|
* @param remoteFiles 远程文件列表
|
||||||
|
* @param remoteMemePath 远程基准路径
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private async compareAndDownloadFiles(
|
private async compareAndDownloadFiles(
|
||||||
localPath: string,
|
localPath: string,
|
||||||
localFiles: string[],
|
localFiles: string[],
|
||||||
remoteFiles: any[],
|
remoteFiles: any[],
|
||||||
|
remoteMemePath: string,
|
||||||
) {
|
) {
|
||||||
for (const remoteFile of remoteFiles) {
|
for (const remoteFile of remoteFiles) {
|
||||||
const remoteFilePath = path.join(localPath, remoteFile.name);
|
let relativePath = path.relative(remoteMemePath, remoteFile.path);
|
||||||
|
relativePath = relativePath.replace(/D:\\alist\\crystelf\\meme/g, '');
|
||||||
|
const localFilePath = path.join(
|
||||||
|
localPath,
|
||||||
|
relativePath.replace(/\\/g, '/'),
|
||||||
|
);
|
||||||
if (remoteFile.is_dir) {
|
if (remoteFile.is_dir) {
|
||||||
await fs.mkdir(remoteFilePath, { recursive: true });
|
|
||||||
this.logger.log(`文件夹已创建: ${remoteFile.name}`);
|
|
||||||
await this.compareAndDownloadFiles(
|
|
||||||
remoteFilePath,
|
|
||||||
[],
|
|
||||||
remoteFile.content,
|
|
||||||
);
|
|
||||||
} else if (!localFiles.includes(remoteFilePath)) {
|
|
||||||
this.logger.log(`文件缺失: ${remoteFile.name},开始下载..`);
|
|
||||||
try {
|
try {
|
||||||
await this.openListService.downloadFile(
|
const localDirPath = path.dirname(localFilePath);
|
||||||
remoteFile.raw_url,
|
await fs.mkdir(localDirPath, { recursive: true });
|
||||||
remoteFilePath,
|
this.logger.log(`文件夹已创建: ${localDirPath}`);
|
||||||
|
const subRemoteFiles = await this.openListService.listFiles(
|
||||||
|
remoteFile.path,
|
||||||
);
|
);
|
||||||
this.logger.log(`文件下载成功: ${remoteFile.name}`);
|
if (subRemoteFiles.code === 200 && subRemoteFiles.data.content) {
|
||||||
|
await this.compareAndDownloadFiles(
|
||||||
|
localPath,
|
||||||
|
[],
|
||||||
|
subRemoteFiles.data.content,
|
||||||
|
remoteMemePath,
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`下载文件失败: ${remoteFile.name}`, error);
|
this.logger.error(`创建文件夹失败: ${remoteFile.path}`, error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!localFiles.includes(localFilePath)) {
|
||||||
|
this.logger.log(`文件缺失: ${remoteFile.path}, 开始下载..`);
|
||||||
|
try {
|
||||||
|
await this.openListService.downloadFile(
|
||||||
|
remoteFile.path,
|
||||||
|
localFilePath,
|
||||||
|
);
|
||||||
|
this.logger.log(`文件下载成功: ${remoteFile.path}`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`下载文件失败: ${remoteFile.path}`, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user