-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.js
321 lines (284 loc) · 18.7 KB
/
util.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
const path = require("path");
module.exports.resourceListFields = [
"_id",
"name",
"tag",
"contributors",
"external",
"likes",
"file",
"testedVersions",
"sourceCodeLink",
"donationLink",
"supportedLanguages",
"links",
"version",
"author",
"category",
"rating",
"releaseDate",
"updateDate",
"downloads",
"icon",
"icon.url",
"icon.data",
"author",
"premium",
"existenceStatus",
"hidden"
];
module.exports.resourceAllFields = [
"_id",
"name",
"tag",
"contributors",
"external",
"file",
"description",
"documentation",
"likes",
"testedVersions",
"sourceCodeLink",
"donationLink",
"supportedLanguages",
"version",
"versions",
"updates",
"links",
"author",
"category",
"rating",
"releaseDate",
"updateDate",
"downloads",
"icon",
"icon.url",
"icon.data",
"reviews",
"premium",
"price",
"currency",
"existenceStatus",
"hidden"
];
module.exports.authorAllFields = [
"_id",
"name",
"icon",
"identities"
];
module.exports.reviewAllFields = [
"_id",
"author",
"rating",
"message",
"version",
"date",
"resource",
"responseMessage"
];
module.exports.updateAllFields = [
"_id",
"title",
"description",
"date",
"likes",
"resource"
];
module.exports.versionAllFields = [
"_id",
"uuid",
"downloads",
"rating",
"url",
"name",
"releaseDate",
"resource"
];
module.exports.categoryAllFields = [
"_id",
"name"
];
module.exports.notFoundImg = {
url: "https://spiget.org/img/not-found-256.png",
data: "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QIaFTQqLtTdpgAAH7dJREFUeNrtnXuYXFWZr99VVX1P0rkn3MUECEQw3BRBBBFhhAiCDIqFiI4IjuN4RoXDHI/D6HE8jI7jjaMzioOgNQIzDggDHBRFARkUDUQQUEgIAZKQC0m60/eu2vPH+nb36squvoSu7rr83uepp6urdu2919rr+61vfevmEHVFlCMDvAo4CzgbeNMET7Ea+CfgFmCbyzKoXK1enLKgbgw/BZwAfBA4A5j/Ck+5A/g+cJPL8oByWAIgKtf4X2PGegAwe5JP3wXcDnzAZelRbksAROUYfiPwUeBqIDMFl3wzcL/LklfuVwcpZUHNGv8y4DrgH6bI+AHuBb4R5WjTE5AHIKbP+E8A/h1YPE23cKs1CbbraUgAptMQXELtVwgPcdkR/9dCmt9ibfKWab6Vu4CLXJatNVimUkU2FNpRoZqaQLUuAK8DHoShmigCfmmikAZ+Bzxs77uBnXZMBHTYZw7odVleqIL0HoMP9h1SIbd0H/A+l2VdFeRdE7CPPe8UsJdVFvng8zxwBHBUcNyrgYV2rANucVkukQBUjis8kS6q7kAAdtn/KaAXWGP5lQF+a987E42ngQbgRZflkWlK6wITu6UV9hieAc6fxnw5OjDmucCBZsgZ4Bg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k06EqLsHItf2GO8a/tfVgbD3Af4ELCK4fUIBtBeh0JMCZ9jfLMB49evrEmwFGidwHUcftzBPvhlwi8D7iJ5cxEJgBATZE/bzO3AzcBpE/hNBDwL/M7iCGvMbX/ZavEUfi+BNvxow33x6w4cYMKxN37V4VIM2u+16agQU8A84JdMbO3/cPOPATP8Xmsq9Nqrz74bZGIbisgDEGIaROA2xhcULPdLAiDENDAL+J/48f/TKQAFCYAQ0xdLOAj43gTd9sl8/UECIMTEDXeyWYHvojsdvyRY2ySfP44ZbMMHEe8Ffgb8hrGHKQshyiwAMYvxIwKPwW//tcwEoZ2xuwIL+HkHnfguv+fwoxDXA88A6+y1SY9QiMoUgPAajfjdgFqB+cBsYKZ9lrJj8vbqwq8mtAPfRdiP7xnoYzjYKISYBP4b2e5RAVlnOSIAAAAASUVORK5CYII="
};
module.exports.fixId = function (docs) {
if (docs) {
if (Array.isArray(docs)) {
return docs.map(doc => {
doc.id = doc._id;
delete doc._id;
return doc;
});
} else {
docs.id = docs._id;
delete docs._id;
}
}
return docs;
};
module.exports.paginatePlugin = function () {
let p = require("mongoose-paginate");
p.paginate.options = {
lean: true,
leanWithId: false,
sort: "_id"
};
return p;
}();
module.exports.paginateReq = function (req, defaultFields, other) {
let fieldStr = selectFields(req, defaultFields);
let sortParam = req.query.sort || "id";
let sortSplit = sortParam.split(",");
let sortObj = {};
for (let i = 0; i < sortSplit.length; i++) {
let sort = sortSplit[i];
let sortMode = 1;
if (sort.indexOf("-") === 0) {
sortMode = -1;
sort = sort.substr(1);
} else if (sort.indexOf("+") === 0) {
sortMode = 1;
sort = sort.substr(1);
}
sort = sort.trim();
if (sort.length <= 0) continue;
if (sort === "id") sort = "_id";
sortObj[sort] = sortMode;
}
return Object.assign({}, {
page: parseInt(req.query.page) || 1,
limit: parseInt(req.query.size) || 10,
sort: sortObj,
select: fieldStr
}, other);
};
function selectFields(req, defaultFields) {
let fieldParam = req.query.fields || (defaultFields || ["id"]).join(",");
let fieldSplit = fieldParam.split(",");
let allowedFields = [];
for (let i = 0; i < fieldSplit.length; i++) {
if (defaultFields.indexOf(fieldSplit[i]) !== -1) {
allowedFields.push(fieldSplit[i]);
}
}
// hack to avoid path collisions
if (allowedFields.includes('icon')) {
let urlInd = allowedFields.indexOf('icon.url');
if (urlInd !== -1) {
allowedFields.splice(urlInd, 1);
}
let dataInd = allowedFields.indexOf('icon.data');
if (dataInd !== -1) {
allowedFields.splice(dataInd, 1);
}
}
return allowedFields.join(" ");
}
module.exports.selectFields = selectFields;
module.exports.paginateRes = function (paginated, res) {
res.set({
"X-Page-Size": paginated.limit,
"X-Page-Index": paginated.page,
"X-Page-Count": paginated.pages,
"X-Total": paginated.total
});
if (paginated.total <= 0) {
res.status(404);
}
return paginated.docs;
};
module.exports.sendImage = function (res, source, type, defaultData, defaultUrl) {
if (type === "raw") {
if (!source || !source.icon.data) {
res.status(404).send(defaultData);
} else {
res.send(source.icon.data);
}
} else if (type === "go") {
if (!source || !source.icon.url) {
res.status(404).redirect(defaultUrl);
} else {
res.redirect("https://spigotmc.org/" + source.icon.url);
}
} else if (type === "url") {
if (!source || !source.icon.url) {
res.status(404).send(source.icon.url);
} else {
res.send("https://spigotmc.org/" + source.icon.url);
}
} else {
res.set({
"Content-Type": "image/jpeg"
});
if (!source || !source.icon.data) {
res.status(404).end(new Buffer(defaultData, "base64"));
} else {
res.end(new Buffer(source.icon.data, "base64"));
}
}
};
module.exports.timeInSeconds = function () {
return Date.now() / 1000;
};
module.exports.forceArray = function (obj) {
return [].concat(obj || []);
};
module.exports.forceObject = function (arr) {
if (Array.isArray(arr)) {
return arr[0];
}
return arr;
};
module.exports.pad = function (s, l) {
while (s.length < l) {
s = "0" + s;
}
return s;
};
module.exports.trim = function (s, l) {
if (s.length <= l) return s;
return s.substring(s.length - 1);
};
// https://github.com/SpiGetOrg/SpigetData/blob/master/src/main/java/org/spiget/data/resource/version/ResourceVersion.java#L40
// module.exports.makeVersionUuid = function (resourceId, authorId, versionName, updateCount, date) {
// const versionNameNumber = versionName.replace(/[^\d]/g, "");
// const dateString = date.getFullYear() + "" + module.exports.pad("" + (date.getMonth() + 1), 2) + module.exports.pad("" + date.getDate(), 2);
// const stringA = "16" + module.exports.trim("" + authorId, 6) + "" + module.exports.trim("" + resourceId, 6) + "" + module.exports.trim(module.exports.pad("" + versionNameNumber, 5), 5);
// const stringB = "16" + module.exports.trim("" + resourceId, 6) + "" + dateString + "" + module.exports.trim(module.exports.pad("" + updateCount, 2), 3);
// return module.exports.javaUuid(BigInt(stringA), BigInt(stringB));
// };
//
// // Java UUID#toString
// module.exports.javaUuid = function (mostSigBits, leastSigBits) {
// return (module.exports.digits(mostSigBits >> 32n, 8n) + "-" +
// module.exports.digits(mostSigBits >> 16n, 4n) + "-" +
// module.exports.digits(mostSigBits, 4n) + "-" +
// module.exports.digits(leastSigBits >> 48n, 4n) + "-" +
// module.exports.digits(leastSigBits, 12n));
// };
// Java UUID#digits
// module.exports.digits = function (val, digits) {
// const hi = 1n << (digits * 4n);
// return (hi | (val & (hi - 1n))).toString(16).substring(1);
// };
module.exports.makeDownloadFile = function (config, resource, type = ".jar") {
let root = config.resourceFileRoot;
let split = resource.split("");
split.pop();
//// <root>/1/2/3/1234.jar
return path.join(root, split.join("/"), resource + type);
};
module.exports.redirectToMaster = function (req, res, config) {
if (config.server.masterHost && config.server.masterHost.length > 0) {
let url = "https://" + config.server.masterHost + req.originalUrl;
console.log("Redirecting slave request to master:", url);
res.redirect(307, url);
} else {
console.warn("Unable to redirect slave request to master, as no master host is configured");
}
};
module.exports.escapeRegex = function (string) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}