mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 14:41:09 +10:00
more work on attachments
* fix frontend env usage
This commit is contained in:
@ -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> {
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user