mirror of
https://github.com/certd/certd.git
synced 2026-07-15 10:17:33 +08:00
fix: 修复上传到cos报runtimeDepsService未初始化的问题
This commit is contained in:
@@ -101,7 +101,7 @@ export class AliossAccess extends BaseAccess {
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
// @ts-ignore
|
||||
const OSS = await access.importRuntime("ali-oss");
|
||||
const OSS = await this.importRuntime("ali-oss");
|
||||
return new OSS.default({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { AliyunClientV2 } from "../lib/aliyun-client-v2.js";
|
||||
import { AliyunSslClient } from "../lib/ssl-client.js";
|
||||
@IsAccess({
|
||||
@@ -85,7 +85,7 @@ export class AliyunAccess extends BaseAccess {
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
endpoint,
|
||||
});
|
||||
});
|
||||
return client;
|
||||
}
|
||||
|
||||
@@ -94,8 +94,9 @@ export class AliyunAccess extends BaseAccess {
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
endpoint: endpoint,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new AliyunAccess();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ILogger } from "@certd/basic";
|
||||
import { ILogger } from "@certd/basic";
|
||||
import { AliyunAccess } from "../access/aliyun-access.js";
|
||||
import { importRuntime as importRuntimeDirect } from "@certd/pipeline";
|
||||
|
||||
export type AliyunClientV2Req = {
|
||||
action: string;
|
||||
@@ -19,18 +20,24 @@ export class AliyunClientV2 {
|
||||
logger: ILogger;
|
||||
endpoint: string;
|
||||
|
||||
|
||||
client: any;
|
||||
constructor(opts: { access: AliyunAccess; logger: ILogger; endpoint: string }) {
|
||||
this.access = opts.access;
|
||||
this.logger = opts.logger;
|
||||
this.endpoint = opts.endpoint;
|
||||
|
||||
}
|
||||
|
||||
async importRuntime(name: string) {
|
||||
return await importRuntimeDirect(name, this.logger);
|
||||
}
|
||||
|
||||
async getClient() {
|
||||
if (this.client) {
|
||||
return this.client;
|
||||
}
|
||||
const $OpenApi = await this.access.importRuntime("@alicloud/openapi-client");
|
||||
const $OpenApi = await this.importRuntime("@alicloud/openapi-client");
|
||||
// const Credential = await import("@alicloud/credentials");
|
||||
// //@ts-ignore
|
||||
// const credential = new Credential.default.default({
|
||||
@@ -52,9 +59,9 @@ export class AliyunClientV2 {
|
||||
async doRequest(req: AliyunClientV2Req) {
|
||||
const client = await this.getClient();
|
||||
|
||||
const $OpenApi = await this.access.importRuntime("@alicloud/openapi-client");
|
||||
const $Util = await this.access.importRuntime("@alicloud/tea-util");
|
||||
const OpenApiUtil = await this.access.importRuntime("@alicloud/openapi-util");
|
||||
const $OpenApi = await this.importRuntime("@alicloud/openapi-client");
|
||||
const $Util = await this.importRuntime("@alicloud/tea-util");
|
||||
const OpenApiUtil = await this.importRuntime("@alicloud/openapi-util");
|
||||
const params = new $OpenApi.Params({
|
||||
// 接口名称
|
||||
action: req.action,
|
||||
@@ -89,3 +96,4 @@ export class AliyunClientV2 {
|
||||
return res?.body;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import { getGlobalAgents, ILogger } from "@certd/basic";
|
||||
import { ImportRuntime } from "@certd/pipeline";
|
||||
import { getGlobalAgents, ILogger } from "@certd/basic";
|
||||
import { importRuntime as importRuntimeDirect } from "@certd/pipeline";
|
||||
|
||||
export class AliyunClient {
|
||||
client: any;
|
||||
logger: ILogger;
|
||||
agent: any;
|
||||
useROAClient: boolean;
|
||||
importRuntime: ImportRuntime;
|
||||
|
||||
constructor(opts: { logger: ILogger; useROAClient?: boolean; importRuntime?: ImportRuntime }) {
|
||||
|
||||
constructor(opts: { logger: ILogger; useROAClient?: boolean }) {
|
||||
this.logger = opts.logger;
|
||||
this.useROAClient = opts.useROAClient || false;
|
||||
this.importRuntime = opts.importRuntime || (async (specifier: string) => await import(specifier));
|
||||
|
||||
const agents = getGlobalAgents();
|
||||
this.agent = agents.httpsAgent;
|
||||
}
|
||||
|
||||
async importRuntime(specifier: string) {
|
||||
return await importRuntimeDirect(specifier, this.logger);
|
||||
}
|
||||
|
||||
async getSdk() {
|
||||
if (this.useROAClient) {
|
||||
return await this.getROAClient();
|
||||
@@ -78,3 +82,4 @@ export class AliyunClient {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ILogger, utils } from "@certd/basic";
|
||||
import { ILogger, utils } from "@certd/basic";
|
||||
import { AliyunAccess } from "../access/index.js";
|
||||
import { AliyunClient } from "./index.js";
|
||||
import { CertInfo, CertReader, SimpleCertDetail } from "@certd/plugin-lib";
|
||||
@@ -12,6 +12,7 @@ export type AliyunSslClientOpts = {
|
||||
logger: ILogger;
|
||||
endpoint?: string;
|
||||
region?: string;
|
||||
|
||||
};
|
||||
|
||||
export type AliyunSslGetResourceListReq = {
|
||||
@@ -42,9 +43,11 @@ export type CasCertId = {
|
||||
export class AliyunSslClient {
|
||||
opts: AliyunSslClientOpts;
|
||||
logger: ILogger;
|
||||
|
||||
constructor(opts: AliyunSslClientOpts) {
|
||||
this.opts = opts;
|
||||
this.logger = opts.logger;
|
||||
|
||||
}
|
||||
|
||||
checkRet(ret: any) {
|
||||
@@ -55,7 +58,7 @@ export class AliyunSslClient {
|
||||
|
||||
async getClient() {
|
||||
const access = this.opts.access;
|
||||
const client = new AliyunClient({ logger: this.opts.logger, importRuntime: access.importRuntime.bind(access) });
|
||||
const client = new AliyunClient({ logger: this.opts.logger });
|
||||
|
||||
let endpoint = this.opts.endpoint || "cas.aliyuncs.com";
|
||||
if (this.opts.endpoint == null && this.opts.region) {
|
||||
@@ -251,3 +254,5 @@ export class AliyunSslClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import dayjs from "dayjs";
|
||||
import dayjs from "dayjs";
|
||||
import { TencentAccess, TencentCosAccess, TencentCosClient } from "../../tencent/index.js";
|
||||
import { BaseOssClient, OssFileItem } from "../api.js";
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class TencentOssClientImpl extends BaseOssClient<TencentCosAccess
|
||||
logger: this.logger,
|
||||
region: this.access.region,
|
||||
bucket: this.access.bucket,
|
||||
});
|
||||
});
|
||||
}
|
||||
async download(filePath: string, savePath: string): Promise<void> {
|
||||
const key = this.join(this.rootDir, filePath);
|
||||
@@ -52,3 +52,4 @@ export default class TencentOssClientImpl extends BaseOssClient<TencentCosAccess
|
||||
this.logger.info(`文件删除成功: ${filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ export class TencentAccess extends BaseAccess {
|
||||
}
|
||||
|
||||
async getStsClient() {
|
||||
const sdk = await (this as any).importRuntime("tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js");
|
||||
const sdk = await this.importRuntime("tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js");
|
||||
const StsClient = sdk.v20180813.Client;
|
||||
|
||||
const clientConfig = {
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import { TencentAccess } from "../access.js";
|
||||
import { TencentAccess } from "../access.js";
|
||||
import { ILogger, safePromise } from "@certd/basic";
|
||||
import { ImportRuntime } from "@certd/pipeline";
|
||||
import fs from "fs";
|
||||
import { importRuntime as importRuntimeDirect } from "@certd/pipeline";
|
||||
|
||||
export class TencentCosClient {
|
||||
access: TencentAccess;
|
||||
logger: ILogger;
|
||||
region: string;
|
||||
bucket: string;
|
||||
importRuntime: ImportRuntime;
|
||||
|
||||
constructor(opts: { access: TencentAccess; logger: ILogger; region: string; bucket: string; importRuntime?: ImportRuntime }) {
|
||||
|
||||
constructor(opts: { access: TencentAccess; logger: ILogger; region: string; bucket: string }) {
|
||||
this.access = opts.access;
|
||||
this.logger = opts.logger;
|
||||
this.bucket = opts.bucket;
|
||||
this.region = opts.region;
|
||||
this.importRuntime = opts.importRuntime || (async (specifier: string) => await import(specifier));
|
||||
|
||||
}
|
||||
|
||||
async importRuntime(specifier: string) {
|
||||
return await importRuntimeDirect(specifier, this.logger);
|
||||
}
|
||||
|
||||
async getCosClient() {
|
||||
@@ -118,3 +122,4 @@ export class TencentCosClient {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user