Skip to content

Commit 57510cf

Browse files
committed
update:md文档兼容移动端
1 parent de6e7a7 commit 57510cf

9 files changed

+62
-2761
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ todo:
3232
2. jsonpath
3333
3. underscore
3434
4. pino-pretty
35+
5. deasync

Diff for: index.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as drpy from './libs/drpyS.js';
33
import path from 'path';
44
import os from "os";
55
import {fileURLToPath} from 'url';
6-
import {readdirSync,readFileSync} from 'fs';
6+
import {readdirSync, readFileSync} from 'fs';
77
import {base64Decode} from "./libs_drpy/crypto-util.js";
8-
import {marked} from './utils/marked.esm.min.js';
8+
import './utils/marked.min.js';
99

1010
const fastify = Fastify({logger: true});
1111

@@ -14,14 +14,13 @@ console.log('__dirname:', __dirname);
1414

1515
// 添加 / 接口
1616
fastify.get('/', async (request, reply) => {
17-
const rootDir = path.resolve('.'); // 当前根目录
1817
let readmePath = null;
1918

2019
// 查找根目录下的 README.md 文件(不区分大小写)
21-
const files = readdirSync(rootDir);
20+
const files = readdirSync(__dirname);
2221
for (const file of files) {
2322
if (/^readme\.md$/i.test(file)) {
24-
readmePath = path.join(rootDir, file);
23+
readmePath = path.join(__dirname, file);
2524
break;
2625
}
2726
}
@@ -36,7 +35,7 @@ fastify.get('/', async (request, reply) => {
3635
const markdownContent = readFileSync(readmePath, 'utf-8');
3736

3837
// 将 Markdown 转换为 HTML
39-
const htmlContent = marked(markdownContent);
38+
const htmlContent = marked.parse(markdownContent);
4039

4140
// 返回 HTML 内容
4241
reply.type('text/html').send(`
@@ -79,7 +78,7 @@ fastify.get('/api/:module', async (request, reply) => {
7978
}
8079
}
8180
// 分类逻辑
82-
const result = await drpy.cate(modulePath, query.t, pg, 1,extend);
81+
const result = await drpy.cate(modulePath, query.t, pg, 1, extend);
8382
return reply.send(result);
8483
}
8584

@@ -125,7 +124,7 @@ fastify.get('/api/:module', async (request, reply) => {
125124
const start = async () => {
126125
try {
127126
// 监听 0.0.0.0
128-
await fastify.listen({ port: 5757, host: '0.0.0.0' });
127+
await fastify.listen({port: 5757, host: '0.0.0.0'});
129128

130129
// 获取本地地址
131130
const localAddress = `http://localhost:5757`;

Diff for: libs_drpy/crypto-util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function window_b64() {
7575
}
7676
}
7777

78-
// export const {atob, btoa} = window_b64();
78+
export const {atob, btoa} = window_b64();
7979

8080
export function base64Encode(text) {
8181
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));

Diff for: libs_drpy/moduleLoader.js

+47-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
1-
import { readFileSync, existsSync } from 'fs';
1+
import {readFileSync, existsSync} from 'fs';
22
import path from "path";
3-
import { fileURLToPath } from "url";
3+
import {fileURLToPath} from "url";
44
import axios from "./axios.min.js"; // 引入 axios
5-
import deasync from "deasync"; // 使用 deasync 实现同步行为
5+
// import deasync from "deasync"; // 使用 deasync 实现同步行为
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url));
88

9+
// 创建一个函数,接受一个回调来模拟同步行为
10+
function fetchModuleCodeSync(jsm_path) {
11+
let result = null;
12+
let error = null;
13+
14+
// 返回一个 Promise,用于等待异步请求完成
15+
return new Promise((resolve, reject) => {
16+
axios.get(jsm_path)
17+
.then((response) => {
18+
result = response.data; // 保存结果
19+
resolve(result); // 成功时 resolve
20+
})
21+
.catch((err) => {
22+
error = new Error(`Error fetching module from URL: ${err.message}`); // 错误信息
23+
reject(error); // 失败时 reject
24+
});
25+
});
26+
}
27+
28+
// 模拟同步的处理方法
29+
function requireModule(jsm_path) {
30+
let result = null;
31+
let error = null;
32+
33+
// 阻塞直到 Promise 完成
34+
try {
35+
result = fetchModuleCodeSync(jsm_path); // 等待异步请求完成
36+
result.then(data => {
37+
console.log("Module Code:", data);
38+
}).catch(err => {
39+
throw err;
40+
});
41+
} catch (err) {
42+
error = err;
43+
console.error(error.message);
44+
}
45+
46+
return result; // 返回模块内容
47+
}
48+
949
globalThis.$ = {
1050
/**
1151
* 加载指定的 JavaScript 模块
@@ -21,6 +61,7 @@ globalThis.$ = {
2161

2262
if (isURL) {
2363
// 从网络同步获取模块代码
64+
/*
2465
let error = null;
2566
let result = null;
2667
@@ -38,6 +79,8 @@ globalThis.$ = {
3879
if (error) throw error;
3980
4081
js_code = result;
82+
*/
83+
js_code = requireModule(jsm_path);
4184
} else {
4285
// 本地路径处理
4386
jsm_path = path.join(__dirname, '../js', jsm_path);
@@ -62,7 +105,7 @@ globalThis.$ = {
62105
console,
63106
$,
64107
exports: {},
65-
module: { exports: {} }
108+
module: {exports: {}}
66109
};
67110

68111
try {

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"license": "MIT",
1212
"dependencies": {
1313
"cheerio": "^1.0.0",
14-
"deasync": "^0.1.30",
1514
"fastify": "^4.15.0",
1615
"lodash": "^4.17.21",
1716
"qs": "^6.13.1",

0 commit comments

Comments
 (0)