@wzyjs/utils 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/dayjs/index.d.ts +1 -1
- package/dist/common/index.d.ts +1 -1
- package/dist/node/file/index.d.ts +63 -0
- package/dist/node/{mail.d.ts → mail/index.d.ts} +1 -1
- package/dist/node/oss/ali.d.ts +14 -0
- package/dist/node/oss/cloudflare.d.ts +20 -0
- package/dist/node/oss/index.d.ts +2 -0
- package/dist/node.cjs.js +263 -81
- package/dist/node.d.ts +4 -5
- package/dist/node.esm.js +261 -79
- package/dist/web.cjs.js +0 -2
- package/dist/web.esm.js +0 -3
- package/package.json +5 -4
- package/dist/node/file.d.ts +0 -2
- package/dist/node/oss.d.ts +0 -9
- /package/dist/node/{cron.d.ts → cron/index.d.ts} +0 -0
|
@@ -15,7 +15,7 @@ export declare enum Timezone {
|
|
|
15
15
|
}
|
|
16
16
|
export declare const initChinaDayjs: () => typeof dayjs;
|
|
17
17
|
export declare const chinaDayjs: typeof dayjs;
|
|
18
|
-
export { Dayjs } from 'dayjs';
|
|
18
|
+
export type { Dayjs } from 'dayjs';
|
|
19
19
|
declare const _default: typeof dayjs & {
|
|
20
20
|
isBetween: typeof isBetween;
|
|
21
21
|
isSameOrAfter: typeof isSameOrAfter;
|
package/dist/common/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export * as ai from './ai';
|
|
|
2
2
|
export * from './base';
|
|
3
3
|
export * from './enum';
|
|
4
4
|
export * from './image';
|
|
5
|
-
export { default as dayjs, Dayjs, Timezone, initChinaDayjs, chinaDayjs } from './dayjs';
|
|
5
|
+
export { default as dayjs, type Dayjs, Timezone, initChinaDayjs, chinaDayjs } from './dayjs';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export declare const getMimeType: (fileName: string) => string;
|
|
2
|
+
export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => Promise<void>;
|
|
3
|
+
export declare const downloadFile: (httpUrl: string, outputPath?: string) => Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* 上传文件参数
|
|
6
|
+
*/
|
|
7
|
+
export interface UploadFileParams {
|
|
8
|
+
/**
|
|
9
|
+
* 文件来源类型
|
|
10
|
+
* - 'url': 远程文件 URL 地址
|
|
11
|
+
* - 'path': 本地文件路径
|
|
12
|
+
* - 'buffer': 文件 Buffer 对象
|
|
13
|
+
* - 'file': 浏览器 File 对象
|
|
14
|
+
*/
|
|
15
|
+
type: 'url' | 'path' | 'buffer' | 'file';
|
|
16
|
+
/**
|
|
17
|
+
* 文件内容
|
|
18
|
+
* - type='url' 时,为 string 类型的 URL
|
|
19
|
+
* - type='path' 时,为 string 类型的本地路径
|
|
20
|
+
* - type='buffer' 时,为 Buffer 对象
|
|
21
|
+
* - type='file' 时,为 File 对象
|
|
22
|
+
*/
|
|
23
|
+
file: string | Buffer | File;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 文件处理结果
|
|
27
|
+
*/
|
|
28
|
+
export interface UploadFileResult {
|
|
29
|
+
/** 文件内容 Buffer */
|
|
30
|
+
buffer: Buffer;
|
|
31
|
+
/** 原始文件名 */
|
|
32
|
+
originalName: string;
|
|
33
|
+
/** 生成的唯一文件名 */
|
|
34
|
+
finalFileName: string;
|
|
35
|
+
/** 文件内容的 MD5 哈希值 */
|
|
36
|
+
hash: string;
|
|
37
|
+
/** 文件的 MIME 类型 */
|
|
38
|
+
mimeType: string;
|
|
39
|
+
/** 文件大小(字节) */
|
|
40
|
+
size: number;
|
|
41
|
+
/** 文件扩展名(包含点,如 .png) */
|
|
42
|
+
ext: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 处理各种类型的文件输入,将其统一转换为标准的文件信息对象
|
|
46
|
+
*
|
|
47
|
+
* @description
|
|
48
|
+
* 该函数用于处理不同来源的文件(URL、本地路径、Buffer、File对象),
|
|
49
|
+
* 并返回包含文件Buffer、哈希值、MIME类型等信息的统一格式对象。
|
|
50
|
+
*
|
|
51
|
+
* @param params - 上传文件参数 {@link UploadFileParams}
|
|
52
|
+
* @returns 返回处理后的文件信息 {@link UploadFileResult}
|
|
53
|
+
* @throws 当参数类型不匹配或文件读取/下载失败时抛出错误
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // 处理 URL
|
|
57
|
+
* const result = await processFile({ type: 'url', file: 'https://example.com/image.png' });
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // 处理本地路径
|
|
61
|
+
* const result = await processFile({ type: 'path', file: '/tmp/image.png' });
|
|
62
|
+
*/
|
|
63
|
+
export declare const processFile: (params: UploadFileParams) => Promise<UploadFileResult>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface UploadFile {
|
|
2
|
+
buffer: Buffer;
|
|
3
|
+
fileName: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 上传文件到 OSS
|
|
7
|
+
* @param params - 上传参数
|
|
8
|
+
* @returns 上传后的文件信息 { url, name }
|
|
9
|
+
*/
|
|
10
|
+
export declare const uploadFileToOss: (params: UploadFile) => Promise<{
|
|
11
|
+
url: string;
|
|
12
|
+
objectKey: string;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface UploadFile {
|
|
2
|
+
buffer: Buffer;
|
|
3
|
+
fileName: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 上传文件到 Cloudflare R2
|
|
8
|
+
* @param params - 上传参数
|
|
9
|
+
* @returns 上传后的文件信息 { url, name }
|
|
10
|
+
*/
|
|
11
|
+
export declare function uploadFile(params: UploadFile): Promise<{
|
|
12
|
+
url: string;
|
|
13
|
+
objectKey: string;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* 从 Cloudflare R2 删除文件
|
|
17
|
+
* @param objectKey - 文件在 S3 中的 Key
|
|
18
|
+
*/
|
|
19
|
+
export declare function deleteFile(objectKey: string): Promise<void>;
|
|
20
|
+
export {};
|
package/dist/node.cjs.js
CHANGED
|
@@ -5463,7 +5463,6 @@ __export(exports_node, {
|
|
|
5463
5463
|
watch: () => watch,
|
|
5464
5464
|
void: () => voidType,
|
|
5465
5465
|
util: () => util,
|
|
5466
|
-
uploadFile: () => uploadFile,
|
|
5467
5466
|
unknown: () => unknownType,
|
|
5468
5467
|
union: () => unionType,
|
|
5469
5468
|
undefined: () => undefinedType,
|
|
@@ -5476,10 +5475,7 @@ __export(exports_node, {
|
|
|
5476
5475
|
shuffleArray: () => shuffleArray,
|
|
5477
5476
|
setErrorMap: () => setErrorMap,
|
|
5478
5477
|
set: () => setType,
|
|
5479
|
-
sendMail: () => sendMail,
|
|
5480
|
-
schedule: () => schedule,
|
|
5481
5478
|
retryPromise: () => retryPromise,
|
|
5482
|
-
replaceContentInFile: () => replaceContentInFile,
|
|
5483
5479
|
replaceByVariables: () => replaceByVariables,
|
|
5484
5480
|
replaceByRules: () => replaceByRules,
|
|
5485
5481
|
replaceAll: () => replaceAll,
|
|
@@ -5492,6 +5488,7 @@ __export(exports_node, {
|
|
|
5492
5488
|
pipeline: () => pipelineType,
|
|
5493
5489
|
performDecimalOperation: () => performDecimalOperation,
|
|
5494
5490
|
ostring: () => ostring,
|
|
5491
|
+
oss: () => exports_oss,
|
|
5495
5492
|
optionsToEnum: () => optionsToEnum,
|
|
5496
5493
|
optional: () => optionalType,
|
|
5497
5494
|
onumber: () => onumber,
|
|
@@ -5507,6 +5504,7 @@ __export(exports_node, {
|
|
|
5507
5504
|
nan: () => nanType,
|
|
5508
5505
|
map: () => mapType,
|
|
5509
5506
|
makeIssue: () => makeIssue,
|
|
5507
|
+
mail: () => exports_mail,
|
|
5510
5508
|
literal: () => literalType,
|
|
5511
5509
|
limitDecimals: () => limitDecimals,
|
|
5512
5510
|
levenshteinDistance: () => levenshteinDistance,
|
|
@@ -5520,7 +5518,6 @@ __export(exports_node, {
|
|
|
5520
5518
|
isDirty: () => isDirty,
|
|
5521
5519
|
isAsync: () => isAsync,
|
|
5522
5520
|
isAborted: () => isAborted,
|
|
5523
|
-
interval: () => interval,
|
|
5524
5521
|
intersection: () => intersectionType,
|
|
5525
5522
|
instanceof: () => instanceOfType,
|
|
5526
5523
|
initChinaDayjs: () => initChinaDayjs,
|
|
@@ -5545,10 +5542,10 @@ __export(exports_node, {
|
|
|
5545
5542
|
function: () => functionType,
|
|
5546
5543
|
findItem: () => findItem,
|
|
5547
5544
|
filterParams: () => filterParams,
|
|
5545
|
+
file: () => exports_file,
|
|
5548
5546
|
executePromise: () => executePromise,
|
|
5549
5547
|
enum: () => enumType,
|
|
5550
5548
|
effect: () => effectsType,
|
|
5551
|
-
downloadFile: () => downloadFile,
|
|
5552
5549
|
discriminatedUnion: () => discriminatedUnionType,
|
|
5553
5550
|
delay: () => delay,
|
|
5554
5551
|
defaultErrorMap: () => en_default,
|
|
@@ -5556,6 +5553,7 @@ __export(exports_node, {
|
|
|
5556
5553
|
datetimeRegex: () => datetimeRegex,
|
|
5557
5554
|
date: () => dateType,
|
|
5558
5555
|
custom: () => custom,
|
|
5556
|
+
cron: () => exports_cron,
|
|
5559
5557
|
consola: () => import_consola.default,
|
|
5560
5558
|
coerce: () => coerce,
|
|
5561
5559
|
chinaDayjs: () => chinaDayjs,
|
|
@@ -5563,7 +5561,7 @@ __export(exports_node, {
|
|
|
5563
5561
|
calcJsText: () => calcJsText,
|
|
5564
5562
|
boolean: () => booleanType,
|
|
5565
5563
|
bigint: () => bigIntType,
|
|
5566
|
-
axios: () =>
|
|
5564
|
+
axios: () => import_axios8.default,
|
|
5567
5565
|
array: () => arrayType,
|
|
5568
5566
|
any: () => anyType,
|
|
5569
5567
|
amount: () => amount,
|
|
@@ -5621,9 +5619,6 @@ __export(exports_node, {
|
|
|
5621
5619
|
INVALID: () => INVALID,
|
|
5622
5620
|
Enum: () => Enum,
|
|
5623
5621
|
EMPTY_PATH: () => EMPTY_PATH,
|
|
5624
|
-
Dayjs: () => import_dayjs2.Dayjs,
|
|
5625
|
-
DataStoreOptions: () => import_nedb.DataStoreOptions,
|
|
5626
|
-
DataStore: () => import_nedb.default,
|
|
5627
5622
|
DIRTY: () => DIRTY,
|
|
5628
5623
|
BRAND: () => BRAND
|
|
5629
5624
|
});
|
|
@@ -9605,10 +9600,9 @@ var NEVER = INVALID;
|
|
|
9605
9600
|
// src/node.ts
|
|
9606
9601
|
var cheerio = __toESM(require("cheerio"));
|
|
9607
9602
|
var import_lodash = __toESM(require_lodash());
|
|
9608
|
-
var
|
|
9603
|
+
var import_axios8 = __toESM(require("axios"));
|
|
9609
9604
|
var import_json53 = __toESM(require("json5"));
|
|
9610
9605
|
var import_consola = __toESM(require("consola"));
|
|
9611
|
-
var import_nedb = __toESM(require("nedb"));
|
|
9612
9606
|
|
|
9613
9607
|
// src/common/ai/index.ts
|
|
9614
9608
|
var exports_ai = {};
|
|
@@ -12683,7 +12677,6 @@ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
|
|
|
12683
12677
|
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
|
|
12684
12678
|
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
12685
12679
|
var import_zh_cn = require("dayjs/locale/zh-cn");
|
|
12686
|
-
var import_dayjs2 = require("dayjs");
|
|
12687
12680
|
import_dayjs.default.extend(import_utc.default);
|
|
12688
12681
|
import_dayjs.default.extend(import_isBetween.default);
|
|
12689
12682
|
import_dayjs.default.extend(import_weekday.default);
|
|
@@ -12711,7 +12704,148 @@ var initChinaDayjs = () => {
|
|
|
12711
12704
|
};
|
|
12712
12705
|
var chinaDayjs = initChinaDayjs();
|
|
12713
12706
|
var dayjs_default = import_dayjs.default;
|
|
12714
|
-
// src/node/
|
|
12707
|
+
// src/node/oss/index.ts
|
|
12708
|
+
var exports_oss = {};
|
|
12709
|
+
__export(exports_oss, {
|
|
12710
|
+
cf: () => exports_cloudflare,
|
|
12711
|
+
ali: () => exports_ali
|
|
12712
|
+
});
|
|
12713
|
+
|
|
12714
|
+
// src/node/oss/ali.ts
|
|
12715
|
+
var exports_ali = {};
|
|
12716
|
+
__export(exports_ali, {
|
|
12717
|
+
uploadFileToOss: () => uploadFileToOss
|
|
12718
|
+
});
|
|
12719
|
+
var import_ali_oss = __toESM(require("ali-oss"));
|
|
12720
|
+
var oss = null;
|
|
12721
|
+
var getOssClient = () => {
|
|
12722
|
+
if (!oss) {
|
|
12723
|
+
oss = new import_ali_oss.default({
|
|
12724
|
+
region: process.env.ALI_OSS_REGION,
|
|
12725
|
+
accessKeyId: process.env.ALI_OSS_ACCESS_KEY_ID,
|
|
12726
|
+
accessKeySecret: process.env.ALI_OSS_ACCESS_KEY_SECRET,
|
|
12727
|
+
bucket: process.env.ALI_OSS_BUCKET
|
|
12728
|
+
});
|
|
12729
|
+
}
|
|
12730
|
+
return oss;
|
|
12731
|
+
};
|
|
12732
|
+
var uploadFileToOss = async (params) => {
|
|
12733
|
+
const { buffer, fileName } = params;
|
|
12734
|
+
if (!buffer) {
|
|
12735
|
+
throw new Error("Missing required parameters: buffer");
|
|
12736
|
+
}
|
|
12737
|
+
if (!fileName) {
|
|
12738
|
+
throw new Error("Missing required parameters: fileName");
|
|
12739
|
+
}
|
|
12740
|
+
const client = getOssClient();
|
|
12741
|
+
try {
|
|
12742
|
+
const { url: url2 } = await client.put(decodeURIComponent(fileName), buffer, {
|
|
12743
|
+
headers: {
|
|
12744
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
12745
|
+
}
|
|
12746
|
+
});
|
|
12747
|
+
return {
|
|
12748
|
+
url: url2,
|
|
12749
|
+
objectKey: fileName
|
|
12750
|
+
};
|
|
12751
|
+
} catch (error) {
|
|
12752
|
+
throw new Error(`上传到 OSS 失败: ${error}`);
|
|
12753
|
+
}
|
|
12754
|
+
};
|
|
12755
|
+
// src/node/oss/cloudflare.ts
|
|
12756
|
+
var exports_cloudflare = {};
|
|
12757
|
+
__export(exports_cloudflare, {
|
|
12758
|
+
uploadFile: () => uploadFile,
|
|
12759
|
+
deleteFile: () => deleteFile
|
|
12760
|
+
});
|
|
12761
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
12762
|
+
var s3Client = null;
|
|
12763
|
+
var getS3Client = () => {
|
|
12764
|
+
if (!s3Client) {
|
|
12765
|
+
s3Client = new import_client_s3.S3Client({
|
|
12766
|
+
region: "auto",
|
|
12767
|
+
endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
12768
|
+
credentials: {
|
|
12769
|
+
accessKeyId: process.env.CLOUDFLARE_ACCESS_KEY_ID,
|
|
12770
|
+
secretAccessKey: process.env.CLOUDFLARE_SECRET_ACCESS_KEY
|
|
12771
|
+
}
|
|
12772
|
+
});
|
|
12773
|
+
}
|
|
12774
|
+
return s3Client;
|
|
12775
|
+
};
|
|
12776
|
+
async function uploadFile(params) {
|
|
12777
|
+
const { buffer, mimeType, fileName } = params;
|
|
12778
|
+
if (!buffer) {
|
|
12779
|
+
throw new Error("Missing required parameters: buffer");
|
|
12780
|
+
}
|
|
12781
|
+
if (!fileName) {
|
|
12782
|
+
throw new Error("Missing required parameters: fileName");
|
|
12783
|
+
}
|
|
12784
|
+
if (!mimeType) {
|
|
12785
|
+
throw new Error("Missing required parameters: mimeType");
|
|
12786
|
+
}
|
|
12787
|
+
const client = getS3Client();
|
|
12788
|
+
try {
|
|
12789
|
+
await client.send(new import_client_s3.PutObjectCommand({
|
|
12790
|
+
Bucket: process.env.CLOUDFLARE_BUCKET,
|
|
12791
|
+
Key: fileName,
|
|
12792
|
+
Body: buffer,
|
|
12793
|
+
ContentType: mimeType,
|
|
12794
|
+
ContentDisposition: "inline",
|
|
12795
|
+
CacheControl: "public, max-age=31536000, immutable"
|
|
12796
|
+
}));
|
|
12797
|
+
const url2 = `${process.env.CLOUDFLARE_PUBLIC_URL}/${fileName}`;
|
|
12798
|
+
return {
|
|
12799
|
+
url: url2,
|
|
12800
|
+
objectKey: fileName
|
|
12801
|
+
};
|
|
12802
|
+
} catch (error) {
|
|
12803
|
+
throw new Error(`上传到 Cloudflare 失败: ${error}`);
|
|
12804
|
+
}
|
|
12805
|
+
}
|
|
12806
|
+
async function deleteFile(objectKey) {
|
|
12807
|
+
const client = getS3Client();
|
|
12808
|
+
try {
|
|
12809
|
+
await client.send(new import_client_s3.DeleteObjectCommand({
|
|
12810
|
+
Bucket: process.env.CLOUDFLARE_BUCKET,
|
|
12811
|
+
Key: objectKey
|
|
12812
|
+
}));
|
|
12813
|
+
} catch (error) {
|
|
12814
|
+
throw new Error(`从 Cloudflare 删除失败: ${error}`);
|
|
12815
|
+
}
|
|
12816
|
+
}
|
|
12817
|
+
// src/node/cron/index.ts
|
|
12818
|
+
var exports_cron = {};
|
|
12819
|
+
__export(exports_cron, {
|
|
12820
|
+
schedule: () => schedule,
|
|
12821
|
+
interval: () => interval
|
|
12822
|
+
});
|
|
12823
|
+
var import_node_cron = __toESM(require("node-cron"));
|
|
12824
|
+
var interval = (intervalMinutes, immediately, fn) => {
|
|
12825
|
+
console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
|
|
12826
|
+
if (immediately) {
|
|
12827
|
+
fn();
|
|
12828
|
+
}
|
|
12829
|
+
setInterval(() => {
|
|
12830
|
+
fn();
|
|
12831
|
+
}, intervalMinutes * 60 * 1000);
|
|
12832
|
+
};
|
|
12833
|
+
var schedule = (cronExpression, immediately, fn) => {
|
|
12834
|
+
console.log(`定时任务已启动,cron表达式: ${cronExpression}`);
|
|
12835
|
+
if (immediately) {
|
|
12836
|
+
fn();
|
|
12837
|
+
}
|
|
12838
|
+
import_node_cron.default.schedule(cronExpression, () => {
|
|
12839
|
+
fn();
|
|
12840
|
+
}, {
|
|
12841
|
+
timezone: "Asia/Shanghai"
|
|
12842
|
+
});
|
|
12843
|
+
};
|
|
12844
|
+
// src/node/mail/index.ts
|
|
12845
|
+
var exports_mail = {};
|
|
12846
|
+
__export(exports_mail, {
|
|
12847
|
+
send: () => send
|
|
12848
|
+
});
|
|
12715
12849
|
var import_nodemailer = __toESM(require("nodemailer"));
|
|
12716
12850
|
var authMap = {
|
|
12717
12851
|
163: {
|
|
@@ -12729,17 +12863,73 @@ var transporter = import_nodemailer.default.createTransport({
|
|
|
12729
12863
|
secure: true,
|
|
12730
12864
|
auth: authMap.gmail
|
|
12731
12865
|
});
|
|
12732
|
-
var
|
|
12866
|
+
var send = (config2) => {
|
|
12733
12867
|
return transporter.sendMail({
|
|
12734
12868
|
from: authMap.gmail.user,
|
|
12735
12869
|
...config2
|
|
12736
12870
|
});
|
|
12737
12871
|
};
|
|
12738
|
-
// src/node/file.ts
|
|
12872
|
+
// src/node/file/index.ts
|
|
12873
|
+
var exports_file = {};
|
|
12874
|
+
__export(exports_file, {
|
|
12875
|
+
replaceContentInFile: () => replaceContentInFile,
|
|
12876
|
+
processFile: () => processFile,
|
|
12877
|
+
getMimeType: () => getMimeType,
|
|
12878
|
+
downloadFile: () => downloadFile
|
|
12879
|
+
});
|
|
12739
12880
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
12740
12881
|
var import_axios7 = __toESM(require("axios"));
|
|
12741
12882
|
var import_url = __toESM(require("url"));
|
|
12742
12883
|
var path2 = __toESM(require("path"));
|
|
12884
|
+
var import_crypto = __toESM(require("crypto"));
|
|
12885
|
+
var getMimeType = (fileName) => {
|
|
12886
|
+
const ext = fileName.split(".").pop()?.toLowerCase();
|
|
12887
|
+
switch (ext) {
|
|
12888
|
+
case "png":
|
|
12889
|
+
return "image/png";
|
|
12890
|
+
case "jpg":
|
|
12891
|
+
case "jpeg":
|
|
12892
|
+
return "image/jpeg";
|
|
12893
|
+
case "gif":
|
|
12894
|
+
return "image/gif";
|
|
12895
|
+
case "webp":
|
|
12896
|
+
return "image/webp";
|
|
12897
|
+
case "svg":
|
|
12898
|
+
return "image/svg+xml";
|
|
12899
|
+
case "mp4":
|
|
12900
|
+
return "video/mp4";
|
|
12901
|
+
case "mp3":
|
|
12902
|
+
return "audio/mpeg";
|
|
12903
|
+
case "pdf":
|
|
12904
|
+
return "application/pdf";
|
|
12905
|
+
case "doc":
|
|
12906
|
+
return "application/msword";
|
|
12907
|
+
case "docx":
|
|
12908
|
+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
12909
|
+
case "xls":
|
|
12910
|
+
return "application/vnd.ms-excel";
|
|
12911
|
+
case "xlsx":
|
|
12912
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
12913
|
+
case "ppt":
|
|
12914
|
+
return "application/vnd.ms-powerpoint";
|
|
12915
|
+
case "pptx":
|
|
12916
|
+
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
12917
|
+
case "txt":
|
|
12918
|
+
return "text/plain";
|
|
12919
|
+
case "html":
|
|
12920
|
+
return "text/html";
|
|
12921
|
+
case "css":
|
|
12922
|
+
return "text/css";
|
|
12923
|
+
case "js":
|
|
12924
|
+
return "application/javascript";
|
|
12925
|
+
case "json":
|
|
12926
|
+
return "application/json";
|
|
12927
|
+
case "xml":
|
|
12928
|
+
return "application/xml";
|
|
12929
|
+
default:
|
|
12930
|
+
return "application/octet-stream";
|
|
12931
|
+
}
|
|
12932
|
+
};
|
|
12743
12933
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
12744
12934
|
try {
|
|
12745
12935
|
const data = await import_fs_extra.default.readFile(filePath, "utf8");
|
|
@@ -12786,82 +12976,74 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12786
12976
|
throw error;
|
|
12787
12977
|
}
|
|
12788
12978
|
};
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
-
}
|
|
12800
|
-
async function uploadFile(file, filename) {
|
|
12979
|
+
var generateUniqueFileName2 = (originalName = "") => {
|
|
12980
|
+
const ext = path2.extname(originalName);
|
|
12981
|
+
const nameWithoutExt = path2.basename(originalName, ext);
|
|
12982
|
+
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
12983
|
+
return {
|
|
12984
|
+
finalFileName,
|
|
12985
|
+
ext: ext.toLowerCase()
|
|
12986
|
+
};
|
|
12987
|
+
};
|
|
12988
|
+
var processFile = async (params) => {
|
|
12989
|
+
const { file, type } = params;
|
|
12801
12990
|
let buffer;
|
|
12802
|
-
let
|
|
12803
|
-
|
|
12804
|
-
|
|
12991
|
+
let mimeType;
|
|
12992
|
+
let originalName;
|
|
12993
|
+
switch (type) {
|
|
12994
|
+
case "url":
|
|
12995
|
+
if (typeof file !== "string") {
|
|
12996
|
+
throw new Error("当类型为 url 时,file 必须是字符串");
|
|
12997
|
+
}
|
|
12805
12998
|
try {
|
|
12806
|
-
const response = await
|
|
12999
|
+
const response = await import_axios7.default.get(file, { responseType: "arraybuffer" });
|
|
12807
13000
|
buffer = Buffer.from(response.data);
|
|
12808
13001
|
} catch (error) {
|
|
12809
13002
|
throw new Error(`无法从 URL 下载文件: ${error}`);
|
|
12810
13003
|
}
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
13004
|
+
originalName = path2.basename(new URL(file).pathname);
|
|
13005
|
+
break;
|
|
13006
|
+
case "path":
|
|
13007
|
+
if (typeof file !== "string") {
|
|
13008
|
+
throw new Error("当类型为 path 时,file 必须是字符串");
|
|
13009
|
+
}
|
|
12816
13010
|
try {
|
|
12817
|
-
buffer =
|
|
13011
|
+
buffer = import_fs_extra.default.readFileSync(file);
|
|
13012
|
+
originalName = path2.basename(file);
|
|
12818
13013
|
} catch (error) {
|
|
12819
13014
|
throw new Error(`无法读取文件路径: ${error}`);
|
|
12820
13015
|
}
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
}
|
|
12826
|
-
} else if (Buffer.isBuffer(file)) {
|
|
12827
|
-
if (!filename) {
|
|
12828
|
-
throw new Error("当文件为 Buffer 时,必须提供文件名");
|
|
12829
|
-
}
|
|
12830
|
-
buffer = file;
|
|
12831
|
-
finalFilename = filename;
|
|
12832
|
-
} else {
|
|
12833
|
-
throw new Error("不支持的文件类型");
|
|
12834
|
-
}
|
|
12835
|
-
try {
|
|
12836
|
-
const result = await oss.put(decodeURIComponent(finalFilename), buffer, {
|
|
12837
|
-
headers: {
|
|
12838
|
-
"Cache-Control": "public, max-age=31536000, immutable"
|
|
13016
|
+
break;
|
|
13017
|
+
case "file":
|
|
13018
|
+
if (!(file instanceof File)) {
|
|
13019
|
+
throw new Error("当类型为 file 时,file 必须是 File");
|
|
12839
13020
|
}
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
13021
|
+
buffer = Buffer.from(await file.arrayBuffer());
|
|
13022
|
+
mimeType = file.type;
|
|
13023
|
+
originalName = file.name || "";
|
|
13024
|
+
break;
|
|
13025
|
+
case "buffer":
|
|
13026
|
+
if (!Buffer.isBuffer(file)) {
|
|
13027
|
+
throw new Error("当类型为 buffer 时,file 必须是 Buffer");
|
|
13028
|
+
}
|
|
13029
|
+
buffer = file;
|
|
13030
|
+
break;
|
|
13031
|
+
default:
|
|
13032
|
+
throw new Error("不支持的文件类型");
|
|
12852
13033
|
}
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
console.log(`定时任务已启动,cron表达式: ${cronExpression}`);
|
|
12859
|
-
if (immediately) {
|
|
12860
|
-
fn();
|
|
13034
|
+
const size = buffer.length;
|
|
13035
|
+
const hash = import_crypto.default.createHash("md5").update(buffer).digest("hex");
|
|
13036
|
+
const { finalFileName, ext } = generateUniqueFileName2(originalName);
|
|
13037
|
+
if (!mimeType) {
|
|
13038
|
+
mimeType = getMimeType(finalFileName);
|
|
12861
13039
|
}
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
13040
|
+
return {
|
|
13041
|
+
buffer,
|
|
13042
|
+
finalFileName,
|
|
13043
|
+
originalName,
|
|
13044
|
+
hash,
|
|
13045
|
+
mimeType,
|
|
13046
|
+
size,
|
|
13047
|
+
ext
|
|
13048
|
+
};
|
|
12867
13049
|
};
|
package/dist/node.d.ts
CHANGED
|
@@ -4,9 +4,8 @@ export { default as _ } from 'lodash';
|
|
|
4
4
|
export { default as axios } from 'axios';
|
|
5
5
|
export { default as json5 } from 'json5';
|
|
6
6
|
export { default as consola } from 'consola';
|
|
7
|
-
export { default as DataStore, DataStoreOptions } from 'nedb';
|
|
8
7
|
export * from './common';
|
|
9
|
-
export * from './node/
|
|
10
|
-
export * from './node/
|
|
11
|
-
export * from './node/
|
|
12
|
-
export * from './node/
|
|
8
|
+
export * as oss from './node/oss';
|
|
9
|
+
export * as cron from './node/cron';
|
|
10
|
+
export * as mail from './node/mail';
|
|
11
|
+
export * as file from './node/file';
|
package/dist/node.esm.js
CHANGED
|
@@ -9420,7 +9420,6 @@ import * as cheerio from "cheerio";
|
|
|
9420
9420
|
import { default as default3 } from "axios";
|
|
9421
9421
|
import { default as default4 } from "json5";
|
|
9422
9422
|
import { default as default5 } from "consola";
|
|
9423
|
-
import { default as default6, DataStoreOptions } from "nedb";
|
|
9424
9423
|
|
|
9425
9424
|
// src/common/ai/index.ts
|
|
9426
9425
|
var exports_ai = {};
|
|
@@ -12495,7 +12494,6 @@ import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
|
|
|
12495
12494
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
|
12496
12495
|
import utc from "dayjs/plugin/utc";
|
|
12497
12496
|
import"dayjs/locale/zh-cn";
|
|
12498
|
-
import { Dayjs } from "dayjs";
|
|
12499
12497
|
dayjs.extend(utc);
|
|
12500
12498
|
dayjs.extend(isBetween);
|
|
12501
12499
|
dayjs.extend(weekday);
|
|
@@ -12523,7 +12521,148 @@ var initChinaDayjs = () => {
|
|
|
12523
12521
|
};
|
|
12524
12522
|
var chinaDayjs = initChinaDayjs();
|
|
12525
12523
|
var dayjs_default = dayjs;
|
|
12526
|
-
// src/node/
|
|
12524
|
+
// src/node/oss/index.ts
|
|
12525
|
+
var exports_oss = {};
|
|
12526
|
+
__export(exports_oss, {
|
|
12527
|
+
cf: () => exports_cloudflare,
|
|
12528
|
+
ali: () => exports_ali
|
|
12529
|
+
});
|
|
12530
|
+
|
|
12531
|
+
// src/node/oss/ali.ts
|
|
12532
|
+
var exports_ali = {};
|
|
12533
|
+
__export(exports_ali, {
|
|
12534
|
+
uploadFileToOss: () => uploadFileToOss
|
|
12535
|
+
});
|
|
12536
|
+
import OSS from "ali-oss";
|
|
12537
|
+
var oss = null;
|
|
12538
|
+
var getOssClient = () => {
|
|
12539
|
+
if (!oss) {
|
|
12540
|
+
oss = new OSS({
|
|
12541
|
+
region: process.env.ALI_OSS_REGION,
|
|
12542
|
+
accessKeyId: process.env.ALI_OSS_ACCESS_KEY_ID,
|
|
12543
|
+
accessKeySecret: process.env.ALI_OSS_ACCESS_KEY_SECRET,
|
|
12544
|
+
bucket: process.env.ALI_OSS_BUCKET
|
|
12545
|
+
});
|
|
12546
|
+
}
|
|
12547
|
+
return oss;
|
|
12548
|
+
};
|
|
12549
|
+
var uploadFileToOss = async (params) => {
|
|
12550
|
+
const { buffer, fileName } = params;
|
|
12551
|
+
if (!buffer) {
|
|
12552
|
+
throw new Error("Missing required parameters: buffer");
|
|
12553
|
+
}
|
|
12554
|
+
if (!fileName) {
|
|
12555
|
+
throw new Error("Missing required parameters: fileName");
|
|
12556
|
+
}
|
|
12557
|
+
const client = getOssClient();
|
|
12558
|
+
try {
|
|
12559
|
+
const { url: url2 } = await client.put(decodeURIComponent(fileName), buffer, {
|
|
12560
|
+
headers: {
|
|
12561
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
12562
|
+
}
|
|
12563
|
+
});
|
|
12564
|
+
return {
|
|
12565
|
+
url: url2,
|
|
12566
|
+
objectKey: fileName
|
|
12567
|
+
};
|
|
12568
|
+
} catch (error) {
|
|
12569
|
+
throw new Error(`上传到 OSS 失败: ${error}`);
|
|
12570
|
+
}
|
|
12571
|
+
};
|
|
12572
|
+
// src/node/oss/cloudflare.ts
|
|
12573
|
+
var exports_cloudflare = {};
|
|
12574
|
+
__export(exports_cloudflare, {
|
|
12575
|
+
uploadFile: () => uploadFile,
|
|
12576
|
+
deleteFile: () => deleteFile
|
|
12577
|
+
});
|
|
12578
|
+
import { S3Client, PutObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
12579
|
+
var s3Client = null;
|
|
12580
|
+
var getS3Client = () => {
|
|
12581
|
+
if (!s3Client) {
|
|
12582
|
+
s3Client = new S3Client({
|
|
12583
|
+
region: "auto",
|
|
12584
|
+
endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
12585
|
+
credentials: {
|
|
12586
|
+
accessKeyId: process.env.CLOUDFLARE_ACCESS_KEY_ID,
|
|
12587
|
+
secretAccessKey: process.env.CLOUDFLARE_SECRET_ACCESS_KEY
|
|
12588
|
+
}
|
|
12589
|
+
});
|
|
12590
|
+
}
|
|
12591
|
+
return s3Client;
|
|
12592
|
+
};
|
|
12593
|
+
async function uploadFile(params) {
|
|
12594
|
+
const { buffer, mimeType, fileName } = params;
|
|
12595
|
+
if (!buffer) {
|
|
12596
|
+
throw new Error("Missing required parameters: buffer");
|
|
12597
|
+
}
|
|
12598
|
+
if (!fileName) {
|
|
12599
|
+
throw new Error("Missing required parameters: fileName");
|
|
12600
|
+
}
|
|
12601
|
+
if (!mimeType) {
|
|
12602
|
+
throw new Error("Missing required parameters: mimeType");
|
|
12603
|
+
}
|
|
12604
|
+
const client = getS3Client();
|
|
12605
|
+
try {
|
|
12606
|
+
await client.send(new PutObjectCommand({
|
|
12607
|
+
Bucket: process.env.CLOUDFLARE_BUCKET,
|
|
12608
|
+
Key: fileName,
|
|
12609
|
+
Body: buffer,
|
|
12610
|
+
ContentType: mimeType,
|
|
12611
|
+
ContentDisposition: "inline",
|
|
12612
|
+
CacheControl: "public, max-age=31536000, immutable"
|
|
12613
|
+
}));
|
|
12614
|
+
const url2 = `${process.env.CLOUDFLARE_PUBLIC_URL}/${fileName}`;
|
|
12615
|
+
return {
|
|
12616
|
+
url: url2,
|
|
12617
|
+
objectKey: fileName
|
|
12618
|
+
};
|
|
12619
|
+
} catch (error) {
|
|
12620
|
+
throw new Error(`上传到 Cloudflare 失败: ${error}`);
|
|
12621
|
+
}
|
|
12622
|
+
}
|
|
12623
|
+
async function deleteFile(objectKey) {
|
|
12624
|
+
const client = getS3Client();
|
|
12625
|
+
try {
|
|
12626
|
+
await client.send(new DeleteObjectCommand({
|
|
12627
|
+
Bucket: process.env.CLOUDFLARE_BUCKET,
|
|
12628
|
+
Key: objectKey
|
|
12629
|
+
}));
|
|
12630
|
+
} catch (error) {
|
|
12631
|
+
throw new Error(`从 Cloudflare 删除失败: ${error}`);
|
|
12632
|
+
}
|
|
12633
|
+
}
|
|
12634
|
+
// src/node/cron/index.ts
|
|
12635
|
+
var exports_cron = {};
|
|
12636
|
+
__export(exports_cron, {
|
|
12637
|
+
schedule: () => schedule,
|
|
12638
|
+
interval: () => interval
|
|
12639
|
+
});
|
|
12640
|
+
import cron from "node-cron";
|
|
12641
|
+
var interval = (intervalMinutes, immediately, fn) => {
|
|
12642
|
+
console.log(`定时任务已启动,将每${intervalMinutes}分钟执行一次`);
|
|
12643
|
+
if (immediately) {
|
|
12644
|
+
fn();
|
|
12645
|
+
}
|
|
12646
|
+
setInterval(() => {
|
|
12647
|
+
fn();
|
|
12648
|
+
}, intervalMinutes * 60 * 1000);
|
|
12649
|
+
};
|
|
12650
|
+
var schedule = (cronExpression, immediately, fn) => {
|
|
12651
|
+
console.log(`定时任务已启动,cron表达式: ${cronExpression}`);
|
|
12652
|
+
if (immediately) {
|
|
12653
|
+
fn();
|
|
12654
|
+
}
|
|
12655
|
+
cron.schedule(cronExpression, () => {
|
|
12656
|
+
fn();
|
|
12657
|
+
}, {
|
|
12658
|
+
timezone: "Asia/Shanghai"
|
|
12659
|
+
});
|
|
12660
|
+
};
|
|
12661
|
+
// src/node/mail/index.ts
|
|
12662
|
+
var exports_mail = {};
|
|
12663
|
+
__export(exports_mail, {
|
|
12664
|
+
send: () => send
|
|
12665
|
+
});
|
|
12527
12666
|
import nodemailer from "nodemailer";
|
|
12528
12667
|
var authMap = {
|
|
12529
12668
|
163: {
|
|
@@ -12541,17 +12680,73 @@ var transporter = nodemailer.createTransport({
|
|
|
12541
12680
|
secure: true,
|
|
12542
12681
|
auth: authMap.gmail
|
|
12543
12682
|
});
|
|
12544
|
-
var
|
|
12683
|
+
var send = (config2) => {
|
|
12545
12684
|
return transporter.sendMail({
|
|
12546
12685
|
from: authMap.gmail.user,
|
|
12547
12686
|
...config2
|
|
12548
12687
|
});
|
|
12549
12688
|
};
|
|
12550
|
-
// src/node/file.ts
|
|
12689
|
+
// src/node/file/index.ts
|
|
12690
|
+
var exports_file = {};
|
|
12691
|
+
__export(exports_file, {
|
|
12692
|
+
replaceContentInFile: () => replaceContentInFile,
|
|
12693
|
+
processFile: () => processFile,
|
|
12694
|
+
getMimeType: () => getMimeType,
|
|
12695
|
+
downloadFile: () => downloadFile
|
|
12696
|
+
});
|
|
12551
12697
|
import fs from "fs-extra";
|
|
12552
12698
|
import axios4 from "axios";
|
|
12553
12699
|
import url2 from "url";
|
|
12554
12700
|
import * as path2 from "path";
|
|
12701
|
+
import crypto2 from "crypto";
|
|
12702
|
+
var getMimeType = (fileName) => {
|
|
12703
|
+
const ext = fileName.split(".").pop()?.toLowerCase();
|
|
12704
|
+
switch (ext) {
|
|
12705
|
+
case "png":
|
|
12706
|
+
return "image/png";
|
|
12707
|
+
case "jpg":
|
|
12708
|
+
case "jpeg":
|
|
12709
|
+
return "image/jpeg";
|
|
12710
|
+
case "gif":
|
|
12711
|
+
return "image/gif";
|
|
12712
|
+
case "webp":
|
|
12713
|
+
return "image/webp";
|
|
12714
|
+
case "svg":
|
|
12715
|
+
return "image/svg+xml";
|
|
12716
|
+
case "mp4":
|
|
12717
|
+
return "video/mp4";
|
|
12718
|
+
case "mp3":
|
|
12719
|
+
return "audio/mpeg";
|
|
12720
|
+
case "pdf":
|
|
12721
|
+
return "application/pdf";
|
|
12722
|
+
case "doc":
|
|
12723
|
+
return "application/msword";
|
|
12724
|
+
case "docx":
|
|
12725
|
+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
12726
|
+
case "xls":
|
|
12727
|
+
return "application/vnd.ms-excel";
|
|
12728
|
+
case "xlsx":
|
|
12729
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
12730
|
+
case "ppt":
|
|
12731
|
+
return "application/vnd.ms-powerpoint";
|
|
12732
|
+
case "pptx":
|
|
12733
|
+
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
12734
|
+
case "txt":
|
|
12735
|
+
return "text/plain";
|
|
12736
|
+
case "html":
|
|
12737
|
+
return "text/html";
|
|
12738
|
+
case "css":
|
|
12739
|
+
return "text/css";
|
|
12740
|
+
case "js":
|
|
12741
|
+
return "application/javascript";
|
|
12742
|
+
case "json":
|
|
12743
|
+
return "application/json";
|
|
12744
|
+
case "xml":
|
|
12745
|
+
return "application/xml";
|
|
12746
|
+
default:
|
|
12747
|
+
return "application/octet-stream";
|
|
12748
|
+
}
|
|
12749
|
+
};
|
|
12555
12750
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
12556
12751
|
try {
|
|
12557
12752
|
const data = await fs.readFile(filePath, "utf8");
|
|
@@ -12598,84 +12793,76 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12598
12793
|
throw error;
|
|
12599
12794
|
}
|
|
12600
12795
|
};
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
}
|
|
12612
|
-
async function uploadFile(file, filename) {
|
|
12796
|
+
var generateUniqueFileName2 = (originalName = "") => {
|
|
12797
|
+
const ext = path2.extname(originalName);
|
|
12798
|
+
const nameWithoutExt = path2.basename(originalName, ext);
|
|
12799
|
+
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
12800
|
+
return {
|
|
12801
|
+
finalFileName,
|
|
12802
|
+
ext: ext.toLowerCase()
|
|
12803
|
+
};
|
|
12804
|
+
};
|
|
12805
|
+
var processFile = async (params) => {
|
|
12806
|
+
const { file, type } = params;
|
|
12613
12807
|
let buffer;
|
|
12614
|
-
let
|
|
12615
|
-
|
|
12616
|
-
|
|
12808
|
+
let mimeType;
|
|
12809
|
+
let originalName;
|
|
12810
|
+
switch (type) {
|
|
12811
|
+
case "url":
|
|
12812
|
+
if (typeof file !== "string") {
|
|
12813
|
+
throw new Error("当类型为 url 时,file 必须是字符串");
|
|
12814
|
+
}
|
|
12617
12815
|
try {
|
|
12618
|
-
const response = await
|
|
12816
|
+
const response = await axios4.get(file, { responseType: "arraybuffer" });
|
|
12619
12817
|
buffer = Buffer.from(response.data);
|
|
12620
12818
|
} catch (error) {
|
|
12621
12819
|
throw new Error(`无法从 URL 下载文件: ${error}`);
|
|
12622
12820
|
}
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12821
|
+
originalName = path2.basename(new URL(file).pathname);
|
|
12822
|
+
break;
|
|
12823
|
+
case "path":
|
|
12824
|
+
if (typeof file !== "string") {
|
|
12825
|
+
throw new Error("当类型为 path 时,file 必须是字符串");
|
|
12826
|
+
}
|
|
12628
12827
|
try {
|
|
12629
|
-
buffer =
|
|
12828
|
+
buffer = fs.readFileSync(file);
|
|
12829
|
+
originalName = path2.basename(file);
|
|
12630
12830
|
} catch (error) {
|
|
12631
12831
|
throw new Error(`无法读取文件路径: ${error}`);
|
|
12632
12832
|
}
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
}
|
|
12638
|
-
} else if (Buffer.isBuffer(file)) {
|
|
12639
|
-
if (!filename) {
|
|
12640
|
-
throw new Error("当文件为 Buffer 时,必须提供文件名");
|
|
12641
|
-
}
|
|
12642
|
-
buffer = file;
|
|
12643
|
-
finalFilename = filename;
|
|
12644
|
-
} else {
|
|
12645
|
-
throw new Error("不支持的文件类型");
|
|
12646
|
-
}
|
|
12647
|
-
try {
|
|
12648
|
-
const result = await oss.put(decodeURIComponent(finalFilename), buffer, {
|
|
12649
|
-
headers: {
|
|
12650
|
-
"Cache-Control": "public, max-age=31536000, immutable"
|
|
12833
|
+
break;
|
|
12834
|
+
case "file":
|
|
12835
|
+
if (!(file instanceof File)) {
|
|
12836
|
+
throw new Error("当类型为 file 时,file 必须是 File");
|
|
12651
12837
|
}
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12838
|
+
buffer = Buffer.from(await file.arrayBuffer());
|
|
12839
|
+
mimeType = file.type;
|
|
12840
|
+
originalName = file.name || "";
|
|
12841
|
+
break;
|
|
12842
|
+
case "buffer":
|
|
12843
|
+
if (!Buffer.isBuffer(file)) {
|
|
12844
|
+
throw new Error("当类型为 buffer 时,file 必须是 Buffer");
|
|
12845
|
+
}
|
|
12846
|
+
buffer = file;
|
|
12847
|
+
break;
|
|
12848
|
+
default:
|
|
12849
|
+
throw new Error("不支持的文件类型");
|
|
12664
12850
|
}
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
console.log(`定时任务已启动,cron表达式: ${cronExpression}`);
|
|
12671
|
-
if (immediately) {
|
|
12672
|
-
fn();
|
|
12851
|
+
const size = buffer.length;
|
|
12852
|
+
const hash = crypto2.createHash("md5").update(buffer).digest("hex");
|
|
12853
|
+
const { finalFileName, ext } = generateUniqueFileName2(originalName);
|
|
12854
|
+
if (!mimeType) {
|
|
12855
|
+
mimeType = getMimeType(finalFileName);
|
|
12673
12856
|
}
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12857
|
+
return {
|
|
12858
|
+
buffer,
|
|
12859
|
+
finalFileName,
|
|
12860
|
+
originalName,
|
|
12861
|
+
hash,
|
|
12862
|
+
mimeType,
|
|
12863
|
+
size,
|
|
12864
|
+
ext
|
|
12865
|
+
};
|
|
12679
12866
|
};
|
|
12680
12867
|
var export__ = import_lodash.default;
|
|
12681
12868
|
|
|
@@ -12684,7 +12871,6 @@ export {
|
|
|
12684
12871
|
watch,
|
|
12685
12872
|
voidType as void,
|
|
12686
12873
|
util,
|
|
12687
|
-
uploadFile,
|
|
12688
12874
|
unknownType as unknown,
|
|
12689
12875
|
unionType as union,
|
|
12690
12876
|
undefinedType as undefined,
|
|
@@ -12697,10 +12883,7 @@ export {
|
|
|
12697
12883
|
shuffleArray,
|
|
12698
12884
|
setErrorMap,
|
|
12699
12885
|
setType as set,
|
|
12700
|
-
sendMail,
|
|
12701
|
-
schedule,
|
|
12702
12886
|
retryPromise,
|
|
12703
|
-
replaceContentInFile,
|
|
12704
12887
|
replaceByVariables,
|
|
12705
12888
|
replaceByRules,
|
|
12706
12889
|
replaceAll,
|
|
@@ -12713,6 +12896,7 @@ export {
|
|
|
12713
12896
|
pipelineType as pipeline,
|
|
12714
12897
|
performDecimalOperation,
|
|
12715
12898
|
ostring,
|
|
12899
|
+
exports_oss as oss,
|
|
12716
12900
|
optionsToEnum,
|
|
12717
12901
|
optionalType as optional,
|
|
12718
12902
|
onumber,
|
|
@@ -12728,6 +12912,7 @@ export {
|
|
|
12728
12912
|
nanType as nan,
|
|
12729
12913
|
mapType as map,
|
|
12730
12914
|
makeIssue,
|
|
12915
|
+
exports_mail as mail,
|
|
12731
12916
|
literalType as literal,
|
|
12732
12917
|
limitDecimals,
|
|
12733
12918
|
levenshteinDistance,
|
|
@@ -12741,7 +12926,6 @@ export {
|
|
|
12741
12926
|
isDirty,
|
|
12742
12927
|
isAsync,
|
|
12743
12928
|
isAborted,
|
|
12744
|
-
interval,
|
|
12745
12929
|
intersectionType as intersection,
|
|
12746
12930
|
instanceOfType as instanceof,
|
|
12747
12931
|
initChinaDayjs,
|
|
@@ -12766,10 +12950,10 @@ export {
|
|
|
12766
12950
|
functionType as function,
|
|
12767
12951
|
findItem,
|
|
12768
12952
|
filterParams,
|
|
12953
|
+
exports_file as file,
|
|
12769
12954
|
executePromise,
|
|
12770
12955
|
enumType as enum,
|
|
12771
12956
|
effectsType as effect,
|
|
12772
|
-
downloadFile,
|
|
12773
12957
|
discriminatedUnionType as discriminatedUnion,
|
|
12774
12958
|
delay,
|
|
12775
12959
|
en_default as defaultErrorMap,
|
|
@@ -12777,6 +12961,7 @@ export {
|
|
|
12777
12961
|
datetimeRegex,
|
|
12778
12962
|
dateType as date,
|
|
12779
12963
|
custom,
|
|
12964
|
+
exports_cron as cron,
|
|
12780
12965
|
default5 as consola,
|
|
12781
12966
|
coerce,
|
|
12782
12967
|
chinaDayjs,
|
|
@@ -12842,9 +13027,6 @@ export {
|
|
|
12842
13027
|
INVALID,
|
|
12843
13028
|
Enum,
|
|
12844
13029
|
EMPTY_PATH,
|
|
12845
|
-
Dayjs,
|
|
12846
|
-
DataStoreOptions,
|
|
12847
|
-
default6 as DataStore,
|
|
12848
13030
|
DIRTY,
|
|
12849
13031
|
BRAND
|
|
12850
13032
|
};
|
package/dist/web.cjs.js
CHANGED
|
@@ -10462,7 +10462,6 @@ __export(exports_web, {
|
|
|
10462
10462
|
INVALID: () => INVALID,
|
|
10463
10463
|
Enum: () => Enum,
|
|
10464
10464
|
EMPTY_PATH: () => EMPTY_PATH,
|
|
10465
|
-
Dayjs: () => import_dayjs2.Dayjs,
|
|
10466
10465
|
DIRTY: () => DIRTY,
|
|
10467
10466
|
BRAND: () => BRAND
|
|
10468
10467
|
});
|
|
@@ -21748,7 +21747,6 @@ var import_isSameOrAfter = __toESM(require_isSameOrAfter());
|
|
|
21748
21747
|
var import_isSameOrBefore = __toESM(require_isSameOrBefore());
|
|
21749
21748
|
var import_utc = __toESM(require_utc());
|
|
21750
21749
|
var import_zh_cn = __toESM(require_zh_cn());
|
|
21751
|
-
var import_dayjs2 = __toESM(require_dayjs_min());
|
|
21752
21750
|
import_dayjs.default.extend(import_utc.default);
|
|
21753
21751
|
import_dayjs.default.extend(import_isBetween.default);
|
|
21754
21752
|
import_dayjs.default.extend(import_weekday.default);
|
package/dist/web.esm.js
CHANGED
|
@@ -21560,7 +21560,6 @@ var import_isSameOrAfter = __toESM(require_isSameOrAfter(), 1);
|
|
|
21560
21560
|
var import_isSameOrBefore = __toESM(require_isSameOrBefore(), 1);
|
|
21561
21561
|
var import_utc = __toESM(require_utc(), 1);
|
|
21562
21562
|
var import_zh_cn = __toESM(require_zh_cn(), 1);
|
|
21563
|
-
var import_dayjs2 = __toESM(require_dayjs_min(), 1);
|
|
21564
21563
|
import_dayjs.default.extend(import_utc.default);
|
|
21565
21564
|
import_dayjs.default.extend(import_isBetween.default);
|
|
21566
21565
|
import_dayjs.default.extend(import_weekday.default);
|
|
@@ -21714,7 +21713,6 @@ var export_copy = import_copy_to_clipboard.default;
|
|
|
21714
21713
|
var export_consola = import_consola.default;
|
|
21715
21714
|
var export_classnames = import_classnames.default;
|
|
21716
21715
|
var export__ = import_lodash2.default;
|
|
21717
|
-
var export_Dayjs = import_dayjs2.Dayjs;
|
|
21718
21716
|
|
|
21719
21717
|
export {
|
|
21720
21718
|
exports_external as z,
|
|
@@ -21888,7 +21886,6 @@ export {
|
|
|
21888
21886
|
INVALID,
|
|
21889
21887
|
Enum,
|
|
21890
21888
|
EMPTY_PATH,
|
|
21891
|
-
export_Dayjs as Dayjs,
|
|
21892
21889
|
DIRTY,
|
|
21893
21890
|
BRAND
|
|
21894
21891
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build-web-esm": "bun build ./src/web.ts --outfile dist/web.esm.js --format esm",
|
|
9
9
|
"build-web-cjs": "bun build ./src/web.ts --outfile dist/web.cjs.js --format cjs",
|
|
10
|
-
"build-node-esm": "bun build ./src/node.ts --outfile dist/node.esm.js --format esm --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron",
|
|
11
|
-
"build-node-cjs": "bun build ./src/node.ts --outfile dist/node.cjs.js --format cjs --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron",
|
|
10
|
+
"build-node-esm": "bun build ./src/node.ts --outfile dist/node.esm.js --format esm --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron --external @aws-sdk/client-s3",
|
|
11
|
+
"build-node-cjs": "bun build ./src/node.ts --outfile dist/node.cjs.js --format cjs --target node --external nodemailer --external fs-extra --external axios --external node:* --external ali-oss --external nedb --external cheerio --external json5 --external consola --external dayjs --external node-cron --external @aws-sdk/client-s3",
|
|
12
12
|
"build": "rm -rf dist && npm run build-web-esm && npm run build-web-cjs && npm run build-node-esm && npm run build-node-cjs && tsc"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@aws-sdk/client-s3": "^3.1004.0",
|
|
40
41
|
"ali-oss": "^6.21.0",
|
|
41
42
|
"animejs": "^3.2.1",
|
|
42
43
|
"axios": "^1.6.2",
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"@types/nodemailer": "^6.4.7",
|
|
70
71
|
"@types/papaparse": "^5.3.15"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "74b286716c6df30605f96415a28ee8084cd18923"
|
|
73
74
|
}
|
package/dist/node/file.d.ts
DELETED
package/dist/node/oss.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
type FileInput = string | Buffer;
|
|
2
|
-
/**
|
|
3
|
-
* 上传文件到 OSS
|
|
4
|
-
* @param file - 文件,可以是 HTTP URL、本地文件路径或 Buffer
|
|
5
|
-
* @param filename - 文件名,当 file 是 Buffer 时必须提供
|
|
6
|
-
* @returns 上传后的文件 URL
|
|
7
|
-
*/
|
|
8
|
-
export declare function uploadFile(file: FileInput, filename?: string): Promise<string>;
|
|
9
|
-
export {};
|
|
File without changes
|