Import some changes
This commit is contained in:
parent
05fabea82b
commit
9bf2dfd6fc
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { ImageEntryVariant } from 'picsur-shared/dist/dto/image-entry-variant.enum';
|
||||
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
|
||||
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
|
||||
import { LessThan, Repository } from 'typeorm';
|
||||
import { EImageDerivativeBackend } from '../../database/entities/images/image-derivative.entity';
|
||||
import { EImageFileBackend } from '../../database/entities/images/image-file.entity';
|
||||
|
@ -57,6 +57,40 @@ export class ImageFileDBService {
|
|||
}
|
||||
}
|
||||
|
||||
public async migrateFile(
|
||||
imageId: string,
|
||||
sourceVariant: ImageEntryVariant,
|
||||
targetVariant: ImageEntryVariant,
|
||||
): AsyncFailable<EImageFileBackend> {
|
||||
try {
|
||||
const sourceFile = await this.getFile(imageId, sourceVariant);
|
||||
if (HasFailed(sourceFile)) return sourceFile;
|
||||
|
||||
sourceFile.variant = targetVariant;
|
||||
return await this.imageFileRepo.save(sourceFile);
|
||||
} catch (e) {
|
||||
return Fail(FT.Database, e);
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteFile(
|
||||
imageId: string,
|
||||
variant: ImageEntryVariant,
|
||||
): AsyncFailable<EImageFileBackend> {
|
||||
try {
|
||||
const found = await this.imageFileRepo.findOne({
|
||||
where: { image_id: imageId, variant: variant },
|
||||
});
|
||||
|
||||
if (!found) return Fail(FT.NotFound, 'Image not found');
|
||||
|
||||
await this.imageFileRepo.delete({ image_id: imageId, variant: variant });
|
||||
return found;
|
||||
} catch (e) {
|
||||
return Fail(FT.Database, e);
|
||||
}
|
||||
}
|
||||
|
||||
// This is useful because you dont have to pull the whole image file
|
||||
public async getFileTypes(
|
||||
imageId: string,
|
||||
|
|
|
@ -4,6 +4,7 @@ import { AuthConfigService } from './auth.config.service';
|
|||
import { EarlyJwtConfigService } from './early-jwt.config.service';
|
||||
import { HostConfigService } from './host.config.service';
|
||||
import { MultipartConfigService } from './multipart.config.service';
|
||||
import { RedisConfigService } from './redis.config.service';
|
||||
import { ServeStaticConfigService } from './serve-static.config.service';
|
||||
import { TypeOrmConfigService } from './type-orm.config.service';
|
||||
|
||||
|
@ -21,6 +22,7 @@ import { TypeOrmConfigService } from './type-orm.config.service';
|
|||
HostConfigService,
|
||||
AuthConfigService,
|
||||
MultipartConfigService,
|
||||
RedisConfigService
|
||||
],
|
||||
exports: [
|
||||
ConfigModule,
|
||||
|
@ -30,6 +32,7 @@ import { TypeOrmConfigService } from './type-orm.config.service';
|
|||
HostConfigService,
|
||||
AuthConfigService,
|
||||
MultipartConfigService,
|
||||
RedisConfigService
|
||||
],
|
||||
})
|
||||
export class EarlyConfigModule {}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ParseString } from 'picsur-shared/dist/util/parse-simple';
|
||||
import { EnvPrefix } from '../config.static';
|
||||
|
||||
@Injectable()
|
||||
export class RedisConfigService {
|
||||
private readonly logger = new Logger(RedisConfigService.name);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.logger.log('Redis URL: ' + this.getRedisUrl());
|
||||
}
|
||||
|
||||
public getRedisUrl(): string {
|
||||
return ParseString(
|
||||
this.configService.get(`${EnvPrefix}REDIS_URL`),
|
||||
'redis://localhost:6379',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { Multipart, MultipartFields, MultipartFile } from '@fastify/multipart';
|
||||
import { Multipart, MultipartFile } from '@fastify/multipart';
|
||||
import { Injectable, Logger, PipeTransform, Scope } from '@nestjs/common';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { Fail, FT } from 'picsur-shared/dist/types';
|
||||
|
@ -38,7 +38,7 @@ export class PostFilePipe implements PipeTransform {
|
|||
|
||||
// Return a buffer of the file
|
||||
try {
|
||||
return await files[0]?.toBuffer();
|
||||
return await files[0].toBuffer();
|
||||
} catch (e) {
|
||||
this.logger.warn(e);
|
||||
throw Fail(FT.Internal, 'Invalid file');
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export enum ImageEntryVariant {
|
||||
ORIGINAL = 'original',
|
||||
MASTER = 'master',
|
||||
INGEST = 'ingest',
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue