@iflyrpa/actions 1.2.0 → 1.2.2
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/bundle.js +60 -9
- package/dist/bundle.js.map +1 -1
- package/dist/index.js +60 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -9
- package/dist/index.mjs.map +1 -1
- package/dist/utils/http.d.ts +3 -3
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__ from "node:buffer";
|
|
|
11
11
|
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
12
12
|
class Http {
|
|
13
13
|
static handleApiError(error) {
|
|
14
|
-
if (error &&
|
|
14
|
+
if (error && "object" == typeof error && "code" in error && "message" in error) return error;
|
|
15
15
|
return {
|
|
16
16
|
code: 500,
|
|
17
17
|
message: "",
|
|
@@ -24,15 +24,25 @@ class Http {
|
|
|
24
24
|
addResponseInterceptor(findError) {
|
|
25
25
|
this.apiClient.interceptors.response.use((response)=>{
|
|
26
26
|
const error = findError(response);
|
|
27
|
-
|
|
27
|
+
if (error) return Promise.reject(Object.assign(error, {
|
|
28
|
+
extra: {
|
|
29
|
+
method: response.config.method,
|
|
30
|
+
url: response.config.url
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
return response;
|
|
28
34
|
}, (error)=>{
|
|
29
35
|
const errorResponse = {
|
|
30
36
|
code: error.response?.status || 500,
|
|
31
37
|
message: error.message || "",
|
|
32
|
-
data: error.response?.data
|
|
38
|
+
data: error.response?.data,
|
|
39
|
+
extra: {
|
|
40
|
+
method: error.config?.method,
|
|
41
|
+
url: error.config?.url
|
|
42
|
+
}
|
|
33
43
|
};
|
|
34
44
|
if (error.response?.data) {
|
|
35
|
-
if (
|
|
45
|
+
if ("object" == typeof error.response.data) {
|
|
36
46
|
const serverError = error.response.data;
|
|
37
47
|
if (serverError.message) errorResponse.message = serverError.message;
|
|
38
48
|
errorResponse.data = serverError;
|
|
@@ -141,7 +151,7 @@ const executeAction = (...actions)=>async (task, params)=>{
|
|
|
141
151
|
result = Http.handleApiError(error);
|
|
142
152
|
}
|
|
143
153
|
if (0 === result.code || 200 === result.code) break;
|
|
144
|
-
if (index !== actions.length - 1) task.logger.error(result.message, stringifyError(result.data));
|
|
154
|
+
if (index !== actions.length - 1) task.logger.error(result.message, stringifyError(result.data), result.extra);
|
|
145
155
|
}
|
|
146
156
|
return result;
|
|
147
157
|
};
|
|
@@ -592,7 +602,7 @@ const searchToutiaoTopicList = async (_task, params)=>{
|
|
|
592
602
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)([]);
|
|
593
603
|
}
|
|
594
604
|
};
|
|
595
|
-
const searchXiaohongshuLocation = async (
|
|
605
|
+
const searchXiaohongshuLocation = async (_task, params)=>{
|
|
596
606
|
const http = new Http({
|
|
597
607
|
headers: {
|
|
598
608
|
cookie: params.cookies.map((it)=>`${it.name}=${it.value}`).join(";"),
|
|
@@ -616,7 +626,6 @@ const searchXiaohongshuLocation = async (task, params)=>{
|
|
|
616
626
|
});
|
|
617
627
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(0 === result.code ? result.data.poi_list : []);
|
|
618
628
|
} catch (error) {
|
|
619
|
-
task.logger.error("获取小红书地址失败");
|
|
620
629
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)([]);
|
|
621
630
|
}
|
|
622
631
|
};
|
|
@@ -2168,6 +2177,7 @@ const xiaohongshuPublish_mock_mockAction = async (task, params)=>{
|
|
|
2168
2177
|
});
|
|
2169
2178
|
return (0, __WEBPACK_EXTERNAL_MODULE__iflyrpa_share_f7afdc8c__.success)(publishResult.data.id);
|
|
2170
2179
|
};
|
|
2180
|
+
const rpa_xsEncrypt = new XsEncrypt();
|
|
2171
2181
|
const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
|
|
2172
2182
|
const commonCookies = {
|
|
2173
2183
|
path: "/",
|
|
@@ -2186,6 +2196,47 @@ const xiaohongshuPublish_rpa_rpaAction = async (task, params)=>{
|
|
|
2186
2196
|
})) || []
|
|
2187
2197
|
});
|
|
2188
2198
|
const tmpCachePath = task.getTmpPath();
|
|
2199
|
+
const interceptUrls = [
|
|
2200
|
+
'/api/media/v1/upload/creator/permit',
|
|
2201
|
+
'/api/galaxy/v2/creator/activity_center/list',
|
|
2202
|
+
'/web_api/sns/v5/creator/topic/template/list',
|
|
2203
|
+
'/web_api/sns/v5/creator/file/encryption',
|
|
2204
|
+
'/web_api/sns/v2/note'
|
|
2205
|
+
];
|
|
2206
|
+
await page.route('**', async (route, request)=>{
|
|
2207
|
+
const url = request.url();
|
|
2208
|
+
if (interceptUrls.some((pattern)=>url.includes(pattern))) {
|
|
2209
|
+
const urlObj = new URL(url);
|
|
2210
|
+
const fetchCoverUrl = urlObj.pathname + urlObj.search;
|
|
2211
|
+
const xt = Date.now().toString();
|
|
2212
|
+
const a1Cookie = params.cookies.find((it)=>"a1" === it.name)?.value;
|
|
2213
|
+
if (!a1Cookie) {
|
|
2214
|
+
await route.fulfill({
|
|
2215
|
+
status: 200,
|
|
2216
|
+
contentType: 'application/json',
|
|
2217
|
+
body: JSON.stringify({
|
|
2218
|
+
code: 200,
|
|
2219
|
+
message: "账号数据异常,请重新绑定账号后重试。",
|
|
2220
|
+
data: ""
|
|
2221
|
+
})
|
|
2222
|
+
});
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
const isNoteRequest = urlObj.pathname.includes(interceptUrls[4]);
|
|
2226
|
+
const xs = await (isNoteRequest ? (async ()=>{
|
|
2227
|
+
const publishData = JSON.parse(request.postData() || "");
|
|
2228
|
+
const publishDataStr = rpa_xsEncrypt.dumps(publishData);
|
|
2229
|
+
return rpa_xsEncrypt.encryptXs(interceptUrls[4] + publishDataStr, a1Cookie, xt);
|
|
2230
|
+
})() : rpa_xsEncrypt.encryptXs(fetchCoverUrl, a1Cookie, xt));
|
|
2231
|
+
const newHeaders = {
|
|
2232
|
+
...request.headers(),
|
|
2233
|
+
'x-s': xs
|
|
2234
|
+
};
|
|
2235
|
+
await route.continue({
|
|
2236
|
+
headers: newHeaders
|
|
2237
|
+
});
|
|
2238
|
+
} else await route.continue();
|
|
2239
|
+
});
|
|
2189
2240
|
const selectAddress = async (selector, address)=>{
|
|
2190
2241
|
const instance = "string" == typeof selector ? page.locator(selector) : selector;
|
|
2191
2242
|
await instance.click();
|
|
@@ -2333,7 +2384,7 @@ const xiaohongshuPublish = async (task, params)=>{
|
|
|
2333
2384
|
return executeAction(xiaohongshuPublish_mock_mockAction, xiaohongshuPublish_rpa_rpaAction)(task, params);
|
|
2334
2385
|
};
|
|
2335
2386
|
var package_namespaceObject = {
|
|
2336
|
-
i8: "1.1
|
|
2387
|
+
i8: "1.2.1"
|
|
2337
2388
|
};
|
|
2338
2389
|
class Action {
|
|
2339
2390
|
constructor(task){
|
|
@@ -2349,7 +2400,7 @@ class Action {
|
|
|
2349
2400
|
}
|
|
2350
2401
|
if (200 === responseData.code) this.task.logger.info(`${func.name} action params error`, responseData);
|
|
2351
2402
|
else if (0 !== responseData.code) {
|
|
2352
|
-
this.task.logger.error(responseData.message || `${func.name} 执行失败`, stringifyError(responseData.data));
|
|
2403
|
+
this.task.logger.error(responseData.message || `${func.name} 执行失败`, stringifyError(responseData.data), responseData.extra);
|
|
2353
2404
|
this.task.logger.info(`${func.name} action failed`);
|
|
2354
2405
|
} else this.task.logger.info(`${func.name} action success`);
|
|
2355
2406
|
return responseData;
|