oipage 0.2.0 → 0.3.0
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/CHANGELOG +14 -1
- package/nodejs/core/file.js +40 -5
- package/nodejs/core/server.js +15 -1
- package/nodejs/index.js +2 -2
- package/package.json +1 -1
package/CHANGELOG
CHANGED
|
@@ -40,4 +40,17 @@ v0.2.0:
|
|
|
40
40
|
(包括:input输入框、select列表选择)
|
|
41
41
|
* server hander方法补充api
|
|
42
42
|
(包括:getFileInfo()、filePath)
|
|
43
|
-
|
|
43
|
+
v0.3.0:
|
|
44
|
+
date:2025-01-23
|
|
45
|
+
changes:
|
|
46
|
+
- 修复bug
|
|
47
|
+
1、nodejs
|
|
48
|
+
* 修复目标位置可能不存在导致的报错
|
|
49
|
+
(包括:copySync、moveSync)
|
|
50
|
+
- 优化改造
|
|
51
|
+
1、nodejs
|
|
52
|
+
* 优化服务器启动日志,添加访问地址提示
|
|
53
|
+
- 新增功能
|
|
54
|
+
1、nodejs
|
|
55
|
+
* “file 文件相关操作”新增若干方法
|
|
56
|
+
(包括:listFolderSync)
|
package/nodejs/core/file.js
CHANGED
|
@@ -34,6 +34,8 @@ function copySync(source, target) {
|
|
|
34
34
|
|
|
35
35
|
// 如果是文件,直接复制即可
|
|
36
36
|
if (!fs.lstatSync(source).isDirectory()) {
|
|
37
|
+
if (!fs.existsSync(path.join(target, "../"))) fs.mkdirSync(path.join(target, "../"), { recursive: true });
|
|
38
|
+
|
|
37
39
|
fs.copyFileSync(source, target);
|
|
38
40
|
} else {
|
|
39
41
|
|
|
@@ -58,6 +60,8 @@ function moveSync(source, target) {
|
|
|
58
60
|
|
|
59
61
|
// 如果是文件,直接剪切即可
|
|
60
62
|
if (!fs.lstatSync(source).isDirectory()) {
|
|
63
|
+
if (!fs.existsSync(path.join(target, "../"))) fs.mkdirSync(path.join(target, "../"), { recursive: true });
|
|
64
|
+
|
|
61
65
|
fs.copyFileSync(source, target);
|
|
62
66
|
fs.unlinkSync(source);
|
|
63
67
|
} else {
|
|
@@ -80,15 +84,15 @@ function moveSync(source, target) {
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
//
|
|
87
|
+
// 遍历文件或文件夹中所有文件
|
|
84
88
|
function listFileSync(source, callback) {
|
|
85
89
|
// 文件夹
|
|
86
90
|
if (fs.lstatSync(source).isDirectory()) {
|
|
87
91
|
|
|
88
|
-
//
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
listFileSync(path.join(source, "./" +
|
|
92
|
+
// 读取子内容
|
|
93
|
+
const subItems = fs.readdirSync(source);
|
|
94
|
+
subItems.forEach(function (item) {
|
|
95
|
+
listFileSync(path.join(source, "./" + item), callback);
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
98
|
|
|
@@ -104,6 +108,36 @@ function listFileSync(source, callback) {
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
|
|
111
|
+
// 遍历文件夹中所有文件夹
|
|
112
|
+
function listFolderSync(source, callback) {
|
|
113
|
+
if (fs.lstatSync(source).isDirectory()) {
|
|
114
|
+
(function doIt(source) {
|
|
115
|
+
|
|
116
|
+
// 读取子内容
|
|
117
|
+
const subItems = fs.readdirSync(source);
|
|
118
|
+
subItems.forEach(function (item) {
|
|
119
|
+
let itemPath = path.join(source, "./" + item);
|
|
120
|
+
|
|
121
|
+
// 如果是文件夹
|
|
122
|
+
if (fs.lstatSync(itemPath).isDirectory()) {
|
|
123
|
+
|
|
124
|
+
let notDeep = callback({
|
|
125
|
+
"name": item,
|
|
126
|
+
"path": itemPath
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// 深入
|
|
130
|
+
if (!notDeep) {
|
|
131
|
+
doIt(itemPath);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
})(source);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
107
141
|
// 获取文件或文件夹的全路径
|
|
108
142
|
function fullPathSync(pathString, contextPath) {
|
|
109
143
|
if (/^\//.test(pathString) || /^[A-Za-z]:\\/.test(pathString)) {
|
|
@@ -125,4 +159,5 @@ exports.deleteSync = deleteSync;
|
|
|
125
159
|
exports.copySync = copySync;
|
|
126
160
|
exports.moveSync = moveSync;
|
|
127
161
|
exports.listFileSync = listFileSync;
|
|
162
|
+
exports.listFolderSync = listFolderSync;
|
|
128
163
|
exports.fullPathSync = fullPathSync;
|
package/nodejs/core/server.js
CHANGED
|
@@ -5,6 +5,7 @@ const mineTypes = require('../data/mime.types.js');
|
|
|
5
5
|
const { log, warn, error } = require('./log.js');
|
|
6
6
|
const responseFileList = require('./responseFileList.js');
|
|
7
7
|
const path = require('path');
|
|
8
|
+
const network = require('./network.js');
|
|
8
9
|
|
|
9
10
|
const jsonfile = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json')));
|
|
10
11
|
|
|
@@ -172,5 +173,18 @@ module.exports = function (config = {}) {
|
|
|
172
173
|
});
|
|
173
174
|
|
|
174
175
|
Server.listen(port);
|
|
175
|
-
|
|
176
|
+
|
|
177
|
+
// 打印启动成功信息
|
|
178
|
+
|
|
179
|
+
log('\n<i> [OIPage-server] Project is running at:');
|
|
180
|
+
log('<i> [OIPage-server] Loopback: http://localhost:' + port + '/');
|
|
181
|
+
|
|
182
|
+
let networkInfo = network();
|
|
183
|
+
|
|
184
|
+
// 打印IPv4地址
|
|
185
|
+
for (let ipv4 of networkInfo.IPv4) {
|
|
186
|
+
log('<i> [OIPage-server] On Your Network (IPv4): http://' + ipv4.address + ':' + port + '/');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
log('\nOIPage Server compiled successfully\n');
|
|
176
190
|
};
|
package/nodejs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { deleteSync, copySync, moveSync, listFileSync, fullPathSync } = require('./core/file');
|
|
1
|
+
const { deleteSync, copySync, moveSync, listFileSync, listFolderSync, fullPathSync } = require('./core/file');
|
|
2
2
|
const { log, warn, error, linelog, deeplog } = require('./core/log');
|
|
3
3
|
const options = require('./core/options');
|
|
4
4
|
const { get, post } = require('./core/remote');
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
options,
|
|
21
21
|
|
|
22
22
|
// 文件操作相关
|
|
23
|
-
deleteSync, copySync, moveSync, listFileSync, fullPathSync,
|
|
23
|
+
deleteSync, copySync, moveSync, listFileSync, listFolderSync, fullPathSync,
|
|
24
24
|
|
|
25
25
|
// 图片相关
|
|
26
26
|
toBase64,
|