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
bdfc7f43d1
commit
beebcc14f9
@ -36,7 +36,7 @@ export class AppConfigService implements OnModuleInit {
|
|||||||
* 检查并补全 .env 文件
|
* 检查并补全 .env 文件
|
||||||
*/
|
*/
|
||||||
private checkAndSyncEnv(): void {
|
private checkAndSyncEnv(): void {
|
||||||
this.logger.log('检查并同步 .env 与 .env.example ...');
|
this.logger.log('检查并同步 .env 与 .envExample ...');
|
||||||
|
|
||||||
if (!fs.existsSync(this.envExamplePath)) {
|
if (!fs.existsSync(this.envExamplePath)) {
|
||||||
this.logger.error(`缺少 ${this.envExamplePath} 文件,无法校验`);
|
this.logger.error(`缺少 ${this.envExamplePath} 文件,无法校验`);
|
||||||
@ -67,7 +67,7 @@ export class AppConfigService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
this.logger.log('.env 已自动补全缺失项');
|
this.logger.log('.env 已自动补全缺失项');
|
||||||
} else {
|
} else {
|
||||||
this.logger.log('.env 已与 .env.example 保持一致');
|
this.logger.log('.env 已与 .envExample 保持一致');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ export class OpenListService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 列出目录下的所有文件
|
* 列出目录下的所有文件
|
||||||
* @param path 目录路径
|
* @param path 服务器目录路径
|
||||||
* @returns 目录下的文件列表
|
* @returns 目录下的文件列表
|
||||||
*/
|
*/
|
||||||
public async listFiles(path: string): Promise<FsList> {
|
public async listFiles(path: string): Promise<FsList> {
|
||||||
|
|||||||
@ -5,7 +5,8 @@ export interface FsList {
|
|||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
data: {
|
data: {
|
||||||
content: [
|
content:
|
||||||
|
| [
|
||||||
name: string,
|
name: string,
|
||||||
size: number,
|
size: number,
|
||||||
is_dir: boolean,
|
is_dir: boolean,
|
||||||
@ -13,7 +14,8 @@ export interface FsList {
|
|||||||
sign: string, //签名
|
sign: string, //签名
|
||||||
thumb: string, //略缩图
|
thumb: string, //略缩图
|
||||||
type: number, //类型
|
type: number, //类型
|
||||||
];
|
]
|
||||||
|
| null;
|
||||||
total: number; //总数
|
total: number; //总数
|
||||||
readme: string; //说明?
|
readme: string; //说明?
|
||||||
write: boolean; //是否可写入
|
write: boolean; //是否可写入
|
||||||
|
|||||||
@ -50,10 +50,20 @@ export class OpenListUtils {
|
|||||||
static async listDirectory(token: string, path: string): Promise<FsList> {
|
static async listDirectory(token: string, path: string): Promise<FsList> {
|
||||||
const url = `${this.apiBaseUrl}/api/fs/list`;
|
const url = `${this.apiBaseUrl}/api/fs/list`;
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
let data = JSON.stringify({
|
||||||
params: { path },
|
path: path,
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
|
||||||
});
|
});
|
||||||
|
//this.logger.debug(path);
|
||||||
|
let config = {
|
||||||
|
method: 'post',
|
||||||
|
url: `${url}`,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `${token}`,
|
||||||
|
},
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
let response = await axios(config);
|
||||||
this.logger.log(`列出目录${path}成功..`);
|
this.logger.log(`列出目录${path}成功..`);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -72,7 +82,7 @@ export class OpenListUtils {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
params: { path: filePath },
|
params: { path: filePath },
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `${token}` },
|
||||||
});
|
});
|
||||||
this.logger.log('获取文件信息成功..');
|
this.logger.log('获取文件信息成功..');
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|||||||
@ -71,7 +71,6 @@ export class PathService {
|
|||||||
this.logger.debug(`成功创建目录: ${dirToCreate}`);
|
this.logger.debug(`成功创建目录: ${dirToCreate}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(`创建目录失败: ${err}`);
|
this.logger.error(`创建目录失败: ${err}`);
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,16 @@ import { PathModule } from '../../core/path/path.module';
|
|||||||
import { ToolsModule } from '../../core/tools/tools.module';
|
import { ToolsModule } from '../../core/tools/tools.module';
|
||||||
import { RedisModule } from '../../core/redis/redis.module';
|
import { RedisModule } from '../../core/redis/redis.module';
|
||||||
import { OpenListModule } from '../../core/openlist/openlist.module';
|
import { OpenListModule } from '../../core/openlist/openlist.module';
|
||||||
|
import { AppConfigModule } from '../../config/config.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PathModule, OpenListModule, ToolsModule, RedisModule],
|
imports: [
|
||||||
|
PathModule,
|
||||||
|
OpenListModule,
|
||||||
|
ToolsModule,
|
||||||
|
RedisModule,
|
||||||
|
AppConfigModule,
|
||||||
|
],
|
||||||
providers: [MemeService],
|
providers: [MemeService],
|
||||||
controllers: [MemeController],
|
controllers: [MemeController],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,17 +3,20 @@ import * as path from 'path';
|
|||||||
import * as fs from 'fs/promises';
|
import * as fs from 'fs/promises';
|
||||||
import { PathService } from '../../core/path/path.service';
|
import { PathService } from '../../core/path/path.service';
|
||||||
import { OpenListService } from '../../core/openlist/openlist.service';
|
import { OpenListService } from '../../core/openlist/openlist.service';
|
||||||
|
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 = 15 * 60 * 1000; // 15min
|
private readonly updateMs = 1 * 60 * 1000; // 15min
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(PathService)
|
@Inject(PathService)
|
||||||
private readonly pathService: PathService,
|
private readonly pathService: PathService,
|
||||||
@Inject(OpenListService)
|
@Inject(OpenListService)
|
||||||
private readonly openListService: OpenListService,
|
private readonly openListService: OpenListService,
|
||||||
|
@Inject(AppConfigService)
|
||||||
|
private readonly configService: AppConfigService,
|
||||||
) {
|
) {
|
||||||
this.startAutoUpdate();
|
this.startAutoUpdate();
|
||||||
}
|
}
|
||||||
@ -21,10 +24,14 @@ export class MemeService {
|
|||||||
private startAutoUpdate() {
|
private startAutoUpdate() {
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
const memePath = path.join(this.pathService.get('meme'));
|
const memePath = path.join(this.pathService.get('meme'));
|
||||||
|
const remoteMemePath = this.configService.get('OPENLIST_API_MEME_PATH');
|
||||||
|
if (remoteMemePath) {
|
||||||
this.logger.log('定时检查表情仓库更新..');
|
this.logger.log('定时检查表情仓库更新..');
|
||||||
try {
|
try {
|
||||||
const remoteFiles = await this.openListService.listFiles(memePath);
|
const remoteFiles =
|
||||||
if (remoteFiles.code === 200) {
|
await this.openListService.listFiles(remoteMemePath);
|
||||||
|
this.logger.debug(remoteFiles);
|
||||||
|
if (remoteFiles.code === 200 && remoteFiles.data.content) {
|
||||||
const remoteFileList = remoteFiles.data.content;
|
const remoteFileList = remoteFiles.data.content;
|
||||||
const localFiles = await this.getLocalFileList(memePath);
|
const localFiles = await this.getLocalFileList(memePath);
|
||||||
await this.compareAndDownloadFiles(
|
await this.compareAndDownloadFiles(
|
||||||
@ -38,6 +45,9 @@ export class MemeService {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('定时检查表情仓库更新失败..', error);
|
this.logger.error('定时检查表情仓库更新失败..', error);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.logger.warn('未配置远程表情包地址..');
|
||||||
|
}
|
||||||
}, this.updateMs);
|
}, this.updateMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user