MCPcopy
hub / github.com/midwayjs/midway / COSServiceFactory

Class COSServiceFactory

packages/cos/src/manager.ts:19–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17@Provide()
18@Scope(ScopeEnum.Singleton)
19export class COSServiceFactory extends ServiceFactory<COS> {
20 @Config('cos')
21 cosConfig;
22
23 @Init()
24 async init() {
25 await this.initClients(this.cosConfig, {
26 concurrent: true,
27 });
28 }
29
30 @Logger('coreLogger')
31 logger;
32
33 @Inject()
34 protected traceService: MidwayTraceService;
35
36 @Config('cos.tracing.meta')
37 protected traceMetaResolver;
38
39 @Config('cos.tracing.enable')
40 protected traceEnabled;
41
42 @Config('cos.tracing.injector')
43 protected traceInjector;
44
45 async createClient(config: COS.COSOptions): Promise<COS> {
46 const { customClientClass, ...otherConfig } = config as any;
47 if (customClientClass) {
48 const client = new customClientClass(otherConfig);
49 this.bindTraceContext(client as any);
50 return client;
51 }
52
53 assert.ok(
54 config.SecretKey && config.SecretId,
55 '[@midwayjs/cos] secretId secretKey is required on config'
56 );
57 this.logger.info('[midway:cos] init %s', config.SecretKey);
58
59 const client = new COS(config);
60 this.bindTraceContext(client);
61 return client;
62 }
63
64 protected bindTraceContext(client: COS) {
65 if (!client || !this.traceService) {
66 return;
67 }
68
69 const rawRequest = (client as any).request?.bind(client);
70 if (!rawRequest) {
71 return;
72 }
73
74 (client as any).request = async (...args) => {
75 if (typeof args[1] === 'function') {
76 return rawRequest(...args);

Callers

nothing calls this directly

Calls 4

ConfigFunction · 0.90
InitFunction · 0.90
LoggerClass · 0.90
InjectFunction · 0.90

Tested by

no test coverage detected