mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-12-05 10:31:56 +00:00
feat:meme仓库自动更新
This commit is contained in:
parent
258de609df
commit
296bd924cd
@ -29,7 +29,7 @@ export class PathService {
|
||||
modules: path.join(this.baseDir, 'src/modules'),
|
||||
words: path.join(this.baseDir, 'private/words/src'),
|
||||
private: path.join(this.baseDir, 'private'),
|
||||
meme: path.join(this.baseDir, 'private/meme'),
|
||||
meme: path.join(this.baseDir, 'private/meme/src'),
|
||||
};
|
||||
|
||||
return type ? mappings[type] : this.baseDir;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MemeService } from './meme.service';
|
||||
import { MemeController } from './meme.controller';
|
||||
import { PathService } from '../../core/path/path.service';
|
||||
import { PathModule } from '../../core/path/path.module';
|
||||
import { AutoUpdateModule } from '../../core/auto-update/auto-update.module';
|
||||
|
||||
@Module({
|
||||
imports: [PathModule],
|
||||
imports: [PathModule, AutoUpdateModule],
|
||||
providers: [MemeService],
|
||||
controllers: [MemeController],
|
||||
})
|
||||
|
||||
@ -2,12 +2,35 @@ import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
import { PathService } from '../../core/path/path.service';
|
||||
import { AutoUpdateService } from '../../core/auto-update/auto-update.service';
|
||||
|
||||
@Injectable()
|
||||
export class MemeService {
|
||||
private readonly logger = new Logger(MemeService.name);
|
||||
private readonly updateMs = 15 * 60 * 1000; // 15min
|
||||
|
||||
constructor(@Inject(PathService) private readonly pathService: PathService) {}
|
||||
constructor(
|
||||
@Inject(PathService)
|
||||
private readonly pathService: PathService,
|
||||
@Inject(AutoUpdateService)
|
||||
private readonly autoUpdateService: AutoUpdateService,
|
||||
) {
|
||||
this.startAutoUpdate();
|
||||
}
|
||||
|
||||
private startAutoUpdate() {
|
||||
setInterval(async () => {
|
||||
const memePath = this.pathService.get('meme');
|
||||
this.logger.log('定时检查表情仓库更新..');
|
||||
const updated = await this.autoUpdateService.checkRepoForUpdates(
|
||||
memePath,
|
||||
'meme 仓库',
|
||||
);
|
||||
if (updated) {
|
||||
this.logger.log('表情仓库已更新..');
|
||||
}
|
||||
}, this.updateMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表情路径
|
||||
@ -18,7 +41,7 @@ export class MemeService {
|
||||
character?: string,
|
||||
status?: string,
|
||||
): Promise<string | null> {
|
||||
const baseDir = path.join(this.pathService.get('private'), 'meme');
|
||||
const baseDir = path.join(this.pathService.get('meme'));
|
||||
|
||||
try {
|
||||
if (!character) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user