@waline/vercel 1.30.1 → 1.30.2

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.
Files changed (59) hide show
  1. package/package.json +9 -6
  2. package/src/controller/db.js +18 -0
  3. package/dist/404.html +0 -39
  4. package/dist/500.html +0 -275
  5. package/dist/index.js +0 -58521
  6. package/dist/package.json +0 -55
  7. package/dist/src/config/adapter.js +0 -170
  8. package/dist/src/config/config.js +0 -134
  9. package/dist/src/config/extend.js +0 -38
  10. package/dist/src/config/middleware.js +0 -67
  11. package/dist/src/config/router.js +0 -1
  12. package/dist/src/controller/article.js +0 -88
  13. package/dist/src/controller/comment.js +0 -736
  14. package/dist/src/controller/db.js +0 -71
  15. package/dist/src/controller/index.js +0 -36
  16. package/dist/src/controller/oauth.js +0 -136
  17. package/dist/src/controller/rest.js +0 -60
  18. package/dist/src/controller/token/2fa.js +0 -67
  19. package/dist/src/controller/token.js +0 -76
  20. package/dist/src/controller/user/password.js +0 -53
  21. package/dist/src/controller/user.js +0 -290
  22. package/dist/src/controller/verification.js +0 -35
  23. package/dist/src/extend/controller.js +0 -26
  24. package/dist/src/extend/think.js +0 -104
  25. package/dist/src/locales/en.json +0 -19
  26. package/dist/src/locales/index.js +0 -12
  27. package/dist/src/locales/zh-CN.json +0 -19
  28. package/dist/src/locales/zh-TW.json +0 -19
  29. package/dist/src/logic/article.js +0 -27
  30. package/dist/src/logic/base.js +0 -165
  31. package/dist/src/logic/comment.js +0 -317
  32. package/dist/src/logic/db.js +0 -81
  33. package/dist/src/logic/oauth.js +0 -10
  34. package/dist/src/logic/token/2fa.js +0 -28
  35. package/dist/src/logic/token.js +0 -53
  36. package/dist/src/logic/user/password.js +0 -11
  37. package/dist/src/logic/user.js +0 -117
  38. package/dist/src/middleware/dashboard.js +0 -23
  39. package/dist/src/middleware/version.js +0 -6
  40. package/dist/src/service/akismet.js +0 -42
  41. package/dist/src/service/avatar.js +0 -36
  42. package/dist/src/service/markdown/highlight.js +0 -32
  43. package/dist/src/service/markdown/index.js +0 -64
  44. package/dist/src/service/markdown/katex.js +0 -50
  45. package/dist/src/service/markdown/mathCommon.js +0 -156
  46. package/dist/src/service/markdown/mathjax.js +0 -78
  47. package/dist/src/service/markdown/utils.js +0 -11
  48. package/dist/src/service/markdown/xss.js +0 -44
  49. package/dist/src/service/notify.js +0 -538
  50. package/dist/src/service/storage/base.js +0 -31
  51. package/dist/src/service/storage/cloudbase.js +0 -222
  52. package/dist/src/service/storage/deta.js +0 -309
  53. package/dist/src/service/storage/github.js +0 -379
  54. package/dist/src/service/storage/leancloud.js +0 -432
  55. package/dist/src/service/storage/mongodb.js +0 -180
  56. package/dist/src/service/storage/mysql.js +0 -123
  57. package/dist/src/service/storage/postgresql.js +0 -84
  58. package/dist/src/service/storage/sqlite.js +0 -11
  59. package/dist/src/service/storage/tidb.js +0 -3
