feat:meme仓库自动更新

This commit is contained in:
Jerry 2025-09-04 13:38:52 +08:00
parent 258de609df
commit 296bd924cd
3 changed files with 28 additions and 5 deletions

View File

@ -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;

View File

@ -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],
})

View File

@ -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) {