@yoooloo42/beat 1.0.29 → 1.0.31

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.
@@ -1,455 +0,0 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import Richtext from './richtext.js'
4
- const thisTime = new Date()
5
-
6
- // 图片新增
7
- function imageAppend (para) {
8
- // para.pathHead 路径头部
9
- // para.pathHead.dbFolder 数据库文件夹
10
- // para.pathHead.dbUrl 数据库URL
11
- // para.pathHead.uploadFolder 上传文件夹
12
- // para.pathHead.uploadUrl 上传URL
13
- // para.uploaded 已上传文件的URL
14
-
15
- // para.dataunitId 数据单元ID
16
- // para.tblName 表名
17
- // para.fieldName 字段名
18
- // para.fieldIndex 多文件索引
19
- // para.dataId 数据ID
20
-
21
- return new Promise(function (resolve, reject) {
22
- if (!para.uploaded) {
23
- return resolve('')
24
- }
25
-
26
- // 数据库文件夹:数据单元ID + 表名 + 字段名 + 多文件索引 + 当年 + 当月
27
- const dbFolder = para.pathHead.dbFolder +
28
- (para.dataunitId ? '/' + para.dataunitId : '') +
29
- '/' + para.tblName +
30
- '/' + para.fieldName +
31
- '[' + ('fieldIndex' in para ? para.fieldIndex : 0) + "]" +
32
- '/' + thisTime.getFullYear() +
33
- '/' + (thisTime.getMonth() + 1)
34
- // 数据库文件名:数据单元ID + 表名 + 字段名 + 多文件索引 + 数据ID + 随机数 + 扩展名
35
- const dbFileName = (para.dataunitId ? para.dataunitId + '.' : '') +
36
- para.tblName + '.' +
37
- para.fieldName + '.' +
38
- ('fieldIndex' in para ? para.fieldIndex : 0) + '.' +
39
- para.dataId + '.' +
40
- Math.floor((999999 - 0) * Math.random() + 0) +
41
- path.parse(para.uploaded).ext
42
-
43
- // 上传文件路径
44
- const uploadFilePath = para.uploaded.replace(para.pathHead.uploadUrl, para.pathHead.uploadFolder)
45
- // 数据库文件路径
46
- const dbFilePath = dbFolder + '/' + dbFileName
47
- // 数据库URL
48
- const dbUrl = dbFilePath.replace(para.pathHead.dbFolder, para.pathHead.dbUrl)
49
- new Promise(function (resolve, reject) {
50
- // 创建数据库文件夹
51
- fs.mkdir(dbFolder, {recursive: true}, err => {
52
- if (err) throw err
53
- resolve()
54
- })
55
- }).then(function () {
56
- new Promise(function (resolve, reject) {
57
- // 已上传文件转存至数据库文件夹
58
- fs.rename(uploadFilePath, dbFilePath, err => {
59
- if (err) throw err
60
- resolve(dbUrl) // 返回数据库URL
61
- })
62
- }).then(function (result) {
63
- resolve(result)
64
- })
65
- })
66
- })
67
- }
68
-
69
- // 图片删除
70
- function imageDelete (para) {
71
- // para.pathHead 路径头部
72
- // para.pathHead.dbFolder 数据库文件夹
73
- // para.pathHead.dbUrl 数据库URL
74
- // para.url 待删除文件的URL
75
-
76
- return new Promise(function (resolve, reject) {
77
- if (!para.url) {
78
- return resolve()
79
- }
80
- fs.unlink(para.url.replace(para.pathHead.dbUrl, para.pathHead.dbFolder), err => {
81
- if (err) throw err
82
- resolve()
83
- })
84
- })
85
- }
86
-
87
- // 图片更新
88
- function imageUpdate (para) {
89
- // para.pathHead 路径头部
90
- // para.pathHead.dbFolder 数据库文件夹
91
- // para.pathHead.dbUrl 数据库URL
92
- // para.pathHead.uploadFolder 上传文件夹
93
- // para.pathHead.uploadUrl 上传URL
94
- // para.uploaded 已上传文件的URL
95
- // para.old 原文件的URL
96
- // para.delete 如果没有上传新文件,是否删除原文件
97
-
98
- // para.dataunitId 数据单元ID
99
- // para.tblName 表名
100
- // para.fieldName 字段名
101
- // para.fieldIndex 多文件索引
102
- // para.dataId 数据ID
103
-
104
- return new Promise(function (resolve, reject) {
105
- if (!!para.uploaded || para.delete === true || para.delete === 'true') {
106
- imageDelete({
107
- pathHead: {
108
- dbFolder: para.pathHead.dbFolder,
109
- dbUrl: para.pathHead.dbUrl
110
- },
111
- url: para.old
112
- })
113
- }
114
- if (!para.uploaded) {
115
- return resolve(para.old)
116
- }
117
-
118
- imageAppend({
119
- pathHead: {
120
- dbFolder: para.pathHead.dbFolder,
121
- dbUrl: para.pathHead.dbUrl,
122
- uploadFolder: para.pathHead.uploadFolder,
123
- uploadUrl: para.pathHead.uploadUrl
124
- },
125
- uploaded: para.uploaded,
126
-
127
- dataunitId: para.dataunitId,
128
- tblName: para.tblName,
129
- fieldName: para.fieldName,
130
- fieldIndex: 'fieldIndex' in para ? para.fieldIndex : 0,
131
- dataId: para.dataId
132
- }).then(result=>{
133
- resolve(result)
134
- })
135
- })
136
- }
137
-
138
- // 图片新增 - 多文件处理
139
- function imagesAppend (para) {
140
- // para.pathHead 路径头部
141
- // para.pathHead.dbFolder 数据库文件夹
142
- // para.pathHead.dbUrl 数据库URL
143
- // para.pathHead.uploadFolder 上传文件夹
144
- // para.pathHead.uploadUrl 上传URL
145
- // para.arrUploaded 已上传文件的URL
146
-
147
- // para.dataunitId 数据单元ID
148
- // para.tblName 表名
149
- // para.fieldName 字段名
150
- // para.dataId 数据ID
151
-
152
- return new Promise(function (resolve, reject) {
153
- if(!para.arrUploaded || para.arrUploaded.length === 0){
154
- return resolve([])
155
- }
156
- let arrPrm = []
157
- para.arrUploaded.forEach((item, index)=>{
158
- arrPrm.push(imageAppend ({
159
- pathHead: para.pathHead,
160
- uploaded: item,
161
-
162
- dataunitId: para.dataunitId,
163
- tblName: para.tblName,
164
- fieldName: para.fieldName,
165
- fieldIndex: index,
166
- dataId: para.dataId
167
- }))
168
- })
169
- Promise.all(arrPrm).then(result=>{
170
- resolve(result)
171
- })
172
- })
173
- }
174
-
175
- // 图片删除 - 多文件处理
176
- function imagesDelete(para){
177
- // para.pathHead 路径头部
178
- // para.pathHead.dbFolder 数据库文件夹
179
- // para.pathHead.dbUrl 数据库URL
180
- // para.arrUrl 待删除文件的URL
181
-
182
- return new Promise(function (resolve, reject) {
183
- if(!para.arrUrl || para.arrUrl.length === 0){
184
- return resolve()
185
- }
186
-
187
- let arrPrm = []
188
- para.arrUrl.forEach(i=>{
189
- arrPrm.push(imageDelete({
190
- pathHead: para.pathHead,
191
- url: i
192
- }))
193
- })
194
- Promise.all((arrPrm)).then(()=>{
195
- resolve()
196
- })
197
- })
198
- }
199
-
200
- // 图片更新 - 多文件处理
201
- function imagesUpdate (para) {
202
- // para.pathHead 路径头部
203
- // para.pathHead.dbFolder 数据库文件夹
204
- // para.pathHead.dbUrl 数据库URL
205
- // para.pathHead.uploadFolder 上传文件夹
206
- // para.pathHead.uploadUrl 上传URL
207
- // para.arrUploaded 已上传文件的URL
208
- // para.arrOld 原文件的URL
209
- // para.arrDelete 待删除文件的URL
210
-
211
- // para.dataunitId 数据单元ID
212
- // para.tblName 表名
213
- // para.fieldName 字段名
214
- // para.dataId 数据ID
215
-
216
- return new Promise(function (resolve, reject) {
217
- imagesDelete({
218
- pathHead: {
219
- dbFolder: para.pathHead.dbFolder,
220
- dbUrl: para.pathHead.dbUrl
221
- },
222
- arrUrl: para.arrDelete
223
- }).then(()=>{
224
- imagesAppend ({
225
- pathHead: para.pathHead,
226
- arrUploaded: para.arrUploaded,
227
-
228
- dataunitId: para.dataunitId,
229
- tblName: para.tblName,
230
- fieldName: para.fieldName,
231
- dataId: para.dataId
232
- }).then(result=>{
233
- // 原文件中未删除的并入返回结果
234
- let arrHoldon = []
235
- para.arrOld.forEach(i=>{
236
- let holdon = true
237
- para.arrDelete.forEach(j=>{
238
- if(i === j){
239
- holdon = false
240
- }
241
- })
242
- if(holdon){
243
- arrHoldon.push(i)
244
- }
245
- })
246
- resolve(arrHoldon.concat(result))
247
- })
248
- })
249
- })
250
- }
251
-
252
- // 富文本新增
253
- function richtextAppend (para) {
254
- // para.pathHead 路径头部
255
- // para.pathHead.dbFolder 数据库文件夹
256
- // para.pathHead.dbUrl 数据库URL
257
- // para.pathHead.uploadFolder 上传文件夹
258
- // para.pathHead.uploadUrl 上传URL
259
- // para.richtext 富文本
260
-
261
- // para.dataunitId 数据单元ID
262
- // para.tblName 表名
263
- // para.fieldName 字段名
264
- // para.dataId 数据ID
265
-
266
- return new Promise(function (resolve, reject) {
267
- let richtextReturn = para.richtext,
268
- arrSrc = Richtext.extractAllSrc(para.richtext);
269
-
270
- let dbFolder = para.pathHead.dbFolder +
271
- (para.dataunitId ? '/' + para.dataunitId : '') +
272
- '/' + para.tblName +
273
- '/' + para.fieldName +
274
- '/' + thisTime.getFullYear() +
275
- '/' + (thisTime.getMonth() + 1);
276
-
277
- new Promise(function (resolve, reject) {
278
- // 创建数据库文件夹
279
- fs.mkdir(dbFolder, {recursive: true}, err => {
280
- if (err) throw err
281
- resolve()
282
- })
283
- }).then(function () {
284
- let arrPrm = []
285
- for (let i in arrSrc) {
286
- let uploadFilePath = arrSrc[i].replace(para.pathHead.uploadUrl, para.pathHead.uploadFolder),
287
- dbFilePath = dbFolder + '/' +
288
- (para.dataunitId ? para.dataunitId + '.' : '') +
289
- para.tblName + '.' +
290
- para.fieldName + '.' +
291
- para.dataId + '.' +
292
- Math.floor((999999 - 0) * Math.random() + 0) +
293
- path.parse(arrSrc [i]).ext,
294
- dbUrl = dbFilePath.replace(para.pathHead.dbFolder, para.pathHead.dbUrl)
295
-
296
- arrPrm.push(new Promise(function (resolve, reject) {
297
- // 已上传文件转存至数据库文件夹
298
- fs.rename(uploadFilePath, dbFilePath, err => {
299
- if (err) throw err
300
-
301
- // 重置富文本内的src
302
- richtextReturn = richtextReturn.replace(arrSrc[i], dbUrl)
303
- resolve()
304
- })
305
- }))
306
- }
307
-
308
- Promise.all(arrPrm).then(function () {
309
- resolve(richtextReturn)
310
- })
311
- })
312
- })
313
- }
314
-
315
- // 富文本删除
316
- function richtextDelete (para) {
317
- // para.pathHead 路径头部
318
- // para.pathHead.dbFolder 数据库文件夹
319
- // para.pathHead.dbUrl 数据库URL
320
- // para.richtext 富文本
321
-
322
- return new Promise(function (resolve, reject) {
323
- let arrSrc = Richtext.extractAllSrc(para.richtext),
324
- arrPrm = []
325
- for (let i in arrSrc) {
326
- arrPrm[i] = new Promise(function (resolve, reject) {
327
- fs.unlink(arrSrc[i].replace(para.pathHead.dbUrl, para.pathHead.dbFolder), err => {
328
- if (err) throw err
329
- resolve()
330
- })
331
- })
332
- }
333
-
334
- Promise.all(arrPrm).then(function () {
335
- resolve({code: 0, message: '删除成功'})
336
- })
337
- })
338
- }
339
-
340
- // 富文本更新
341
- function richtextUpdate (para) {
342
- // para.pathHead 路径头部
343
- // para.pathHead.dbFolder 数据库文件夹
344
- // para.pathHead.dbUrl 数据库URL
345
- // para.pathHead.uploadFolder 上传文件夹
346
- // para.pathHead.uploadUrl 上传URL
347
- // para.richtextNew 新富文本
348
- // para.richtextOld 原富文本
349
-
350
- // para.dataunitId 数据单元ID
351
- // para.tblName 表名
352
- // para.fieldName 字段名
353
- // para.dataId 数据ID
354
-
355
- return new Promise(function (resolve, reject) {
356
- let richtextReturn = para.richtextNew,
357
- arrSrcNew = Richtext.extractAllSrc(para.richtextNew),
358
- arrSrcOld = Richtext.extractAllSrc(para.richtextOld)
359
-
360
- let dbFolder = para.pathHead.dbFolder +
361
- (para.dataunitId ? '/' + para.dataunitId : '') +
362
- '/' + para.tblName +
363
- '/' + para.fieldName +
364
- '/' + thisTime.getFullYear() +
365
- '/' + (thisTime.getMonth() + 1)
366
-
367
- new Promise(function (resolve, reject) {
368
- // 创建数据库文件夹
369
- fs.mkdir(dbFolder, {recursive: true}, err => {
370
- if (err) console.log(err)
371
- resolve()
372
- })
373
- }).then(function () {
374
- new Promise(function (resolve, reject) {
375
- let arrPrm = []
376
- for (let i in arrSrcNew) {
377
- // 处理富文本 richtextNew 内的新增src
378
- if (arrSrcNew [i].startsWith(para.pathHead.uploadUrl)) {
379
- let uploadFilePath = arrSrcNew[i].replace(para.pathHead.uploadUrl, para.pathHead.uploadFolder),
380
- dbFilePath = dbFolder + '/' +
381
- (para.dataunitId ? para.dataunitId + '.' : '') +
382
- para.tblName + '.' +
383
- para.fieldName + '.' +
384
- para.dataId + '.' +
385
- Math.floor((999999 - 0) * Math.random() + 0) +
386
- path.parse(arrSrcNew [i]).ext,
387
- dbUrl = dbFilePath.replace(para.pathHead.dbFolder, para.pathHead.dbUrl)
388
-
389
- arrPrm.push(new Promise(function (resolve, reject) {
390
- // 已上传文件转存至数据库文件夹
391
- fs.rename(uploadFilePath, dbFilePath, err => {
392
- if (err) throw err
393
-
394
- // 重置富文本内新增的src
395
- richtextReturn = richtextReturn.replace(arrSrcNew [i], dbUrl)
396
- resolve()
397
- })
398
- }))
399
- } else {
400
- // 新src与原src重复处理:不能删除
401
- for (let j in arrSrcOld) {
402
- if (arrSrcOld [j] === arrSrcNew [i]) {
403
- arrSrcOld [j] = ''
404
- }
405
- }
406
- }
407
- }
408
-
409
- Promise.all(arrPrm).then(function () {
410
- resolve()
411
- })
412
- }).then(function () {
413
- let arrPrm = []
414
- for (let i in arrSrcOld) {
415
- if (arrSrcOld [i]) {
416
- arrPrm.push(new Promise(function (resolve, reject) {
417
- // 删除垃圾文件
418
- fs.unlink(arrSrcOld [i].replace(para.pathHead.dbUrl, para.pathHead.dbFolder), err => {
419
- if (err) throw err
420
- resolve()
421
- })
422
- }))
423
- }
424
- }
425
-
426
- Promise.all(arrPrm).then(function () {
427
- resolve(richtextReturn)
428
- })
429
- })
430
- })
431
- })
432
- }
433
-
434
- export {
435
- imageAppend,
436
- imageDelete,
437
- imageUpdate,
438
- imagesAppend,
439
- imagesDelete,
440
- imagesUpdate,
441
- richtextAppend,
442
- richtextDelete,
443
- richtextUpdate
444
- }
445
- export default {
446
- imageAppend,
447
- imageDelete,
448
- imageUpdate,
449
- imagesAppend,
450
- imagesDelete,
451
- imagesUpdate,
452
- richtextAppend,
453
- richtextDelete,
454
- richtextUpdate
455
- }
@@ -1,125 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import https from 'https';
4
- import http from 'http'; // 也可能需要处理 http 链接
5
-
6
- /**
7
- * 从本地文件路径获取文件的 Base64 编码。
8
- * @param {string} filePath - 本地文件的绝对或相对路径。
9
- * @returns {Promise<string>} - 文件的 Base64 编码字符串。
10
- */
11
- function getBase64FromLocalFile(filePath) {
12
- return new Promise((resolve, reject) => {
13
- // 确保路径是绝对路径
14
- const absolutePath = path.resolve(filePath);
15
-
16
- // 使用 { encoding: 'base64' } 直接读取为 Base64 字符串
17
- fs.readFile(absolutePath, { encoding: 'base64' }, (err, data) => {
18
- if (err) {
19
- console.error(`[本地文件错误] 读取本地文件失败: ${err.message}`);
20
- return reject(err);
21
- }
22
- resolve(data);
23
- });
24
- });
25
- }
26
-
27
- /**
28
- * 从远程文件 URL 获取文件的 Base64 编码,支持自动重定向跟随 (3xx 状态码)。
29
- * @param {string} fileUrl - 远程文件的完整 URL。
30
- * @param {number} [redirects=5] - 最大重定向次数限制。
31
- * @returns {Promise<string>} - 文件的 Base64 编码字符串。
32
- */
33
- function getBase64FromURL(fileUrl, redirects = 5) {
34
- if (redirects === 0) {
35
- return Promise.reject(new Error(`[远程文件错误] 重定向次数过多 (${fileUrl})`));
36
- }
37
-
38
- // 根据 URL 协议选择合适的模块
39
- const client = fileUrl.startsWith('https') ? https : http;
40
-
41
- return new Promise((resolve, reject) => {
42
- client.get(fileUrl, (res) => {
43
- const statusCode = res.statusCode;
44
-
45
- // --- 处理重定向 (3xx 状态码) ---
46
- if (statusCode >= 300 && statusCode < 400 && res.headers.location) {
47
- const newUrl = res.headers.location;
48
- console.log(`[重定向] 遇到状态码 ${statusCode},重定向至: ${newUrl}`);
49
- // 递归调用自身,跟随重定向
50
- return getBase64FromURL(newUrl, redirects - 1)
51
- .then(resolve)
52
- .catch(reject);
53
- }
54
-
55
- // --- 处理请求失败 (4xx, 5xx) ---
56
- if (statusCode < 200 || statusCode >= 400) {
57
- return reject(new Error(`[远程文件错误] 请求失败,状态码: ${statusCode} (${fileUrl})`));
58
- }
59
-
60
- // --- 成功获取 (2xx) ---
61
- const chunks = [];
62
- res.on('data', (chunk) => {
63
- chunks.push(chunk);
64
- });
65
-
66
- res.on('end', () => {
67
- try {
68
- // 合并所有 Buffer 块并转换为 Base64 字符串
69
- const buffer = Buffer.concat(chunks);
70
- const base64String = buffer.toString('base64');
71
- resolve(base64String);
72
- } catch (e) {
73
- reject(new Error(`[远程文件错误] 处理远程文件数据失败: ${e.message}`));
74
- }
75
- });
76
-
77
- }).on('error', (err) => {
78
- console.error(`[远程文件错误] 远程请求连接错误: ${err.message}`);
79
- reject(err);
80
- });
81
- });
82
- }
83
-
84
- /*
85
- // ------------------------------------
86
- // 示例执行
87
- // ------------------------------------
88
-
89
- // 1. 本地文件示例(请确保 'test.bmp' 存在于同一目录下)
90
- // 注意:如果文件不存在,会捕获到错误。
91
- getBase64FromLocalFile('Base64.js.test.png')
92
- .then(base64String => {
93
- console.log('\n--- 本地文件结果 ---');
94
- console.log(`本地文件的 Base64 编码长度: ${base64String.length}`);
95
- console.log(`本地文件的 Base64 编码 (前50字符): ${base64String.substring(0, 50)}...`);
96
- })
97
- .catch(error => {
98
- // 捕获本地文件不存在或权限不足的错误
99
- console.error('\n--- 本地文件错误 ---');
100
- console.error('获取本地文件 Base64 失败:', error.message);
101
- });
102
-
103
- // 2. 远程 URL 示例(使用支持重定向的函数)
104
- const remoteUrl = 'https://picsum.photos/200/300'; // 这个 URL 会导致 302 重定向
105
- getBase64FromURL(remoteUrl)
106
- .then(base64String => {
107
- console.log('\n--- 远程文件结果 ---');
108
- console.log(`远程文件的 Base64 编码长度: ${base64String.length}`);
109
- console.log(`远程文件的 Base64 编码 (前50字符): ${base64String.substring(0, 50)}...`);
110
- })
111
- .catch(error => {
112
- // 捕获请求失败或重定向超时的错误
113
- console.error('\n--- 远程文件错误 ---');
114
- console.error('获取远程文件 Base64 失败:', error.message);
115
- });
116
- */
117
-
118
- export {
119
- getBase64FromLocalFile,
120
- getBase64FromURL
121
- }
122
- export default {
123
- getBase64FromLocalFile,
124
- getBase64FromURL
125
- }
Binary file
@@ -1,85 +0,0 @@
1
- import * as fs from 'fs/promises';
2
- import * as path from 'path';
3
-
4
- /**
5
- * 🚀 删除指定的文件夹及其包含的所有文件和子文件夹。
6
- *
7
- * @param {string} folderPath - 要删除的文件夹的绝对或相对路径。
8
- * @returns {Promise<void>} 一个在删除成功时解析的 Promise。
9
- */
10
- async function deleteFolder(folderPath) {
11
- // 检查路径是否存在,避免不必要的错误日志 (可选,fs.rm在路径不存在时会报错)
12
- try {
13
- await fs.access(folderPath);
14
- } catch (error) {
15
- if (error.code === 'ENOENT') {
16
- console.log(`文件夹 ${folderPath} 不存在,无需删除。`);
17
- return;
18
- }
19
- throw error; // 抛出其他类型的文件系统错误
20
- }
21
-
22
- try {
23
- console.log(`正在删除文件夹及其内容: ${folderPath}`);
24
- // 使用 { recursive: true, force: true } 来递归地强制删除。
25
- // force: true 忽略路径不存在时的错误。
26
- await fs.rm(folderPath, { recursive: true, force: true });
27
- console.log(`✅ 文件夹及其内容删除成功: ${folderPath}`);
28
- } catch (error) {
29
- console.error(`❌ 删除文件夹 ${folderPath} 失败:`, error);
30
- throw error;
31
- }
32
- }
33
-
34
- /**
35
- * ✨ 清空指定的文件夹,但保留文件夹本身。
36
- *
37
- * @param {string} folderPath - 要清空的文件夹的绝对或相对路径。
38
- * @returns {Promise<void>} 一个在清空成功时解析的 Promise。
39
- */
40
- async function clearFolder(folderPath) {
41
- try {
42
- // 1. 读取文件夹中的所有文件和子目录名
43
- const files = await fs.readdir(folderPath);
44
-
45
- if (files.length === 0) {
46
- console.log(`文件夹 ${folderPath} 已经是空的。`);
47
- return;
48
- }
49
-
50
- console.log(`正在清空文件夹内容: ${folderPath}`);
51
-
52
- // 2. 使用 Promise.all 并行删除所有内容
53
- const deletePromises = files.map(file => {
54
- const fullPath = path.join(folderPath, file);
55
- // 对于每个项目,我们使用 fs.rm 配合 { recursive: true, force: true }。
56
- // 这样无论是文件还是子文件夹,都可以被正确删除。
57
- return fs.rm(fullPath, { recursive: true, force: true })
58
- .then(() => console.log(` - 已删除: ${file}`))
59
- .catch(err => {
60
- console.error(` - ❌ 无法删除 ${file}: ${err.message}`);
61
- // 决定是否抛出错误,这里我们选择记录错误但不中断整个清空过程。
62
- });
63
- });
64
-
65
- await Promise.all(deletePromises);
66
-
67
- console.log(`✅ 文件夹 ${folderPath} 内容清空成功。`);
68
- } catch (error) {
69
- if (error.code === 'ENOENT') {
70
- console.error(`❌ 文件夹 ${folderPath} 不存在,无法清空。`);
71
- } else {
72
- console.error(`❌ 清空文件夹 ${folderPath} 失败:`, error);
73
- }
74
- throw error;
75
- }
76
- }
77
-
78
- export {
79
- deleteFolder,
80
- clearFolder
81
- }
82
- export default {
83
- deleteFolder,
84
- clearFolder
85
- }