refactor imagemanager and demomanager
This commit is contained in:
parent
9d9a5983d8
commit
d8dd3021da
|
@ -11,22 +11,13 @@ import { DemoManagerService } from './demomanager.service';
|
|||
})
|
||||
export class DemoManagerModule implements OnModuleInit, OnModuleDestroy {
|
||||
private readonly logger = new Logger('DemoManagerModule');
|
||||
private interval: NodeJS.Timeout;
|
||||
|
||||
constructor(
|
||||
private readonly demoManagerService: DemoManagerService,
|
||||
private hostConfigService: HostConfigService,
|
||||
) {}
|
||||
|
||||
private interval: NodeJS.Timeout;
|
||||
|
||||
private async setupDemoMode() {
|
||||
this.demoManagerService.setupRoles();
|
||||
this.interval = setInterval(
|
||||
this.demoManagerService.execute.bind(this.demoManagerService),
|
||||
this.hostConfigService.getDemoInterval(),
|
||||
);
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
if (this.hostConfigService.isDemo()) {
|
||||
this.logger.log('Demo mode enabled');
|
||||
|
@ -34,6 +25,15 @@ export class DemoManagerModule implements OnModuleInit, OnModuleDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
private async setupDemoMode() {
|
||||
this.demoManagerService.setupRoles();
|
||||
this.interval = setInterval(
|
||||
// Run demoManagerService.execute() every interval
|
||||
this.demoManagerService.execute.bind(this.demoManagerService),
|
||||
this.hostConfigService.getDemoInterval(),
|
||||
);
|
||||
}
|
||||
|
||||
onModuleDestroy() {
|
||||
if (this.interval) clearInterval(this.interval);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ export class DemoManagerService {
|
|||
this.logger.warn(
|
||||
'Modifying roles for demo mode, this will not be reverted automatically',
|
||||
);
|
||||
// Could be done manually, but this makes settup up a demo instance quicker
|
||||
this.rolesService.addPermissions('guest', [Permission.ImageUpload]);
|
||||
}
|
||||
|
||||
|
@ -24,7 +25,7 @@ export class DemoManagerService {
|
|||
}
|
||||
|
||||
private async executeAsync() {
|
||||
this.logger.log('Executing demo cleanup');
|
||||
this.logger.debug('Executing demo cleanup');
|
||||
await this.imagesService.deleteAll(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@ import { MimesService } from '../../collections/imagedb/mimes.service';
|
|||
import { FullMime } from '../../models/dto/mimes.dto';
|
||||
import { EImageBackend } from '../../models/entities/image.entity';
|
||||
|
||||
// Right now this service is mostly a wrapper for the imagedbservice.
|
||||
// But in the future the actual image logic will happend here
|
||||
// And the image storing part will stay in the imagedbservice
|
||||
|
||||
@Injectable()
|
||||
export class ImageManagerService {
|
||||
constructor(
|
||||
|
@ -18,6 +22,7 @@ export class ImageManagerService {
|
|||
}
|
||||
|
||||
// Image data buffer is not included by default, this also returns that buffer
|
||||
// Dont send to client, keep in backend
|
||||
public async retrieveComplete(hash: string): AsyncFailable<Required<EImageBackend>> {
|
||||
return await this.imagesService.findOne(hash, true);
|
||||
}
|
||||
|
@ -38,6 +43,7 @@ export class ImageManagerService {
|
|||
}
|
||||
|
||||
private async process(image: Buffer, mime: FullMime): Promise<Buffer> {
|
||||
// nothing happens right now
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue