@iflyrpa/share 0.0.18 → 0.1.0-beta.1
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/index.js +36 -6
- package/dist/index.mjs +34 -6
- package/dist/types.d.ts +9 -0
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43,11 +43,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
43
43
|
pathExists: ()=>pathExists,
|
|
44
44
|
randomString: ()=>randomString,
|
|
45
45
|
ensureFile: ()=>ensureFile,
|
|
46
|
-
sleep: ()=>sleep,
|
|
47
46
|
fetchJSON: ()=>fetchJSON,
|
|
47
|
+
sleep: ()=>sleep,
|
|
48
48
|
ElectronCookieSchema: ()=>ElectronCookieSchema,
|
|
49
49
|
getFilenameFromUrl: ()=>getFilenameFromUrl,
|
|
50
50
|
success: ()=>success,
|
|
51
|
+
LocalStorageBaseSchema: ()=>LocalStorageBaseSchema,
|
|
51
52
|
TaskState: ()=>types_TaskState,
|
|
52
53
|
ensureFileSync: ()=>ensureFileSync,
|
|
53
54
|
isNil: ()=>isNil,
|
|
@@ -58,6 +59,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
58
59
|
});
|
|
59
60
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
60
61
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
62
|
+
const external_node_http_namespaceObject = require("node:http");
|
|
63
|
+
var external_node_http_default = /*#__PURE__*/ __webpack_require__.n(external_node_http_namespaceObject);
|
|
61
64
|
const external_node_https_namespaceObject = require("node:https");
|
|
62
65
|
var external_node_https_default = /*#__PURE__*/ __webpack_require__.n(external_node_https_namespaceObject);
|
|
63
66
|
const external_node_path_namespaceObject = require("node:path");
|
|
@@ -166,14 +169,36 @@ function ensureFile(filePath) {
|
|
|
166
169
|
}
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
|
-
async function downloadImage(url, savePath) {
|
|
172
|
+
async function downloadImage(url, savePath, retries = 3) {
|
|
173
|
+
const RETRYABLE_CODES = new Set([
|
|
174
|
+
"ECONNRESET",
|
|
175
|
+
"ETIMEDOUT",
|
|
176
|
+
"EAI_AGAIN",
|
|
177
|
+
"ENOTFOUND"
|
|
178
|
+
]);
|
|
179
|
+
try {
|
|
180
|
+
return await downloadImageOnce(url, savePath);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
var _err_extra;
|
|
183
|
+
const errCode = (null == err ? void 0 : err.code) ?? (null == err ? void 0 : null === (_err_extra = err.extra) || void 0 === _err_extra ? void 0 : _err_extra.code);
|
|
184
|
+
if (retries > 0 && (RETRYABLE_CODES.has(errCode) || (null == err ? void 0 : err.code) === 500)) {
|
|
185
|
+
console.warn(`downloadImage 失败,剩余重试次数 ${retries},url: ${url},原因:`, (null == err ? void 0 : err.message) ?? err);
|
|
186
|
+
await new Promise((r)=>setTimeout(r, 1000));
|
|
187
|
+
return downloadImage(url, savePath, retries - 1);
|
|
188
|
+
}
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function downloadImageOnce(url, savePath) {
|
|
170
193
|
await ensureFile(savePath);
|
|
171
194
|
return new Promise((resolve, reject)=>{
|
|
172
195
|
const handleResponse = (response)=>{
|
|
173
196
|
if (301 === response.statusCode || 302 === response.statusCode) {
|
|
174
197
|
const redirectUrl = response.headers.location;
|
|
175
|
-
if (redirectUrl)
|
|
176
|
-
|
|
198
|
+
if (redirectUrl) {
|
|
199
|
+
const redirectFn = redirectUrl.startsWith("http://") ? external_node_http_default().get : external_node_https_default().get;
|
|
200
|
+
redirectFn(redirectUrl, handleResponse).on("error", handleError);
|
|
201
|
+
} else reject({
|
|
177
202
|
code: 414,
|
|
178
203
|
message: `图片下载失败: 跳转地址 Url:${url} 无效`
|
|
179
204
|
});
|
|
@@ -244,12 +269,13 @@ async function downloadImage(url, savePath) {
|
|
|
244
269
|
};
|
|
245
270
|
reject(customMessage);
|
|
246
271
|
};
|
|
247
|
-
const
|
|
272
|
+
const requestFn = url.startsWith("http://") ? external_node_http_default().get : external_node_https_default().get;
|
|
273
|
+
const req = requestFn(url, handleResponse);
|
|
248
274
|
req.setTimeout(10000, ()=>{
|
|
249
275
|
req.destroy();
|
|
250
276
|
reject({
|
|
251
277
|
code: 500,
|
|
252
|
-
message:
|
|
278
|
+
message: `图片下载超时 (${url}),请检查网络连接或稍后重试!`
|
|
253
279
|
});
|
|
254
280
|
});
|
|
255
281
|
req.on("error", handleError);
|
|
@@ -3623,6 +3649,10 @@ const ElectronCookieSchema = CookieBaseSchema.extend({
|
|
|
3623
3649
|
"strict"
|
|
3624
3650
|
]).optional()
|
|
3625
3651
|
});
|
|
3652
|
+
const LocalStorageBaseSchema = schemas_object({
|
|
3653
|
+
key: schemas_string(),
|
|
3654
|
+
value: schemas_string()
|
|
3655
|
+
}).catchall(unknown());
|
|
3626
3656
|
var types_TaskState = /*#__PURE__*/ function(TaskState) {
|
|
3627
3657
|
TaskState["INIT"] = "INIT";
|
|
3628
3658
|
TaskState["ACTION"] = "ACTION";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_http_2dc67212__ from "node:http";
|
|
2
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_https_626f33a7__ from "node:https";
|
|
3
4
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
4
5
|
function pathExists(path) {
|
|
@@ -105,14 +106,36 @@ function ensureFile(filePath) {
|
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
|
-
async function downloadImage(url, savePath) {
|
|
109
|
+
async function downloadImage(url, savePath, retries = 3) {
|
|
110
|
+
const RETRYABLE_CODES = new Set([
|
|
111
|
+
"ECONNRESET",
|
|
112
|
+
"ETIMEDOUT",
|
|
113
|
+
"EAI_AGAIN",
|
|
114
|
+
"ENOTFOUND"
|
|
115
|
+
]);
|
|
116
|
+
try {
|
|
117
|
+
return await downloadImageOnce(url, savePath);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
var _err_extra;
|
|
120
|
+
const errCode = (null == err ? void 0 : err.code) ?? (null == err ? void 0 : null === (_err_extra = err.extra) || void 0 === _err_extra ? void 0 : _err_extra.code);
|
|
121
|
+
if (retries > 0 && (RETRYABLE_CODES.has(errCode) || (null == err ? void 0 : err.code) === 500)) {
|
|
122
|
+
console.warn(`downloadImage 失败,剩余重试次数 ${retries},url: ${url},原因:`, (null == err ? void 0 : err.message) ?? err);
|
|
123
|
+
await new Promise((r)=>setTimeout(r, 1000));
|
|
124
|
+
return downloadImage(url, savePath, retries - 1);
|
|
125
|
+
}
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function downloadImageOnce(url, savePath) {
|
|
109
130
|
await ensureFile(savePath);
|
|
110
131
|
return new Promise((resolve, reject)=>{
|
|
111
132
|
const handleResponse = (response)=>{
|
|
112
133
|
if (301 === response.statusCode || 302 === response.statusCode) {
|
|
113
134
|
const redirectUrl = response.headers.location;
|
|
114
|
-
if (redirectUrl)
|
|
115
|
-
|
|
135
|
+
if (redirectUrl) {
|
|
136
|
+
const redirectFn = redirectUrl.startsWith("http://") ? __WEBPACK_EXTERNAL_MODULE_node_http_2dc67212__["default"].get : __WEBPACK_EXTERNAL_MODULE_node_https_626f33a7__["default"].get;
|
|
137
|
+
redirectFn(redirectUrl, handleResponse).on("error", handleError);
|
|
138
|
+
} else reject({
|
|
116
139
|
code: 414,
|
|
117
140
|
message: `图片下载失败: 跳转地址 Url:${url} 无效`
|
|
118
141
|
});
|
|
@@ -183,12 +206,13 @@ async function downloadImage(url, savePath) {
|
|
|
183
206
|
};
|
|
184
207
|
reject(customMessage);
|
|
185
208
|
};
|
|
186
|
-
const
|
|
209
|
+
const requestFn = url.startsWith("http://") ? __WEBPACK_EXTERNAL_MODULE_node_http_2dc67212__["default"].get : __WEBPACK_EXTERNAL_MODULE_node_https_626f33a7__["default"].get;
|
|
210
|
+
const req = requestFn(url, handleResponse);
|
|
187
211
|
req.setTimeout(10000, ()=>{
|
|
188
212
|
req.destroy();
|
|
189
213
|
reject({
|
|
190
214
|
code: 500,
|
|
191
|
-
message:
|
|
215
|
+
message: `图片下载超时 (${url}),请检查网络连接或稍后重试!`
|
|
192
216
|
});
|
|
193
217
|
});
|
|
194
218
|
req.on("error", handleError);
|
|
@@ -3562,6 +3586,10 @@ const ElectronCookieSchema = CookieBaseSchema.extend({
|
|
|
3562
3586
|
"strict"
|
|
3563
3587
|
]).optional()
|
|
3564
3588
|
});
|
|
3589
|
+
const LocalStorageBaseSchema = schemas_object({
|
|
3590
|
+
key: schemas_string(),
|
|
3591
|
+
value: schemas_string()
|
|
3592
|
+
}).catchall(unknown());
|
|
3565
3593
|
var types_TaskState = /*#__PURE__*/ function(TaskState) {
|
|
3566
3594
|
TaskState["INIT"] = "INIT";
|
|
3567
3595
|
TaskState["ACTION"] = "ACTION";
|
|
@@ -3573,4 +3601,4 @@ var types_TaskState = /*#__PURE__*/ function(TaskState) {
|
|
|
3573
3601
|
TaskState["TIMEOUT"] = "TIMEOUT";
|
|
3574
3602
|
return TaskState;
|
|
3575
3603
|
}({});
|
|
3576
|
-
export { CookieBaseSchema, ElectronCookieSchema, types_TaskState as TaskState, downloadImage, ensureFile, ensureFileSync, fetchJSON, getFilenameFromUrl, isNil, pathExists, randomString, utils_response as response, semver, sleep, success, writeFile };
|
|
3604
|
+
export { CookieBaseSchema, ElectronCookieSchema, LocalStorageBaseSchema, types_TaskState as TaskState, downloadImage, ensureFile, ensureFileSync, fetchJSON, getFilenameFromUrl, isNil, pathExists, randomString, utils_response as response, semver, sleep, success, writeFile };
|
package/dist/types.d.ts
CHANGED
|
@@ -32,9 +32,16 @@ export declare const ElectronCookieSchema: z.ZodObject<{
|
|
|
32
32
|
}, z.core.$catchall<z.ZodUnknown>>;
|
|
33
33
|
export type ElectronCookiesSetDetails = z.infer<typeof ElectronCookieSchema>;
|
|
34
34
|
export type CookieMap = ElectronCookiesSetDetails[];
|
|
35
|
+
export declare const LocalStorageBaseSchema: z.ZodObject<{
|
|
36
|
+
key: z.ZodString;
|
|
37
|
+
value: z.ZodString;
|
|
38
|
+
}, z.core.$catchall<z.ZodUnknown>>;
|
|
39
|
+
export type LocalStorageBase = z.infer<typeof LocalStorageBaseSchema>;
|
|
40
|
+
export type LocalStorageBaseMap = LocalStorageBase[];
|
|
35
41
|
export interface PageParams {
|
|
36
42
|
url: string;
|
|
37
43
|
cookies?: CookieBaseMap;
|
|
44
|
+
localStorage?: LocalStorageBaseMap;
|
|
38
45
|
userAgent?: string;
|
|
39
46
|
viewport?: {
|
|
40
47
|
width: number;
|
|
@@ -99,9 +106,11 @@ export interface PodImagesData {
|
|
|
99
106
|
}
|
|
100
107
|
export interface SteelConnector {
|
|
101
108
|
getProxyUrl(sessionId: string, path: string): string;
|
|
109
|
+
getLive(sessionId: string): Promise<string>;
|
|
102
110
|
}
|
|
103
111
|
export interface AutomateTask {
|
|
104
112
|
debug?: boolean;
|
|
113
|
+
enverionment?: "development" | "production";
|
|
105
114
|
cachePath: string;
|
|
106
115
|
forceUpdate?: boolean;
|
|
107
116
|
logger: LoggerImplement;
|
package/dist/utils.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const semver: {
|
|
|
8
8
|
export declare function fetchJSON<T>(url: string): Promise<T>;
|
|
9
9
|
export declare function isNil(value: unknown): value is null | undefined;
|
|
10
10
|
export declare function ensureFile(filePath: string): Promise<void>;
|
|
11
|
-
export declare function downloadImage(url: string, savePath: string): Promise<string>;
|
|
11
|
+
export declare function downloadImage(url: string, savePath: string, retries?: number): Promise<string>;
|
|
12
12
|
export declare function getFilenameFromUrl(imageUrl: string): string;
|
|
13
13
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
14
14
|
export declare const success: <T>(data: T, message?: string) => ResponseData<T>;
|