返回 AiToEarn
oss.provider.ts
根目录 / project / aitoearn-electron / server / src / lib / oss / oss.provider.ts
1 /*
2 * @Author: nevin
3 * @Date: 2022-02-18 09:38:19
4 * @LastEditors: nevin
5 * @LastEditTime: 2024-07-18 14:09:07
6 * @Description: 文件描述
7 */
8 import * as OSS from 'ali-oss';
9 import { Provider } from '@nestjs/common';
10
11 export class OssProvider {
12 /**
13 * 创建连接
14 * @param options
15 */
16 private static createClient(options: OSS.Options): OSS {
17 return new OSS(options);
18 }
19
20 /**
21 * 得到 oss 客户端连接的 provider
22 * @return {Provider}
23 */
24 public static createClientProvider(
25 options: OSS.Options,
26 resetName?: string,
27 ): Provider {
28 return {
29 provide: resetName || 'OSS_CLIENT_PROVIDER',
30 useFactory: () => {
31 return this.createClient(options);
32 },
33 // inject: ['OSS_CLIENT_PROVIDER'],
34 };
35 }
36 }
37
37 lines TYPESCRIPT