|
|
@@ -1,6 +1,7 @@
|
|
|
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
|
|
|
import { UserEntity } from '@/server/modules/users/user.entity';
|
|
|
import process from 'node:process';
|
|
|
+import { MinioService } from './minio.service';
|
|
|
|
|
|
@Entity('file')
|
|
|
export class File {
|
|
|
@@ -28,15 +29,27 @@ export class File {
|
|
|
// return `${protocol}://${host}${port}/${bucketName}/${this.path}`;
|
|
|
// }
|
|
|
get fullUrl(): Promise<string> {
|
|
|
- return new Promise((resolve) => {
|
|
|
- // 这里可以执行异步操作
|
|
|
- const protocol = process.env.MINIO_USE_SSL !== 'false' ? 'https' : 'http';
|
|
|
- const port = process.env.MINIO_PORT ? `:${process.env.MINIO_PORT}` : '';
|
|
|
- const host = process.env.MINIO_HOST || 'localhost';
|
|
|
- const bucketName = process.env.MINIO_BUCKET_NAME || 'd8dai';
|
|
|
- resolve(`${protocol}://${host}${port}/${bucketName}/${this.path}`);
|
|
|
+ // 创建MinioService实例
|
|
|
+ const minioService = new MinioService();
|
|
|
+ // 获取配置的桶名称
|
|
|
+ const bucketName = process.env.MINIO_BUCKET_NAME || 'd8dai';
|
|
|
+
|
|
|
+ // 返回一个Promise,内部处理异步获取URL的逻辑
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ // 调用minioService的异步方法
|
|
|
+ minioService.getPresignedFileUrl(bucketName, this.path)
|
|
|
+ .then(url => {
|
|
|
+ // 成功获取URL后解析Promise
|
|
|
+ resolve(url);
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ // 处理可能的错误
|
|
|
+ console.error('获取文件预签名URL失败:', error);
|
|
|
+ reject(error); // 将错误传递出去
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
|
|
|
@Column({ name: 'description', type: 'text', nullable: true, comment: '文件描述' })
|
|
|
description!: string | null;
|