chore: basic 从pipeline中移除

This commit is contained in:
xiaojunnuo
2024-11-04 15:14:56 +08:00
parent 0f572f4cb3
commit 1274f56da8
38 changed files with 128 additions and 58 deletions
+2 -1
View File
@@ -8,7 +8,7 @@ export * from './util.hash.js';
export * from './util.merge.js';
export * from './util.cache.js';
import sleep from './util.sleep.js';
import { http } from './util.request.js';
import { http, download } from './util.request.js';
import { mergeUtils } from './util.merge.js';
import { sp } from './util.sp.js';
@@ -25,6 +25,7 @@ import * as id from './util.id.js';
export const utils = {
sleep,
http,
download,
sp,
hash: hashUtils,
promises,
@@ -6,6 +6,8 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
import nodeHttp from 'http';
import * as https from 'node:https';
import { merge } from 'lodash-es';
import { safePromise } from './util.promise';
import fs from 'fs';
export class HttpError extends Error {
status?: number;
statusText?: string;
@@ -214,3 +216,38 @@ export function createAgent(opts: CreateAgentOptions = {}) {
httpsAgent,
};
}
export async function download(http: HttpClient, config: HttpRequestConfig, savePath: string) {
return safePromise((resolve, reject) => {
http
.request({
...config,
responseType: 'stream',
})
.then(res => {
const writer = fs.createWriteStream(savePath);
res.data.pipe(writer);
writer.on('close', () => {
console.log('文件下载成功');
resolve(true);
});
//error
writer.on('error', err => {
console.error('下载失败', err);
reject(err);
});
//进度条打印
const totalLength = res.headers['content-length'];
let currentLength = 0;
res.data.on('data', (chunk: any) => {
currentLength += chunk.length;
const percent = ((currentLength / totalLength) * 100).toFixed(2);
console.log(`下载进度:${percent}%`);
});
})
.catch(err => {
console.error('下载失败', err);
reject(err);
});
});
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { Registrable } from "../registry/index.js";
import { FormItemProps } from "../dt/index.js";
import { HttpClient, ILogger, utils } from "../utils/index.js";
import { HttpClient, ILogger, utils } from "@certd/basic";
import _ from "lodash-es";
import { AccessRequestHandleReq } from "../core";
@@ -3,7 +3,7 @@ import { AccessContext, AccessDefine, AccessInputDefine } from "./api.js";
import { Decorator } from "../decorator/index.js";
import _ from "lodash-es";
import { accessRegistry } from "./registry.js";
import { http, logger, utils } from "../utils/index.js";
import { http, logger, utils } from "@certd/basic";
// 提供一个唯一 key
export const ACCESS_CLASS_KEY = "pipeline:access";
+1 -1
View File
@@ -3,7 +3,7 @@ import { RunHistory, RunnableCollection } from "./run-history.js";
import { AbstractTaskPlugin, PluginDefine, pluginRegistry, TaskInstanceContext, UserInfo } from "../plugin/index.js";
import { ContextFactory, IContext } from "./context.js";
import { IStorage } from "./storage.js";
import { createAxiosService, hashUtils, logger, utils } from "../utils/index.js";
import { createAxiosService, hashUtils, logger, utils } from "@certd/basic";
import { Logger } from "log4js";
import { IAccessService } from "../access/index.js";
import { RegistryItem } from "../registry/index.js";
@@ -1,8 +1,8 @@
import { fileUtils } from "../utils/index.js";
import { fileUtils } from "@certd/basic";
import dayjs from "dayjs";
import path from "path";
import fs from "fs";
import { logger } from "../utils/index.js";
import { logger } from "@certd/basic";
export type FileStoreOptions = {
rootDir?: string;
+1 -1
View File
@@ -1,4 +1,4 @@
import { HttpClient, ILogger, utils } from "../utils/index.js";
import { HttpClient, ILogger, utils } from "@certd/basic";
export type PluginRequestHandleReq<T = any> = {
typeName: string;
+1 -1
View File
@@ -1,4 +1,4 @@
import { logger } from "../utils/index.js";
import { logger } from "@certd/basic";
import { setLogger, isPlus, isComm } from "@certd/plus-core";
setLogger(logger);
export * from "@certd/plus-core";
@@ -1,6 +1,6 @@
import { HistoryResult, Pipeline, ResultType, Runnable, RunnableMap, Stage, Step, Task } from "../dt/index.js";
import _ from "lodash-es";
import { buildLogger } from "../utils/index.js";
import { buildLogger } from "@certd/basic";
import { Logger } from "log4js";
export type HistoryStatus = {
+1 -1
View File
@@ -1,6 +1,6 @@
import fs from "fs";
import path from "path";
import { fileUtils } from "../utils/index.js";
import { fileUtils } from "@certd/basic";
export interface IStorage {
get(scope: string, namespace: string, version: string, key: string): Promise<string | null>;
-1
View File
@@ -3,7 +3,6 @@ export * from "./dt/index.js";
export * from "./access/index.js";
export * from "./registry/index.js";
export * from "./plugin/index.js";
export * from "./utils/index.js";
export * from "./context/index.js";
export * from "./decorator/index.js";
export * from "./service/index.js";
+2 -2
View File
@@ -5,8 +5,8 @@ import { Logger } from "log4js";
import { IAccessService } from "../access/index.js";
import { ICnameProxyService, IEmailService } from "../service/index.js";
import { CancelError, IContext, PluginRequestHandleReq, RunnableCollection } from "../core/index.js";
import { ILogger, logger, utils } from "../utils/index.js";
import { HttpClient } from "../utils/index.js";
import { ILogger, logger, utils } from "@certd/basic";
import { HttpClient } from "@certd/basic";
import dayjs from "dayjs";
import { IPluginConfigService } from "../service/config";
import { upperFirst } from "lodash-es";
@@ -1,4 +1,4 @@
import { isDev, logger } from "../utils/index.js";
import { isDev, logger } from "@certd/basic";
export type Registrable = {
name: string;
@@ -1 +0,0 @@
export * from "@certd/basic";