@wzyjs/utils 0.3.32 → 0.3.37
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/base/string.d.ts +1 -0
- package/dist/node/cors/index.d.ts +14 -0
- package/dist/node/file/index.d.ts +16 -3
- package/dist/node/network/index.d.ts +1 -0
- package/dist/node.cjs.js +118 -57
- package/dist/node.d.ts +2 -0
- package/dist/node.esm.js +118 -57
- package/dist/web.cjs.js +7 -0
- package/dist/web.esm.js +7 -0
- package/package.json +4 -3
|
@@ -4,6 +4,7 @@ export declare const replaceByRules: (str: string, rules: [string, string][]) =>
|
|
|
4
4
|
export declare const replaceByVariables: (prompt: string, variables?: {
|
|
5
5
|
[key: string]: string;
|
|
6
6
|
}) => string;
|
|
7
|
+
export declare const getSafeCallbackPath: (value: string | null, fallback: string) => string;
|
|
7
8
|
export declare const getType: (value: any) => any;
|
|
8
9
|
export declare const safeJsonParse: <T = any>(value: unknown, fallback: T) => T;
|
|
9
10
|
export declare const isJsonObject: (str: string) => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type CorsOptions = {
|
|
2
|
+
allowHeaders?: string[];
|
|
3
|
+
allowMethods?: string[];
|
|
4
|
+
maxAge?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const createCorsHeaders: (request: Request, options?: CorsOptions) => {
|
|
7
|
+
'Access-Control-Allow-Headers': string;
|
|
8
|
+
'Access-Control-Allow-Methods': string;
|
|
9
|
+
'Access-Control-Allow-Origin': string;
|
|
10
|
+
'Access-Control-Max-Age': string;
|
|
11
|
+
Vary: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const applyCorsHeaders: (request: Request, response: Response, options?: CorsOptions) => Response;
|
|
14
|
+
export declare const createCorsPreflightResponse: (request: Request, options?: CorsOptions) => Response;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
export declare const getExtFromFileName: (fileName?: string) => string;
|
|
2
|
+
export declare const getExtFromMimeType: (mimeType?: string) => string;
|
|
1
3
|
export declare const getMimeType: (fileName: string) => string;
|
|
4
|
+
export declare const normalizeDataUrlBase64: (value: string) => {
|
|
5
|
+
base64: string;
|
|
6
|
+
mimeType?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const parseBase64File: (input: {
|
|
9
|
+
fileBase64: string;
|
|
10
|
+
mimeType?: string;
|
|
11
|
+
}) => {
|
|
12
|
+
buffer: Buffer;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
};
|
|
2
15
|
export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => Promise<void>;
|
|
3
16
|
export declare const downloadFile: (httpUrl: string, outputPath?: string) => Promise<string>;
|
|
4
17
|
/**
|
|
5
|
-
*
|
|
18
|
+
* 描述 processFile 支持的文件来源和对应输入内容。
|
|
6
19
|
*/
|
|
7
20
|
export interface UploadFileParams {
|
|
8
21
|
/**
|
|
@@ -23,7 +36,7 @@ export interface UploadFileParams {
|
|
|
23
36
|
file: string | Buffer | File;
|
|
24
37
|
}
|
|
25
38
|
/**
|
|
26
|
-
*
|
|
39
|
+
* 描述 processFile 归一化后的文件元信息和内容。
|
|
27
40
|
*/
|
|
28
41
|
export interface UploadFileResult {
|
|
29
42
|
/** 文件内容 Buffer */
|
|
@@ -42,7 +55,7 @@ export interface UploadFileResult {
|
|
|
42
55
|
ext: string;
|
|
43
56
|
}
|
|
44
57
|
/**
|
|
45
|
-
*
|
|
58
|
+
* 处理各种类型的文件输入,将其统一转换为标准的文件信息对象。
|
|
46
59
|
*
|
|
47
60
|
* @description
|
|
48
61
|
* 该函数用于处理不同来源的文件(URL、本地路径、Buffer、File对象),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getLocalIp: () => string | null;
|
package/dist/node.cjs.js
CHANGED
|
@@ -5517,6 +5517,7 @@ __export(exports_node, {
|
|
|
5517
5517
|
nullable: () => nullableType,
|
|
5518
5518
|
null: () => nullType,
|
|
5519
5519
|
never: () => neverType,
|
|
5520
|
+
network: () => exports_network,
|
|
5520
5521
|
nativeEnum: () => nativeEnumType,
|
|
5521
5522
|
nan: () => nanType,
|
|
5522
5523
|
map: () => mapType,
|
|
@@ -5539,6 +5540,7 @@ __export(exports_node, {
|
|
|
5539
5540
|
getType: () => getType,
|
|
5540
5541
|
getStrLength: () => getStrLength,
|
|
5541
5542
|
getSliceStr: () => getSliceStr,
|
|
5543
|
+
getSafeCallbackPath: () => getSafeCallbackPath,
|
|
5542
5544
|
getRandomString: () => getRandomString,
|
|
5543
5545
|
getRandomColor: () => getRandomColor,
|
|
5544
5546
|
getPublicUrl: () => getPublicUrl,
|
|
@@ -5564,6 +5566,7 @@ __export(exports_node, {
|
|
|
5564
5566
|
custom: () => custom,
|
|
5565
5567
|
cron: () => exports_cron,
|
|
5566
5568
|
crawl: () => exports_crawl,
|
|
5569
|
+
cors: () => exports_cors,
|
|
5567
5570
|
consola: () => import_consola.default,
|
|
5568
5571
|
coerce: () => coerce,
|
|
5569
5572
|
cheerio: () => cheerio,
|
|
@@ -10413,6 +10416,12 @@ var replaceByVariables = (prompt, variables) => {
|
|
|
10413
10416
|
return variables[p1] ?? match;
|
|
10414
10417
|
});
|
|
10415
10418
|
};
|
|
10419
|
+
var getSafeCallbackPath = (value, fallback) => {
|
|
10420
|
+
if (!value || !value.startsWith("/") || value.startsWith("//")) {
|
|
10421
|
+
return fallback;
|
|
10422
|
+
}
|
|
10423
|
+
return value;
|
|
10424
|
+
};
|
|
10416
10425
|
var getType = (value) => {
|
|
10417
10426
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
10418
10427
|
};
|
|
@@ -10726,6 +10735,36 @@ var Timezone;
|
|
|
10726
10735
|
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
10727
10736
|
})(Timezone ||= {});
|
|
10728
10737
|
var dayjs_default = import_dayjs.default;
|
|
10738
|
+
// src/node/cors/index.ts
|
|
10739
|
+
var exports_cors = {};
|
|
10740
|
+
__export(exports_cors, {
|
|
10741
|
+
createCorsPreflightResponse: () => createCorsPreflightResponse,
|
|
10742
|
+
createCorsHeaders: () => createCorsHeaders,
|
|
10743
|
+
applyCorsHeaders: () => applyCorsHeaders
|
|
10744
|
+
});
|
|
10745
|
+
var DEFAULT_ALLOW_HEADERS = ["Authorization", "Content-Type", "X-TRPC-Source"];
|
|
10746
|
+
var DEFAULT_ALLOW_METHODS = ["GET", "POST", "OPTIONS"];
|
|
10747
|
+
var DEFAULT_MAX_AGE = "86400";
|
|
10748
|
+
var createCorsHeaders = (request, options = {}) => {
|
|
10749
|
+
const origin = request.headers.get("origin") ?? "*";
|
|
10750
|
+
return {
|
|
10751
|
+
"Access-Control-Allow-Headers": (options.allowHeaders ?? DEFAULT_ALLOW_HEADERS).join(", "),
|
|
10752
|
+
"Access-Control-Allow-Methods": (options.allowMethods ?? DEFAULT_ALLOW_METHODS).join(", "),
|
|
10753
|
+
"Access-Control-Allow-Origin": origin,
|
|
10754
|
+
"Access-Control-Max-Age": options.maxAge ?? DEFAULT_MAX_AGE,
|
|
10755
|
+
Vary: "Origin"
|
|
10756
|
+
};
|
|
10757
|
+
};
|
|
10758
|
+
var applyCorsHeaders = (request, response, options) => {
|
|
10759
|
+
Object.entries(createCorsHeaders(request, options)).forEach(([key2, value]) => {
|
|
10760
|
+
response.headers.set(key2, value);
|
|
10761
|
+
});
|
|
10762
|
+
return response;
|
|
10763
|
+
};
|
|
10764
|
+
var createCorsPreflightResponse = (request, options) => new Response(null, {
|
|
10765
|
+
headers: createCorsHeaders(request, options),
|
|
10766
|
+
status: 204
|
|
10767
|
+
});
|
|
10729
10768
|
// src/node/oss/index.ts
|
|
10730
10769
|
var exports_oss = {};
|
|
10731
10770
|
__export(exports_oss, {
|
|
@@ -10894,7 +10933,11 @@ var exports_file = {};
|
|
|
10894
10933
|
__export(exports_file, {
|
|
10895
10934
|
replaceContentInFile: () => replaceContentInFile,
|
|
10896
10935
|
processFile: () => processFile,
|
|
10936
|
+
parseBase64File: () => parseBase64File,
|
|
10937
|
+
normalizeDataUrlBase64: () => normalizeDataUrlBase64,
|
|
10897
10938
|
getMimeType: () => getMimeType,
|
|
10939
|
+
getExtFromMimeType: () => getExtFromMimeType,
|
|
10940
|
+
getExtFromFileName: () => getExtFromFileName,
|
|
10898
10941
|
downloadFile: () => downloadFile
|
|
10899
10942
|
});
|
|
10900
10943
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
@@ -10902,53 +10945,62 @@ var import_axios9 = __toESM(require("axios"));
|
|
|
10902
10945
|
var import_url = __toESM(require("url"));
|
|
10903
10946
|
var path2 = __toESM(require("path"));
|
|
10904
10947
|
var import_crypto = __toESM(require("crypto"));
|
|
10948
|
+
var mimeExtMap = {
|
|
10949
|
+
"image/png": ["png"],
|
|
10950
|
+
"image/jpeg": ["jpg", "jpeg"],
|
|
10951
|
+
"image/gif": ["gif"],
|
|
10952
|
+
"image/webp": ["webp"],
|
|
10953
|
+
"image/svg+xml": ["svg"],
|
|
10954
|
+
"video/mp4": ["mp4"],
|
|
10955
|
+
"audio/mpeg": ["mp3"],
|
|
10956
|
+
"application/pdf": ["pdf"],
|
|
10957
|
+
"application/msword": ["doc"],
|
|
10958
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ["docx"],
|
|
10959
|
+
"application/vnd.ms-excel": ["xls"],
|
|
10960
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
|
|
10961
|
+
"application/vnd.ms-powerpoint": ["ppt"],
|
|
10962
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": ["pptx"],
|
|
10963
|
+
"text/plain": ["txt"],
|
|
10964
|
+
"text/html": ["html"],
|
|
10965
|
+
"text/css": ["css"],
|
|
10966
|
+
"application/javascript": ["js"],
|
|
10967
|
+
"application/json": ["json"],
|
|
10968
|
+
"application/xml": ["xml"]
|
|
10969
|
+
};
|
|
10970
|
+
var getExtFromFileName = (fileName) => {
|
|
10971
|
+
return fileName ? path2.extname(fileName).toLowerCase() : "";
|
|
10972
|
+
};
|
|
10973
|
+
var getExtFromMimeType = (mimeType) => {
|
|
10974
|
+
const ext = mimeType ? mimeExtMap[mimeType]?.[0] : "";
|
|
10975
|
+
return ext ? `.${ext}` : "";
|
|
10976
|
+
};
|
|
10905
10977
|
var getMimeType = (fileName) => {
|
|
10906
|
-
const ext = fileName.
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
10933
|
-
case "ppt":
|
|
10934
|
-
return "application/vnd.ms-powerpoint";
|
|
10935
|
-
case "pptx":
|
|
10936
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
10937
|
-
case "txt":
|
|
10938
|
-
return "text/plain";
|
|
10939
|
-
case "html":
|
|
10940
|
-
return "text/html";
|
|
10941
|
-
case "css":
|
|
10942
|
-
return "text/css";
|
|
10943
|
-
case "js":
|
|
10944
|
-
return "application/javascript";
|
|
10945
|
-
case "json":
|
|
10946
|
-
return "application/json";
|
|
10947
|
-
case "xml":
|
|
10948
|
-
return "application/xml";
|
|
10949
|
-
default:
|
|
10950
|
-
return "application/octet-stream";
|
|
10951
|
-
}
|
|
10978
|
+
const ext = getExtFromFileName(fileName).replace(/^\./, "");
|
|
10979
|
+
const matched = Object.entries(mimeExtMap).find(([, extensions]) => extensions.includes(ext));
|
|
10980
|
+
return matched?.[0] || "application/octet-stream";
|
|
10981
|
+
};
|
|
10982
|
+
var generateUniqueFileName = (originalName = "") => {
|
|
10983
|
+
const ext = path2.extname(originalName);
|
|
10984
|
+
const nameWithoutExt = path2.basename(originalName, ext);
|
|
10985
|
+
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
10986
|
+
return {
|
|
10987
|
+
finalFileName,
|
|
10988
|
+
ext: ext.toLowerCase()
|
|
10989
|
+
};
|
|
10990
|
+
};
|
|
10991
|
+
var normalizeDataUrlBase64 = (value) => {
|
|
10992
|
+
const matched = value.match(/^data:([^;]+);base64,(.*)$/);
|
|
10993
|
+
return {
|
|
10994
|
+
base64: matched?.[2] || value,
|
|
10995
|
+
mimeType: matched?.[1]
|
|
10996
|
+
};
|
|
10997
|
+
};
|
|
10998
|
+
var parseBase64File = (input) => {
|
|
10999
|
+
const parsed = normalizeDataUrlBase64(input.fileBase64);
|
|
11000
|
+
return {
|
|
11001
|
+
buffer: Buffer.from(parsed.base64, "base64"),
|
|
11002
|
+
mimeType: input.mimeType || parsed.mimeType
|
|
11003
|
+
};
|
|
10952
11004
|
};
|
|
10953
11005
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
10954
11006
|
const data = await import_fs_extra.default.readFile(filePath, "utf8");
|
|
@@ -10962,8 +11014,8 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
|
10962
11014
|
};
|
|
10963
11015
|
var downloadFile = async (httpUrl, outputPath) => {
|
|
10964
11016
|
try {
|
|
10965
|
-
|
|
10966
|
-
|
|
11017
|
+
const parsedUrl = import_url.default.parse(httpUrl);
|
|
11018
|
+
const fileName = path2.basename(parsedUrl.pathname);
|
|
10967
11019
|
if (!outputPath) {
|
|
10968
11020
|
if (!import_fs_extra.default.existsSync(".tmp")) {
|
|
10969
11021
|
import_fs_extra.default.mkdirSync(".tmp", { recursive: true });
|
|
@@ -10987,15 +11039,6 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
10987
11039
|
throw error;
|
|
10988
11040
|
}
|
|
10989
11041
|
};
|
|
10990
|
-
var generateUniqueFileName = (originalName = "") => {
|
|
10991
|
-
const ext = path2.extname(originalName);
|
|
10992
|
-
const nameWithoutExt = path2.basename(originalName, ext);
|
|
10993
|
-
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
10994
|
-
return {
|
|
10995
|
-
finalFileName,
|
|
10996
|
-
ext: ext.toLowerCase()
|
|
10997
|
-
};
|
|
10998
|
-
};
|
|
10999
11042
|
var processFile = async (params) => {
|
|
11000
11043
|
const { file, type } = params;
|
|
11001
11044
|
let buffer;
|
|
@@ -12085,5 +12128,23 @@ var getFanqieChapterContents = async (fanqieBookId, chapterIds, sidecarOptions)
|
|
|
12085
12128
|
}
|
|
12086
12129
|
}
|
|
12087
12130
|
};
|
|
12131
|
+
// src/node/network/index.ts
|
|
12132
|
+
var exports_network = {};
|
|
12133
|
+
__export(exports_network, {
|
|
12134
|
+
getLocalIp: () => getLocalIp
|
|
12135
|
+
});
|
|
12136
|
+
var import_os = __toESM(require("os"));
|
|
12137
|
+
var getLocalIp = () => {
|
|
12138
|
+
const interfaces = import_os.default.networkInterfaces();
|
|
12139
|
+
for (const name of Object.keys(interfaces)) {
|
|
12140
|
+
for (const net of interfaces[name] || []) {
|
|
12141
|
+
if (net.family === "IPv4" && !net.internal) {
|
|
12142
|
+
return net.address;
|
|
12143
|
+
}
|
|
12144
|
+
}
|
|
12145
|
+
}
|
|
12146
|
+
return null;
|
|
12147
|
+
};
|
|
12148
|
+
|
|
12088
12149
|
// src/node.ts
|
|
12089
12150
|
var _ = import_lodash.default;
|
package/dist/node.d.ts
CHANGED
|
@@ -7,8 +7,10 @@ export { default as fs } from 'fs-extra';
|
|
|
7
7
|
import lodash from 'lodash';
|
|
8
8
|
export declare const _: lodash.LoDashStatic;
|
|
9
9
|
export * from './common';
|
|
10
|
+
export * as cors from './node/cors';
|
|
10
11
|
export * as oss from './node/oss';
|
|
11
12
|
export * as cron from './node/cron';
|
|
12
13
|
export * as mail from './node/mail';
|
|
13
14
|
export * as file from './node/file';
|
|
14
15
|
export * as crawl from './node/crawl';
|
|
16
|
+
export * as network from './node/network';
|
package/dist/node.esm.js
CHANGED
|
@@ -10240,6 +10240,12 @@ var replaceByVariables = (prompt, variables) => {
|
|
|
10240
10240
|
return variables[p1] ?? match;
|
|
10241
10241
|
});
|
|
10242
10242
|
};
|
|
10243
|
+
var getSafeCallbackPath = (value, fallback) => {
|
|
10244
|
+
if (!value || !value.startsWith("/") || value.startsWith("//")) {
|
|
10245
|
+
return fallback;
|
|
10246
|
+
}
|
|
10247
|
+
return value;
|
|
10248
|
+
};
|
|
10243
10249
|
var getType = (value) => {
|
|
10244
10250
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
10245
10251
|
};
|
|
@@ -10553,6 +10559,36 @@ var Timezone;
|
|
|
10553
10559
|
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
10554
10560
|
})(Timezone ||= {});
|
|
10555
10561
|
var dayjs_default = dayjs;
|
|
10562
|
+
// src/node/cors/index.ts
|
|
10563
|
+
var exports_cors = {};
|
|
10564
|
+
__export(exports_cors, {
|
|
10565
|
+
createCorsPreflightResponse: () => createCorsPreflightResponse,
|
|
10566
|
+
createCorsHeaders: () => createCorsHeaders,
|
|
10567
|
+
applyCorsHeaders: () => applyCorsHeaders
|
|
10568
|
+
});
|
|
10569
|
+
var DEFAULT_ALLOW_HEADERS = ["Authorization", "Content-Type", "X-TRPC-Source"];
|
|
10570
|
+
var DEFAULT_ALLOW_METHODS = ["GET", "POST", "OPTIONS"];
|
|
10571
|
+
var DEFAULT_MAX_AGE = "86400";
|
|
10572
|
+
var createCorsHeaders = (request, options = {}) => {
|
|
10573
|
+
const origin = request.headers.get("origin") ?? "*";
|
|
10574
|
+
return {
|
|
10575
|
+
"Access-Control-Allow-Headers": (options.allowHeaders ?? DEFAULT_ALLOW_HEADERS).join(", "),
|
|
10576
|
+
"Access-Control-Allow-Methods": (options.allowMethods ?? DEFAULT_ALLOW_METHODS).join(", "),
|
|
10577
|
+
"Access-Control-Allow-Origin": origin,
|
|
10578
|
+
"Access-Control-Max-Age": options.maxAge ?? DEFAULT_MAX_AGE,
|
|
10579
|
+
Vary: "Origin"
|
|
10580
|
+
};
|
|
10581
|
+
};
|
|
10582
|
+
var applyCorsHeaders = (request, response, options) => {
|
|
10583
|
+
Object.entries(createCorsHeaders(request, options)).forEach(([key2, value]) => {
|
|
10584
|
+
response.headers.set(key2, value);
|
|
10585
|
+
});
|
|
10586
|
+
return response;
|
|
10587
|
+
};
|
|
10588
|
+
var createCorsPreflightResponse = (request, options) => new Response(null, {
|
|
10589
|
+
headers: createCorsHeaders(request, options),
|
|
10590
|
+
status: 204
|
|
10591
|
+
});
|
|
10556
10592
|
// src/node/oss/index.ts
|
|
10557
10593
|
var exports_oss = {};
|
|
10558
10594
|
__export(exports_oss, {
|
|
@@ -10721,7 +10757,11 @@ var exports_file = {};
|
|
|
10721
10757
|
__export(exports_file, {
|
|
10722
10758
|
replaceContentInFile: () => replaceContentInFile,
|
|
10723
10759
|
processFile: () => processFile,
|
|
10760
|
+
parseBase64File: () => parseBase64File,
|
|
10761
|
+
normalizeDataUrlBase64: () => normalizeDataUrlBase64,
|
|
10724
10762
|
getMimeType: () => getMimeType,
|
|
10763
|
+
getExtFromMimeType: () => getExtFromMimeType,
|
|
10764
|
+
getExtFromFileName: () => getExtFromFileName,
|
|
10725
10765
|
downloadFile: () => downloadFile
|
|
10726
10766
|
});
|
|
10727
10767
|
import fs from "fs-extra";
|
|
@@ -10729,53 +10769,62 @@ import axios6 from "axios";
|
|
|
10729
10769
|
import url2 from "url";
|
|
10730
10770
|
import * as path2 from "path";
|
|
10731
10771
|
import crypto2 from "crypto";
|
|
10772
|
+
var mimeExtMap = {
|
|
10773
|
+
"image/png": ["png"],
|
|
10774
|
+
"image/jpeg": ["jpg", "jpeg"],
|
|
10775
|
+
"image/gif": ["gif"],
|
|
10776
|
+
"image/webp": ["webp"],
|
|
10777
|
+
"image/svg+xml": ["svg"],
|
|
10778
|
+
"video/mp4": ["mp4"],
|
|
10779
|
+
"audio/mpeg": ["mp3"],
|
|
10780
|
+
"application/pdf": ["pdf"],
|
|
10781
|
+
"application/msword": ["doc"],
|
|
10782
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ["docx"],
|
|
10783
|
+
"application/vnd.ms-excel": ["xls"],
|
|
10784
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
|
|
10785
|
+
"application/vnd.ms-powerpoint": ["ppt"],
|
|
10786
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": ["pptx"],
|
|
10787
|
+
"text/plain": ["txt"],
|
|
10788
|
+
"text/html": ["html"],
|
|
10789
|
+
"text/css": ["css"],
|
|
10790
|
+
"application/javascript": ["js"],
|
|
10791
|
+
"application/json": ["json"],
|
|
10792
|
+
"application/xml": ["xml"]
|
|
10793
|
+
};
|
|
10794
|
+
var getExtFromFileName = (fileName) => {
|
|
10795
|
+
return fileName ? path2.extname(fileName).toLowerCase() : "";
|
|
10796
|
+
};
|
|
10797
|
+
var getExtFromMimeType = (mimeType) => {
|
|
10798
|
+
const ext = mimeType ? mimeExtMap[mimeType]?.[0] : "";
|
|
10799
|
+
return ext ? `.${ext}` : "";
|
|
10800
|
+
};
|
|
10732
10801
|
var getMimeType = (fileName) => {
|
|
10733
|
-
const ext = fileName.
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
10760
|
-
case "ppt":
|
|
10761
|
-
return "application/vnd.ms-powerpoint";
|
|
10762
|
-
case "pptx":
|
|
10763
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
10764
|
-
case "txt":
|
|
10765
|
-
return "text/plain";
|
|
10766
|
-
case "html":
|
|
10767
|
-
return "text/html";
|
|
10768
|
-
case "css":
|
|
10769
|
-
return "text/css";
|
|
10770
|
-
case "js":
|
|
10771
|
-
return "application/javascript";
|
|
10772
|
-
case "json":
|
|
10773
|
-
return "application/json";
|
|
10774
|
-
case "xml":
|
|
10775
|
-
return "application/xml";
|
|
10776
|
-
default:
|
|
10777
|
-
return "application/octet-stream";
|
|
10778
|
-
}
|
|
10802
|
+
const ext = getExtFromFileName(fileName).replace(/^\./, "");
|
|
10803
|
+
const matched = Object.entries(mimeExtMap).find(([, extensions]) => extensions.includes(ext));
|
|
10804
|
+
return matched?.[0] || "application/octet-stream";
|
|
10805
|
+
};
|
|
10806
|
+
var generateUniqueFileName = (originalName = "") => {
|
|
10807
|
+
const ext = path2.extname(originalName);
|
|
10808
|
+
const nameWithoutExt = path2.basename(originalName, ext);
|
|
10809
|
+
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
10810
|
+
return {
|
|
10811
|
+
finalFileName,
|
|
10812
|
+
ext: ext.toLowerCase()
|
|
10813
|
+
};
|
|
10814
|
+
};
|
|
10815
|
+
var normalizeDataUrlBase64 = (value) => {
|
|
10816
|
+
const matched = value.match(/^data:([^;]+);base64,(.*)$/);
|
|
10817
|
+
return {
|
|
10818
|
+
base64: matched?.[2] || value,
|
|
10819
|
+
mimeType: matched?.[1]
|
|
10820
|
+
};
|
|
10821
|
+
};
|
|
10822
|
+
var parseBase64File = (input) => {
|
|
10823
|
+
const parsed = normalizeDataUrlBase64(input.fileBase64);
|
|
10824
|
+
return {
|
|
10825
|
+
buffer: Buffer.from(parsed.base64, "base64"),
|
|
10826
|
+
mimeType: input.mimeType || parsed.mimeType
|
|
10827
|
+
};
|
|
10779
10828
|
};
|
|
10780
10829
|
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
10781
10830
|
const data = await fs.readFile(filePath, "utf8");
|
|
@@ -10789,8 +10838,8 @@ var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
|
10789
10838
|
};
|
|
10790
10839
|
var downloadFile = async (httpUrl, outputPath) => {
|
|
10791
10840
|
try {
|
|
10792
|
-
|
|
10793
|
-
|
|
10841
|
+
const parsedUrl = url2.parse(httpUrl);
|
|
10842
|
+
const fileName = path2.basename(parsedUrl.pathname);
|
|
10794
10843
|
if (!outputPath) {
|
|
10795
10844
|
if (!fs.existsSync(".tmp")) {
|
|
10796
10845
|
fs.mkdirSync(".tmp", { recursive: true });
|
|
@@ -10814,15 +10863,6 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
10814
10863
|
throw error;
|
|
10815
10864
|
}
|
|
10816
10865
|
};
|
|
10817
|
-
var generateUniqueFileName = (originalName = "") => {
|
|
10818
|
-
const ext = path2.extname(originalName);
|
|
10819
|
-
const nameWithoutExt = path2.basename(originalName, ext);
|
|
10820
|
-
const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
|
|
10821
|
-
return {
|
|
10822
|
-
finalFileName,
|
|
10823
|
-
ext: ext.toLowerCase()
|
|
10824
|
-
};
|
|
10825
|
-
};
|
|
10826
10866
|
var processFile = async (params) => {
|
|
10827
10867
|
const { file, type } = params;
|
|
10828
10868
|
let buffer;
|
|
@@ -11912,6 +11952,24 @@ var getFanqieChapterContents = async (fanqieBookId, chapterIds, sidecarOptions)
|
|
|
11912
11952
|
}
|
|
11913
11953
|
}
|
|
11914
11954
|
};
|
|
11955
|
+
// src/node/network/index.ts
|
|
11956
|
+
var exports_network = {};
|
|
11957
|
+
__export(exports_network, {
|
|
11958
|
+
getLocalIp: () => getLocalIp
|
|
11959
|
+
});
|
|
11960
|
+
import os from "os";
|
|
11961
|
+
var getLocalIp = () => {
|
|
11962
|
+
const interfaces = os.networkInterfaces();
|
|
11963
|
+
for (const name of Object.keys(interfaces)) {
|
|
11964
|
+
for (const net of interfaces[name] || []) {
|
|
11965
|
+
if (net.family === "IPv4" && !net.internal) {
|
|
11966
|
+
return net.address;
|
|
11967
|
+
}
|
|
11968
|
+
}
|
|
11969
|
+
}
|
|
11970
|
+
return null;
|
|
11971
|
+
};
|
|
11972
|
+
|
|
11915
11973
|
// src/node.ts
|
|
11916
11974
|
var _ = import_lodash.default;
|
|
11917
11975
|
export {
|
|
@@ -11952,6 +12010,7 @@ export {
|
|
|
11952
12010
|
nullableType as nullable,
|
|
11953
12011
|
nullType as null,
|
|
11954
12012
|
neverType as never,
|
|
12013
|
+
exports_network as network,
|
|
11955
12014
|
nativeEnumType as nativeEnum,
|
|
11956
12015
|
nanType as nan,
|
|
11957
12016
|
mapType as map,
|
|
@@ -11974,6 +12033,7 @@ export {
|
|
|
11974
12033
|
getType,
|
|
11975
12034
|
getStrLength,
|
|
11976
12035
|
getSliceStr,
|
|
12036
|
+
getSafeCallbackPath,
|
|
11977
12037
|
getRandomString,
|
|
11978
12038
|
getRandomColor,
|
|
11979
12039
|
getPublicUrl,
|
|
@@ -11999,6 +12059,7 @@ export {
|
|
|
11999
12059
|
custom,
|
|
12000
12060
|
exports_cron as cron,
|
|
12001
12061
|
exports_crawl as crawl,
|
|
12062
|
+
exports_cors as cors,
|
|
12002
12063
|
default4 as consola,
|
|
12003
12064
|
coerce,
|
|
12004
12065
|
cheerio,
|
package/dist/web.cjs.js
CHANGED
|
@@ -10861,6 +10861,7 @@ __export(exports_web, {
|
|
|
10861
10861
|
getType: () => getType,
|
|
10862
10862
|
getStrLength: () => getStrLength,
|
|
10863
10863
|
getSliceStr: () => getSliceStr,
|
|
10864
|
+
getSafeCallbackPath: () => getSafeCallbackPath,
|
|
10864
10865
|
getRandomString: () => getRandomString,
|
|
10865
10866
|
getRandomColor: () => getRandomColor,
|
|
10866
10867
|
getPublicUrl: () => getPublicUrl,
|
|
@@ -20350,6 +20351,12 @@ var replaceByVariables = (prompt, variables) => {
|
|
|
20350
20351
|
return variables[p1] ?? match;
|
|
20351
20352
|
});
|
|
20352
20353
|
};
|
|
20354
|
+
var getSafeCallbackPath = (value, fallback) => {
|
|
20355
|
+
if (!value || !value.startsWith("/") || value.startsWith("//")) {
|
|
20356
|
+
return fallback;
|
|
20357
|
+
}
|
|
20358
|
+
return value;
|
|
20359
|
+
};
|
|
20353
20360
|
var getType = (value) => {
|
|
20354
20361
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
20355
20362
|
};
|
package/dist/web.esm.js
CHANGED
|
@@ -20181,6 +20181,12 @@ var replaceByVariables = (prompt, variables) => {
|
|
|
20181
20181
|
return variables[p1] ?? match;
|
|
20182
20182
|
});
|
|
20183
20183
|
};
|
|
20184
|
+
var getSafeCallbackPath = (value, fallback) => {
|
|
20185
|
+
if (!value || !value.startsWith("/") || value.startsWith("//")) {
|
|
20186
|
+
return fallback;
|
|
20187
|
+
}
|
|
20188
|
+
return value;
|
|
20189
|
+
};
|
|
20184
20190
|
var getType = (value) => {
|
|
20185
20191
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
20186
20192
|
};
|
|
@@ -20620,6 +20626,7 @@ export {
|
|
|
20620
20626
|
getType,
|
|
20621
20627
|
getStrLength,
|
|
20622
20628
|
getSliceStr,
|
|
20629
|
+
getSafeCallbackPath,
|
|
20623
20630
|
getRandomString,
|
|
20624
20631
|
getRandomColor,
|
|
20625
20632
|
getPublicUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.37",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"build-web-cjs": "bun build ./src/web.ts --outfile dist/web.cjs.js --format cjs",
|
|
10
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
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
|
-
"build": "rm -rf dist && bun run build-web-esm && bun run build-web-cjs && bun run build-node-esm && bun run build-node-cjs && tsc"
|
|
12
|
+
"build": "rm -rf dist && bun run build-web-esm && bun run build-web-cjs && bun run build-node-esm && bun run build-node-cjs && tsc",
|
|
13
|
+
"typecheck": "tsc --noEmit"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"@types/nodemailer": "^6.4.7",
|
|
72
73
|
"@types/papaparse": "^5.3.15"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "66fc9b56ff49d9a725189dbd3360d6987cb9d604",
|
|
75
76
|
"publishConfig": {
|
|
76
77
|
"access": "public"
|
|
77
78
|
}
|