mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: update attachment and i18n services
This commit is contained in:
parent
6aaa130bc7
commit
8326c8c121
@ -83,7 +83,8 @@ export class AttachmentService extends BaseService<Attachment> {
|
||||
if (this.getStoragePlugin()) {
|
||||
try {
|
||||
const pict = foreign_id + '.jpeg';
|
||||
const picture = await this.getStoragePlugin()?.downloadProfilePic(pict);
|
||||
const picture =
|
||||
await this.getStoragePlugin()?.downloadProfilePic?.(pict);
|
||||
return picture;
|
||||
} catch (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(),
|
||||
} as Express.Multer.File;
|
||||
try {
|
||||
await this.getStoragePlugin()?.uploadAvatar(picture);
|
||||
await this.getStoragePlugin()?.uploadAvatar?.(picture);
|
||||
this.logger.log(
|
||||
`Profile picture uploaded successfully to ${
|
||||
this.getStoragePlugin()?.name
|
||||
@ -167,7 +168,7 @@ export class AttachmentService extends BaseService<Attachment> {
|
||||
|
||||
if (this.getStoragePlugin()) {
|
||||
for (const file of files?.file) {
|
||||
const dto = await this.getStoragePlugin()?.upload(file);
|
||||
const dto = await this.getStoragePlugin()?.upload?.(file);
|
||||
if (dto) {
|
||||
const uploadedFile = await this.create(dto);
|
||||
uploadedFiles.push(uploadedFile);
|
||||
@ -204,14 +205,14 @@ export class AttachmentService extends BaseService<Attachment> {
|
||||
file: Buffer | Readable | Express.Multer.File,
|
||||
metadata: AttachmentMetadataDto,
|
||||
rootDir = config.parameters.uploadDir,
|
||||
): Promise<Attachment> {
|
||||
): Promise<Attachment | undefined> {
|
||||
if (this.getStoragePlugin()) {
|
||||
const storedDto = await this.getStoragePlugin().store(
|
||||
const storedDto = await this.getStoragePlugin()?.store?.(
|
||||
file,
|
||||
metadata,
|
||||
rootDir,
|
||||
);
|
||||
return await this.create(storedDto);
|
||||
return storedDto ? await this.create(storedDto) : undefined;
|
||||
} else {
|
||||
const uniqueFilename = generateUniqueFilename(metadata.name);
|
||||
const filePath = resolve(join(rootDir, sanitizeFilename(uniqueFilename)));
|
||||
@ -289,7 +290,7 @@ export class AttachmentService extends BaseService<Attachment> {
|
||||
async readAsBuffer(
|
||||
attachment: Attachment,
|
||||
rootDir = config.parameters.uploadDir,
|
||||
): Promise<Buffer> {
|
||||
): Promise<Buffer | undefined> {
|
||||
if (this.getStoragePlugin()) {
|
||||
return await this.getStoragePlugin()?.readAsBuffer?.(attachment);
|
||||
} else {
|
||||
|
@ -30,12 +30,12 @@ export class I18nService<
|
||||
): IfAnyOrNever<R, string, R> {
|
||||
options = {
|
||||
...options,
|
||||
lang: options.lang || this.i18nOptions.fallbackLanguage,
|
||||
defaultValue: options.defaultValue || key,
|
||||
lang: options?.lang || this.i18nOptions.fallbackLanguage,
|
||||
defaultValue: options?.defaultValue || key,
|
||||
};
|
||||
let { lang } = options;
|
||||
|
||||
lang = this.resolveLanguage(lang);
|
||||
lang = this.resolveLanguage(lang!);
|
||||
|
||||
// Translate block message, button text, ...
|
||||
if (lang in this.dynamicTranslations) {
|
||||
|
Loading…
Reference in New Issue
Block a user