@@ -1,222 +0,0 @@
1
- const cloudbase = require('@cloudbase/node-sdk');
2
-
3
- const Base = require('./base');
4
-
5
- const { TCB_ENV, TCB_ID, TCB_KEY } = process.env;
6
- const app = cloudbase.init({
7
- env: TCB_ENV,
8
- secretId: TCB_ID,
9
- secretKey: TCB_KEY,
10
- });
11
-
12
- const db = app.database();
13
- const _ = db.command;
14
- const $ = db.command.aggregate;
15
- const collections = {};
16
-
17
- module.exports = class extends Base {
18
- async collection(tableName) {
19
- if (collections[tableName]) {
20
- return db.collection(tableName);
21
- }
22
-
23
- try {
24
- const instance = db.collection(tableName);
25
-
26
- await instance.count();
27
- collections[tableName] = true;
28
-
29
- return db.collection(tableName);
30
- } catch (e) {
31
- if (e.code === 'DATABASE_COLLECTION_NOT_EXIST') {
32
- await db.createCollection(tableName);
33
- collections[tableName] = true;
34
-
35
- return db.collection(tableName);
36
- }
37
- throw e;
38
- }
39
- }
40
-
41
- parseWhere(where) {
42
- if (think.isEmpty(where)) {
43
- return {};
44
- }
45
-
46
- const filter = {};
47
- const parseKey = (k) => (k === 'objectId' ? '_id' : k);
48
-
49
- for (let k in where) {
50
- if (k === '_complex') {
51
- continue;
52
- }
53
- if (think.isString(where[k])) {
54
- filter[parseKey(k)] = _.eq(where[k]);
55
- continue;
56
- }
57
- if (where[k] === undefined) {
58
- filter[parseKey(k)] = _.eq(null);
59
- }
60
- if (Array.isArray(where[k])) {
61
- if (where[k][0]) {
62
- const handler = where[k][0].toUpperCase();
63
-
64
- switch (handler) {
65
- case 'IN':
66
- filter[parseKey(k)] = _.in(where[k][1]);
67
- break;
68
- case 'NOT IN':
69
- filter[parseKey(k)] = _.nin(where[k][1]);
70
- break;
71
- case 'LIKE': {
72
- const first = where[k][1][0];
73
- const last = where[k][1].slice(-1);
74
- let reg;
75
-
76
- if (first === '%' && last === '%') {
77
- reg = new RegExp(where[k][1].slice(1, -1));
78
- } else if (first === '%') {
79
- reg = new RegExp(where[k][1].slice(1) + '$');
80
- } else if (last === '%') {
81
- reg = new RegExp('^' + where[k][1].slice(0, -1));
82
- }
83
- filter[parseKey(k)] = reg;
84
- break;
85
- }
86
- case '!=': {
87
- filter[parseKey(k)] = _.neq(where[k][1]);
88
- break;
89
- }
90
- case '>': {
91
- filter[parseKey(k)] = _.gt(where[k][1]);
92
- break;
93
- }
94
- }
95
- }
96
- }
97
- }
98
-
99
- return filter;
100
- }
101
-
102
- where(instance, where, method = 'where') {
103
- const filter = this.parseWhere(where);
104
-
105
- if (!where._complex) {
106
- return instance[method](filter);
107
- }
108
-
109
- const filters = [];
110
-
111
- for (const k in where._complex) {
112
- if (k === '_logic') {
113
- continue;
114
- }
115
- filters.push({
116
- ...this.parseWhere({ [k]: where._complex[k] }),
117
- ...filter,
118
- });
119
- }
120
-
121
- return instance[method](_[where._complex._logic](...filters));
122
- }
123
-
124
- async _select(where, { desc, limit, offset, field } = {}) {
125
- let instance = await this.collection(this.tableName);
126
-
127
- instance = this.where(instance, where);
128
- if (desc) {
129
- instance = instance.orderBy(desc, 'desc');
130
- }
131
- if (limit) {
132
- instance = instance.limit(limit);
133
- }
134
- if (offset) {
135
- instance = instance.skip(offset);
136
- }
137
- if (field) {
138
- const filedObj = {};
139
-
140
- field.forEach((f) => (filedObj[f] = true));
141
- instance = instance.field(filedObj);
142
- }
143
-
144
- const { data } = await instance.get();
145
-
146
- return data.map(({ _id, ...cmt }) => ({
147
- ...cmt,
148
- objectId: _id.toString(),
149
- }));
150
- }
151
-
152
- async select(where, options = {}) {
153
- let data = [];
154
- let ret = [];
155
- let offset = options.offset || 0;
156
-
157
- do {
158
- options.offset = offset + data.length;
159
- ret = await this._select(where, options);
160
- data = data.concat(ret);
161
- } while (ret.length === 100);
162
-
163
- return data;
164
- }
165
-
166
- async count(where = {}, { group } = {}) {
167
- let instance = await this.collection(this.tableName);
168
-
169
- if (!group) {
170
- instance = this.where(instance, where);
171
- const { total } = await instance.count();
172
-
173
- return total;
174
- }
175
-
176
- const _id = {};
177
-
178
- group.forEach((f) => {
179
- _id[f] = `$${f}`;
180
- });
181
- instance = instance.aggregate();
182
- this.where(instance, where, 'match');
183
- instance = instance.group({ _id, count: $.sum(1) });
184
- const { data } = await instance.end();
185
-
186
- return data.map(({ _id, count }) => ({ ..._id, count }));
187
- }
188
-
189
- async add(data) {
190
- if (data.objectId) {
191
- data._id = data.objectId;
192
- delete data.objectId;
193
- }
194
-
195
- const instance = await this.collection(this.tableName);
196
- const { id } = await instance.add(data);
197
-
198
- return { ...data, objectId: id };
199
- }
200
-
201
- async update(data, where) {
202
- const instance = await this.collection(this.tableName);
203
- const { data: list } = await this.where(instance, where).get();
204
-
205
- return Promise.all(
206
- list.map(async (item) => {
207
- const updateData = typeof data === 'function' ? data(item) : data;
208
- const instance = await this.collection(this.tableName);
209
-
210
- await instance.doc(item._id).update(updateData);
211
-
212
- return { ...item, ...updateData };
213
- })
214
- );
215
- }
216
-
217
- async delete(where) {
218
- const instance = await this.collection(this.tableName);
219
-
220
- return this.where(instance, where).remove();
221
- }
222
- };
@@ -1,309 +0,0 @@
1
- const { performance } = require('perf_hooks');
2
-
3
- const { Deta } = require('deta');
4
-
5
- const Base = require('./base');
6
-
7
- module.exports = class extends Base {
8
- constructor(tableName) {
9
- super(tableName);
10
- const deta = Deta(process.env.DETA_PROJECT_KEY);
11
-
12
- this.instance = deta.Base(tableName);
13
- }
14
-
15
- complex(obj, keys) {
16
- const result = new Array(keys.reduce((a, b) => a * obj[b].length, 1));
17
-
18
- for (let i = 0; i < result.length; i++) {
19
- result[i] = { ...obj };
20
- for (let n = 0; n < keys.length; n++) {
21
- const divisor = keys
22
- .slice(n + 1)
23
- .reduce((a, b) => a * obj[b].length, 1);
24
- const idx = Math.floor(i / divisor) % obj[keys[n]].length;
25
-
26
- result[i][keys[n]] = obj[keys[n]][idx];
27
- }
28
- }
29
-
30
- return result;
31
- }
32
-
33
- /**
34
- * deta base doesn't support order data by field
35
- * it will order by key default
36
- * so we need create a lower key than before to keep latest data in front
37
- * @returns string
38
- */
39
- async uuid() {
40
- const items = await this.select({}, { limit: 1 });
41
- let lastKey;
42
-
43
- if (items.length && !isNaN(parseInt(items[0].objectId))) {
44
- lastKey = parseInt(items[0].objectId);
45
- } else {
46
- lastKey = Number.MAX_SAFE_INTEGER - performance.now();
47
- }
48
-
49
- return (lastKey - Math.round(Math.random() * 100)).toString();
50
- }
51
-
52
- parseWhere(where) {
53
- if (think.isEmpty(where)) {
54
- return;
55
- }
56
-
57
- const parseKey = (k) => (k === 'objectId' ? 'key' : k);
58
- const conditions = {};
59
- const _isArrayKeys = [];
60
-
61
- for (let k in where) {
62
- if (think.isString(where[k])) {
63
- conditions[parseKey(k)] = where[k];
64
- continue;
65
- }
66
- if (where[k] === undefined) {
67
- conditions[parseKey(k)] = null;
68
- }
69
-
70
- if (!think.isArray(where[k]) || !where[k][0]) {
71
- continue;
72
- }
73
- const handler = where[k][0].toUpperCase();
74
-
75
- switch (handler) {
76
- case 'IN':
77
- conditions[parseKey(k)] = where[k][1];
78
- if (think.isArray(where[k][1])) {
79
- _isArrayKeys.push(parseKey(k));
80
- }
81
- break;
82
- case 'NOT IN':
83
- /**
84
- * deta base doesn't support not equal with multiple value query
85
- * so we have to transfer it into equal with some value in most of scene
86
- */
87
- if (Array.isArray(where[k][1]) && parseKey(k) === 'status') {
88
- const STATUS = ['approved', 'waiting', 'spam'];
89
- let val = STATUS.filter((s) => !where[k][1].includes(s));
90
-
91
- if (val.length === 1) {
92
- val = val[0];
93
- }
94
- conditions[parseKey(k)] = val;
95
- }
96
- conditions[parseKey(k) + '?ne'] = where[k][1];
97
- break;
98
- case 'LIKE': {
99
- const first = where[k][1][0];
100
- const last = where[k][1].slice(-1);
101
-
102
- if (first === '%' && last === '%') {
103
- conditions[parseKey(k) + '?contains'] = where[k][1].slice(1, -1);
104
- } else if (first === '%') {
105
- conditions[parseKey(k) + '?contains'] = where[k][1].slice(1);
106
- } else if (last === '%') {
107
- conditions[parseKey(k) + '?pfx'] = where[k][1].slice(0, -1);
108
- }
109
- break;
110
- }
111
- case '!=':
112
- conditions[parseKey(k) + '?ne'] = where[k][1];
113
- break;
114
- case '>':
115
- conditions[parseKey(k) + '?gt'] = where[k][1];
116
- break;
117
- }
118
- }
119
-
120
- if (_isArrayKeys.length === 0) {
121
- return conditions;
122
- }
123
-
124
- return this.complex(conditions, _isArrayKeys);
125
- }
126
-
127
- where(where) {
128
- const filter = this.parseWhere(where);
129
-
130
- if (!where._complex) {
131
- return filter;
132
- }
133
-
134
- const filters = [];
135
-
136
- for (const k in where._complex) {
137
- if (k === '_logic') {
138
- continue;
139
- }
140
- filters.push({
141
- ...this.parseWhere({ [k]: where._complex[k] }),
142
- ...filter,
143
- });
144
- }
145
-
146
- // just support OR logic for deta
147
- return filters;
148
- }
149
-
150
- async select(where, { limit, offset, field } = {}) {
151
- const conditions = this.where(where);
152
-
153
- if (think.isArray(conditions)) {
154
- return Promise.all(
155
- conditions.map((condition) =>
156
- this.select(condition, { limit, offset, field })
157
- )
158
- ).then((data) => data.flat());
159
- }
160
-
161
- let data = [];
162
-
163
- if (
164
- think.isObject(conditions) &&
165
- think.isString(conditions.key) &&
166
- conditions.key
167
- ) {
168
- /**
169
- * deta base doesn't support fetch with key field query
170
- * if you want query by key field
171
- * you need use `get()` rather than `fetch()` method.
172
- */
173
- const item = await this.instance.get(conditions.key);
174
-
175
- item && data.push(item);
176
- } else if (offset) {
177
- /**
178
- * deta base need last data key when pagination
179
- * so we need fetch data list again and again
180
- * because only that we can get last data key
181
- */
182
- while (data.length < limit + offset) {
183
- const lastData = data[data.length - 1];
184
- const last = lastData ? lastData.key : undefined;
185
- const { items } = await this.instance.fetch(conditions, {
186
- limit,
187
- last,
188
- });
189
-
190
- data = data.concat(items);
191
-
192
- if (items.length < limit) {
193
- break;
194
- }
195
- }
196
-
197
- data = data.slice(offset, offset + limit);
198
- } else {
199
- const { items } = await this.instance.fetch(conditions, {
200
- limit: limit,
201
- });
202
-
203
- data = items || [];
204
- }
205
-
206
- data = data.map(({ key, ...cmt }) => ({
207
- ...cmt,
208
- objectId: key,
209
- }));
210
-
211
- if (Array.isArray(field)) {
212
- const fieldMap = new Set(field);
213
-
214
- fieldMap.add('objectId');
215
- data.forEach((item) => {
216
- for (const k in item) {
217
- if (!fieldMap.has(k)) {
218
- delete item[k];
219
- }
220
- }
221
- });
222
- }
223
-
224
- return data;
225
- }
226
-
227
- async count(where = {}, { group } = {}) {
228
- if (!group) {
229
- const conditions = this.where(where);
230
-
231
- if (think.isArray(conditions)) {
232
- return Promise.all(
233
- conditions.map((condition) => this.count(condition))
234
- ).then((counts) => counts.reduce((a, b) => a + b, 0));
235
- }
236
-
237
- const { count } = await this.instance.fetch(conditions);
238
-
239
- return count;
240
- }
241
-
242
- const counts = [];
243
-
244
- for (let i = 0; i < group.length; i++) {
245
- const groupName = group[i];
246
-
247
- if (!where._complex || !Array.isArray(where._complex[groupName])) {
248
- continue;
249
- }
250
-
251
- const groupFlatValue = {};
252
-
253
- group.slice(0, i).forEach((group) => {
254
- groupFlatValue[group] = null;
255
- });
256
-
257
- for (let j = 0; j < where._complex[groupName][1].length; j++) {
258
- const groupWhere = {
259
- ...where,
260
- ...groupFlatValue,
261
- _complex: undefined,
262
- [groupName]: where._complex[groupName][1][j],
263
- };
264
- const num = await this.count(groupWhere);
265
-
266
- counts.push({
267
- ...groupFlatValue,
268
- [groupName]: where._complex[groupName][1][j],
269
- count: num,
270
- });
271
- }
272
- }
273
-
274
- return counts;
275
- }
276
-
277
- async add(data) {
278
- const uuid = await this.uuid();
279
- const resp = await this.instance.put(data, uuid);
280
-
281
- resp.objectId = resp.key;
282
- delete resp.key;
283
-
284
- return resp;
285
- }
286
-
287
- async update(data, where) {
288
- const items = await this.select(where);
289
-
290
- return Promise.all(
291
- items.map(async (item) => {
292
- const updateData = typeof data === 'function' ? data(item) : data;
293
- const nextData = { ...item, ...updateData };
294
-
295
- await this.instance.put(nextData, item.objectId);
296
-
297
- return nextData;
298
- })
299
- );
300
- }
301
-
302
- async delete(where) {
303
- const items = await this.select(where);
304
-
305
- return Promise.all(
306
- items.map(({ objectId }) => this.instance.delete(objectId))
307
- );
308
- }
309
- };