@digione/node-custom-api 0.2.0-beta1 → 0.2.0-beta2
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/models/user/user.d.ts +0 -3
- package/models/user/user.js +0 -4
- package/package.json +1 -1
- package/utils/file.d.ts +10 -3
- package/utils/file.js +31 -17
- package/utils/stream.js +2 -2
package/models/user/user.d.ts
CHANGED
|
@@ -50,9 +50,6 @@ export declare const UserAttr: {
|
|
|
50
50
|
organ_id: {
|
|
51
51
|
type: sequelize.IntegerDataType;
|
|
52
52
|
};
|
|
53
|
-
member_id: {
|
|
54
|
-
type: sequelize.StringDataType;
|
|
55
|
-
};
|
|
56
53
|
provider: sequelize.StringDataType;
|
|
57
54
|
mobile: sequelize.StringDataType;
|
|
58
55
|
mobile_code: sequelize.StringDataType;
|
package/models/user/user.js
CHANGED
|
@@ -58,10 +58,6 @@ exports.UserAttr = {
|
|
|
58
58
|
organ_id: {
|
|
59
59
|
type: sequelize.INTEGER({ length: 11 })
|
|
60
60
|
},
|
|
61
|
-
// points:sequelize.INTEGER({length:11}),
|
|
62
|
-
member_id: {
|
|
63
|
-
type: sequelize.STRING(100)
|
|
64
|
-
},
|
|
65
61
|
provider: sequelize.STRING(40),
|
|
66
62
|
mobile: sequelize.STRING(20),
|
|
67
63
|
mobile_code: sequelize.STRING(10)
|
package/package.json
CHANGED
package/utils/file.d.ts
CHANGED
|
@@ -62,16 +62,23 @@ export declare class FileUtil {
|
|
|
62
62
|
width?: number;
|
|
63
63
|
height?: number;
|
|
64
64
|
}): Promise<any>;
|
|
65
|
-
beforeFindFile(where?: {}, { tags, group }?: {
|
|
65
|
+
beforeFindFile(where?: {}, { attributes, tags, group, verify }?: {
|
|
66
|
+
attributes?: any;
|
|
66
67
|
tags?: TagFile;
|
|
67
68
|
group?: any;
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
verify?: boolean;
|
|
70
|
+
}): {
|
|
71
|
+
where: {};
|
|
72
|
+
attributes: any;
|
|
73
|
+
order: any[];
|
|
74
|
+
};
|
|
75
|
+
findAllFile({ where, folder, full, file_link, thumb, verify, width, height, parent_folder, attributes, limit, offset, tag, tags, group }?: {
|
|
70
76
|
where?: {};
|
|
71
77
|
folder?: boolean;
|
|
72
78
|
full?: boolean;
|
|
73
79
|
file_link?: boolean;
|
|
74
80
|
thumb?: boolean;
|
|
81
|
+
verify?: boolean;
|
|
75
82
|
width?: number;
|
|
76
83
|
height?: number;
|
|
77
84
|
parent_folder?: string;
|
package/utils/file.js
CHANGED
|
@@ -108,6 +108,7 @@ class FileUtil {
|
|
|
108
108
|
}
|
|
109
109
|
afterQueryFile(data = {}, { tag = {}, file_link = false } = {}) {
|
|
110
110
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
delete data['thumbnail'];
|
|
111
112
|
data['custom'] = data['custom'] || {};
|
|
112
113
|
data['tags'] = data['tags'] || [];
|
|
113
114
|
if (data['filename'] == data['path']) {
|
|
@@ -276,12 +277,12 @@ class FileUtil {
|
|
|
276
277
|
return null;
|
|
277
278
|
where['$folder.parent_id$'] = query['id'];
|
|
278
279
|
}
|
|
279
|
-
|
|
280
|
+
let option = this.beforeFindFile(where, { attributes: ['id', 'extension', 'filename', 'path', 'thumb'], tags, group });
|
|
280
281
|
let result = yield file_1.FileModel.schema(this.ref, "_").findOne({
|
|
281
|
-
raw: true, attributes:
|
|
282
|
-
where: Object.assign({ '$folder.slug$': slug }, where),
|
|
282
|
+
raw: true, attributes: option.attributes,
|
|
283
|
+
where: Object.assign({ '$folder.slug$': slug }, option.where),
|
|
283
284
|
include: [{ as: 'folder', model: folder_1.FolderModel.schema(this.ref, "_"), attributes: [] }],
|
|
284
|
-
order:
|
|
285
|
+
order: option.order
|
|
285
286
|
});
|
|
286
287
|
return this.findImageThumb(result, { width, height });
|
|
287
288
|
}
|
|
@@ -299,7 +300,8 @@ class FileUtil {
|
|
|
299
300
|
return this.findImageThumb(item, { width, height });
|
|
300
301
|
});
|
|
301
302
|
}
|
|
302
|
-
beforeFindFile(where = {}, { tags = [], group = undefined } = {}) {
|
|
303
|
+
beforeFindFile(where = {}, { attributes = undefined, tags = [], group = undefined, verify = false } = {}) {
|
|
304
|
+
let order = [['sort', 'asc'], ['tags', 'desc']], thumbnail = false;
|
|
303
305
|
if (this.option.organ_id) {
|
|
304
306
|
where[sequelize_1.Op.and] = (where[sequelize_1.Op.and] || []).concat({ [sequelize_1.Op.or]: [{ organ_id: this.option.organ_id }, { organ_by: this.option.organ_id }] });
|
|
305
307
|
}
|
|
@@ -310,9 +312,11 @@ class FileUtil {
|
|
|
310
312
|
let op = tags.reduce((total, tag) => {
|
|
311
313
|
let value = Object.keys(tag).reduce((total, key) => total.concat([`'${key}'`, `"${tag[key]}"`]), []).join(',');
|
|
312
314
|
if (value) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
315
|
+
if (tag['slug'] == "thumbnail" && !verify) {
|
|
316
|
+
thumbnail = true;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
total = total.concat((0, sequelize_1.literal)(`JSON_CONTAINS(tags,JSON_OBJECT(${value}))`));
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
322
|
return total;
|
|
@@ -321,9 +325,19 @@ class FileUtil {
|
|
|
321
325
|
where[sequelize_1.Op.and] = (where[sequelize_1.Op.and] || []).concat({ [sequelize_1.Op.or]: op });
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
|
-
|
|
328
|
+
if (thumbnail) {
|
|
329
|
+
let include = [[(0, sequelize_1.literal)(`IF(JSON_CONTAINS(tags,JSON_OBJECT('slug',"thumbnail")),'yes','no')`), 'thumbnail']];
|
|
330
|
+
if (typeof attributes == "undefined") {
|
|
331
|
+
attributes = { include };
|
|
332
|
+
}
|
|
333
|
+
else if (attributes instanceof Array) {
|
|
334
|
+
attributes = attributes.concat(include);
|
|
335
|
+
}
|
|
336
|
+
order = [['thumbnail', 'desc'], ['sort', 'asc']];
|
|
337
|
+
}
|
|
338
|
+
return { where, attributes, order };
|
|
325
339
|
}
|
|
326
|
-
findAllFile({ where = {}, folder = false, full = false, file_link = false, thumb = false, width = 0, height = 0, parent_folder = "", attributes = undefined, limit = undefined, offset = undefined, tag = {}, tags = [], group = undefined } = {}) {
|
|
340
|
+
findAllFile({ where = {}, folder = false, full = false, file_link = false, thumb = false, verify = true, width = 0, height = 0, parent_folder = "", attributes = undefined, limit = undefined, offset = undefined, tag = {}, tags = [], group = undefined } = {}) {
|
|
327
341
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
328
342
|
try {
|
|
329
343
|
let include = [];
|
|
@@ -335,10 +349,10 @@ class FileUtil {
|
|
|
335
349
|
return [];
|
|
336
350
|
where['$folder.parent_id$'] = query['id'];
|
|
337
351
|
}
|
|
338
|
-
where = this.beforeFindFile(where, { tags, group });
|
|
339
352
|
where['is_hidden'] = where['is_hidden'] || "no";
|
|
353
|
+
let option = this.beforeFindFile(where, { attributes, tags, group, verify });
|
|
340
354
|
let result = yield file_1.FileModel.schema(this.ref, "_").findAll({
|
|
341
|
-
attributes, raw: true, where, limit, offset, include, order:
|
|
355
|
+
attributes: option.attributes, raw: true, where: option.where, limit, offset, include, order: option.order
|
|
342
356
|
});
|
|
343
357
|
result.length && (yield this.getStorage());
|
|
344
358
|
result = yield Promise.all(result.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -372,9 +386,9 @@ class FileUtil {
|
|
|
372
386
|
if (!folder)
|
|
373
387
|
return { rows: [], count: 0 };
|
|
374
388
|
where['folder_id'] = folder['id'];
|
|
375
|
-
where = this.beforeFindFile(where, { tags, group });
|
|
376
389
|
where['is_hidden'] = where['is_hidden'] || "no";
|
|
377
|
-
let
|
|
390
|
+
let option = this.beforeFindFile(where, { tags, group, verify: true });
|
|
391
|
+
let data = yield Promise.all([this.findAllFile({ where, full: true, file_link, limit, offset, tag, group }), file_1.FileModel.schema(this.ref, "_").count({ where: option.where })]);
|
|
378
392
|
return { rows: data[0], count: data[1] };
|
|
379
393
|
});
|
|
380
394
|
}
|
|
@@ -385,7 +399,7 @@ class FileUtil {
|
|
|
385
399
|
}
|
|
386
400
|
findOneFileByFolder(slug, { where = {}, full = false, file_link = false, parent_folder = "", tags = [], group = null } = {}) {
|
|
387
401
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
388
|
-
return (yield this.findAllFile({ where: Object.assign({ '$folder.slug$': slug }, where), folder: true, full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
402
|
+
return (yield this.findAllFile({ where: Object.assign({ '$folder.slug$': slug }, where), folder: true, full, file_link, verify: false, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
389
403
|
});
|
|
390
404
|
}
|
|
391
405
|
findOneFileById(id, { where = {}, full = true, file_link = false, parent_folder = "", tags = [], group = null } = {}) {
|
|
@@ -678,8 +692,8 @@ class FileUtil {
|
|
|
678
692
|
}
|
|
679
693
|
remove({ where = {}, delete_object = false, error = true, tags = [], group = undefined } = {}) {
|
|
680
694
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
681
|
-
|
|
682
|
-
let files = yield file_1.FileModel.schema(this.ref, "_").findAll({ where, attributes: ['id', 'path', 'thumb'], raw: true });
|
|
695
|
+
let option = this.beforeFindFile(where, { tags, group, verify: true });
|
|
696
|
+
let files = yield file_1.FileModel.schema(this.ref, "_").findAll({ where: option.where, attributes: ['id', 'path', 'thumb'], raw: true });
|
|
683
697
|
if (files.length) {
|
|
684
698
|
let paths = [], id = files.map(i => { paths = paths.concat(this.getFilePath(i)); return i['id']; });
|
|
685
699
|
yield file_1.FileModel.schema(this.ref, "_").destroy({ where: { id } });
|
package/utils/stream.js
CHANGED
|
@@ -956,8 +956,8 @@ class StreamUtil {
|
|
|
956
956
|
}
|
|
957
957
|
let folder = yield fileUtil.createFolder(index, { parent_id: where_folder['parent_id'] });
|
|
958
958
|
let where_file = { folder_id: folder['id'], is_hidden: "yes" };
|
|
959
|
-
|
|
960
|
-
let query = yield file_1.FileModel.schema(ref, "_").findAll({ where:
|
|
959
|
+
let option_file = fileUtil.beforeFindFile(where_file, { tags, group, verify: true });
|
|
960
|
+
let query = yield file_1.FileModel.schema(ref, "_").findAll({ where: option_file.where, attributes: ['id', 'name'], raw: true });
|
|
961
961
|
id_files = query.reduce((total, item) => Object.assign(total, { [item['name']]: item['id'] }), {});
|
|
962
962
|
let input_files = [];
|
|
963
963
|
yield Promise.all(fields.map(({ field_type, field_slug, field_data }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|