-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublic.js
More file actions
86 lines (83 loc) · 2.17 KB
/
Copy pathpublic.js
File metadata and controls
86 lines (83 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 用于将组件发布到数据库系统中。
/**
* view 节点的范围 [1:只在视图区, 2:只在关系区, 3:即在视图区也在关系区]
*/
const components = [
{
id: "gis-map",
name: "GIS",
type: "node",
icon: "#icon-gisditu",
title: `地图:
Angular@16.1+leaflet+echarts`,
view: 0,
family: "chart",
color: "#2f938f",
des: "基础的gis地图",
component: "GisMapComponent",
},
];
const fs = require("fs"),
path = require("path"),
request = require("request");
const filesName = [
{ name: "main.js", decorator: { defer: true } },
// { name: "polyfills.js", decorator: { defer: true } },
{ name: "runtime.js", decorator: { defer: true } },
// { name: 'vendor.js', decorator: { defer: true } },
"styles.css",
];
const area = "gis",
folderPath = "./dist/my-gis-map";
components.map((item) => {
item["filesName"] = filesName;
item["area"] = area;
});
let options = {
url: "http://127.0.0.1:3000/upload",
method: "POST",
headers: {
"content-type": "multipart/form-data",
},
formData: {
files: [],
area,
components: JSON.stringify(components),
},
};
// 递归遍历文件夹中的所有文件
function uploadFolder(folderPath, dir) {
const files = fs.readdirSync(folderPath);
files.forEach((file) => {
const filePath = folderPath + "/" + file;
// 判断是否为文件夹
if (fs.statSync(filePath).isDirectory()) {
// 递归上传子文件夹
uploadFolder(filePath, dir + "/" + file);
} else {
// 上传文件
uploadFile(filePath, dir, file);
}
});
}
// 缓存上传文件
function uploadFile(filePath, dir, fileName) {
const content = fs.readFileSync(path.resolve(__dirname, filePath));
options.formData.files.push({
content: Buffer.from(content).toString(),
dir,
fileName,
});
}
// 将文件缓存
uploadFolder(folderPath, "");
console.log("共上传文件数:", options.formData.files.length);
//@ts-ignore
options.formData.files = JSON.stringify(options.formData.files);
request(options, (err, res, body) => {
if (res.statusCode === 200) {
console.log("上传完成");
} else {
console.log(body);
}
});