more work on attachments

* fix frontend env usage
This commit is contained in:
Philipinho
2024-05-22 23:24:57 +01:00
parent b06a78b6ec
commit ccf9d5d99f
31 changed files with 612 additions and 349 deletions

View File

@ -9,8 +9,8 @@ import {
} from '@aws-sdk/client-s3';
import { streamToBuffer } from '../storage.utils';
import { Readable } from 'stream';
import * as mime from 'mime-types';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { getMimeType } from '../../../helpers';
export class S3Driver implements StorageDriver {
private readonly s3Client: S3Client;
@ -23,8 +23,7 @@ export class S3Driver implements StorageDriver {
async upload(filePath: string, file: Buffer): Promise<void> {
try {
const contentType =
mime.contentType(filePath) || 'application/octet-stream';
const contentType = getMimeType(filePath);
const command = new PutObjectCommand({
Bucket: this.config.bucket,
@ -75,7 +74,7 @@ export class S3Driver implements StorageDriver {
}
}
getUrl(filePath: string): string {
return `${this.config.endpoint}/${this.config.bucket}/${filePath}`;
return `${this.config.baseUrl ?? this.config.endpoint}/${this.config.bucket}/${filePath}`;
}
async getSignedUrl(filePath: string, expiresIn: number): Promise<string> {

View File

@ -45,6 +45,7 @@ export const storageDriverConfigProvider = {
region: environmentService.getAwsS3Region(),
endpoint: environmentService.getAwsS3Endpoint(),
bucket: environmentService.getAwsS3Bucket(),
baseUrl: environmentService.getAwsS3Url(),
credentials: {
accessKeyId: environmentService.getAwsS3AccessKeyId(),
secretAccessKey: environmentService.getAwsS3SecretAccessKey(),

View File

@ -20,15 +20,19 @@ export class StorageService {
return this.storageDriver.exists(filePath);
}
async signedUrl(path: string, expireIn: number): Promise<string> {
async getSignedUrl(path: string, expireIn: number): Promise<string> {
return this.storageDriver.getSignedUrl(path, expireIn);
}
url(filePath: string): string {
getUrl(filePath: string): string {
return this.storageDriver.getUrl(filePath);
}
async delete(filePath: string): Promise<void> {
await this.storageDriver.delete(filePath);
}
getDriverName(): string {
return this.storageDriver.getDriverName();
}
}