Skip to content

Commit d321f3e

Browse files
author
Taois
committed
feat: 修改core
1 parent 5d17c78 commit d321f3e

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

drpy-node-bundle/localDsCore.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function getEngine(moduleName, query, inject_env) {
8888
hostname = "127.0.0.1:9978",
8989
hostUrl = "127.0.0.1",
9090
proxyUrl = `http://127.0.0.1:9978/proxy?do=node&siteKey=${moduleName}`,
91-
httpUrl, imageApi, mediaProxyUrl, webdavProxyUrl, ftpProxyUrl,
91+
proxyPath, httpUrl, imageApi, mediaProxyUrl, webdavProxyUrl, ftpProxyUrl,
9292
wsName, fServer,
9393
} = inject_env;
9494
const getProxyUrl = function () {
@@ -109,6 +109,7 @@ async function getEngine(moduleName, query, inject_env) {
109109
requestHost,
110110
hostname,
111111
proxyUrl,
112+
proxyPath, // 代理路径
112113
getProxyUrl,
113114
ext: moduleExt,
114115
moduleName: moduleName,
@@ -242,6 +243,73 @@ async function getEngine(moduleName, query, inject_env) {
242243
return result;
243244
}
244245

246+
// 处理解析逻辑
247+
if ('parse' in query) {
248+
let t1 = (new Date()).getTime(); // 记录开始时间
249+
// 构建解析器文件路径
250+
const jxName = query.parse;
251+
const jxPath = path.join(options.jxDir, `${jxName}.js`);
252+
253+
const backResp = await drpyS.jx(jxPath, env, query);
254+
255+
const statusCode = 200;
256+
const mediaType = 'application/json; charset=utf-8';
257+
258+
// 处理对象类型的响应
259+
if (typeof backResp === 'object') {
260+
// 设置默认的状态码
261+
if (!backResp.code) {
262+
let statusCode = backResp.url && backResp.url !== query.url ? 200 : 404;
263+
backResp.code = statusCode
264+
}
265+
266+
// 设置默认的消息
267+
if (!backResp.msg) {
268+
let msgState = backResp.url && backResp.url !== query.url ? '成功' : '失败';
269+
backResp.msg = `${jxName}解析${msgState}`;
270+
}
271+
272+
// 计算耗时
273+
let t2 = (new Date()).getTime();
274+
backResp.cost = t2 - t1;
275+
276+
let backRespSend = backResp;
277+
console.log(backRespSend);
278+
return backRespSend;
279+
}
280+
// 处理字符串类型的响应
281+
else if (typeof backResp === 'string') {
282+
// 构建标准响应格式
283+
let statusCode = backResp && backResp !== query.url ? 200 : 404;
284+
let msgState = backResp && backResp !== query.url ? '成功' : '失败';
285+
let t2 = (new Date()).getTime();
286+
287+
let result = {
288+
code: statusCode,
289+
url: backResp,
290+
msg: `${jxName}解析${msgState}`,
291+
cost: t2 - t1
292+
}
293+
294+
let backRespSend = result;
295+
console.log(backRespSend);
296+
return backRespSend;
297+
} else {
298+
// 其他类型的响应,返回失败
299+
let t2 = (new Date()).getTime();
300+
301+
let result = {
302+
code: 404,
303+
url: "",
304+
msg: `${jxName}解析失败`,
305+
cost: t2 - t1
306+
}
307+
let backRespSend = result;
308+
console.log(backRespSend);
309+
return backRespSend;
310+
}
311+
}
312+
245313
// 处理强制刷新初始化逻辑
246314
if ('refresh' in query) {
247315
const refreshedObject = await apiEngine.init(modulePath, env, true);

0 commit comments

Comments
 (0)