fix: update attachment and i18n services

This commit is contained in:
yassinedorbozgithub 2025-01-08 18:02:11 +01:00
parent 6aaa130bc7
commit 8326c8c121
2 changed files with 11 additions and 10 deletions

View File

@ -83,7 +83,8 @@ export class AttachmentService extends BaseService<Attachment> {
if (this.getStoragePlugin()) { if (this.getStoragePlugin()) {
try { try {
const pict = foreign_id + '.jpeg'; const pict = foreign_id + '.jpeg';
const picture = await this.getStoragePlugin()?.downloadProfilePic(pict); const picture =
await this.getStoragePlugin()?.downloadProfilePic?.(pict);
return picture; return picture;
} catch (err) { } catch (err) {
this.logger.error('Error downloading profile picture', err); this.logger.error('Error downloading profile picture', err);
@ -117,7 +118,7 @@ export class AttachmentService extends BaseService<Attachment> {
buffer: Buffer.isBuffer(data) ? data : await data.buffer(), buffer: Buffer.isBuffer(data) ? data : await data.buffer(),
} as Express.Multer.File; } as Express.Multer.File;
try { try {
await this.getStoragePlugin()?.uploadAvatar(picture); await this.getStoragePlugin()?.uploadAvatar?.(picture);
this.logger.log( this.logger.log(
`Profile picture uploaded successfully to ${ `Profile picture uploaded successfully to ${
this.getStoragePlugin()?.name this.getStoragePlugin()?.name
@ -167,7 +168,7 @@ export class AttachmentService extends BaseService<Attachment> {
if (this.getStoragePlugin()) { if (this.getStoragePlugin()) {
for (const file of files?.file) { for (const file of files?.file) {
const dto = await this.getStoragePlugin()?.upload(file); const dto = await this.getStoragePlugin()?.upload?.(file);
if (dto) { if (dto) {
const uploadedFile = await this.create(dto); const uploadedFile = await this.create(dto);
uploadedFiles.push(uploadedFile); uploadedFiles.push(uploadedFile);
@ -204,14 +205,14 @@ export class AttachmentService extends BaseService<Attachment> {
file: Buffer | Readable | Express.Multer.File, file: Buffer | Readable | Express.Multer.File,
metadata: AttachmentMetadataDto, metadata: AttachmentMetadataDto,
rootDir = config.parameters.uploadDir, rootDir = config.parameters.uploadDir,
): Promise<Attachment> { ): Promise<Attachment | undefined> {
if (this.getStoragePlugin()) { if (this.getStoragePlugin()) {
const storedDto = await this.getStoragePlugin().store( const storedDto = await this.getStoragePlugin()?.store?.(
file, file,
metadata, metadata,
rootDir, rootDir,
); );
return await this.create(storedDto); return storedDto ? await this.create(storedDto) : undefined;
} else { } else {
const uniqueFilename = generateUniqueFilename(metadata.name); const uniqueFilename = generateUniqueFilename(metadata.name);
const filePath = resolve(join(rootDir, sanitizeFilename(uniqueFilename))); const filePath = resolve(join(rootDir, sanitizeFilename(uniqueFilename)));
@ -289,7 +290,7 @@ export class AttachmentService extends BaseService<Attachment> {
async readAsBuffer( async readAsBuffer(
attachment: Attachment, attachment: Attachment,
rootDir = config.parameters.uploadDir, rootDir = config.parameters.uploadDir,
): Promise<Buffer> { ): Promise<Buffer | undefined> {
if (this.getStoragePlugin()) { if (this.getStoragePlugin()) {
return await this.getStoragePlugin()?.readAsBuffer?.(attachment); return await this.getStoragePlugin()?.readAsBuffer?.(attachment);
} else { } else {

View File

@ -30,12 +30,12 @@ export class I18nService<
): IfAnyOrNever<R, string, R> { ): IfAnyOrNever<R, string, R> {
options = { options = {
...options, ...options,
lang: options.lang || this.i18nOptions.fallbackLanguage, lang: options?.lang || this.i18nOptions.fallbackLanguage,
defaultValue: options.defaultValue || key, defaultValue: options?.defaultValue || key,
}; };
let { lang } = options; let { lang } = options;
lang = this.resolveLanguage(lang); lang = this.resolveLanguage(lang!);
// Translate block message, button text, ... // Translate block message, button text, ...
if (lang in this.dynamicTranslations) { if (lang in this.dynamicTranslations) {