@digione/node-custom-api 0.1.8-beta2 → 0.1.9-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/system/file.d.ts +1 -0
- package/models/system/file.js +1 -0
- package/package.json +1 -1
- package/utils/file.d.ts +6 -3
- package/utils/file.js +21 -19
- package/utils/stream.js +1 -1
- package/utils/validator.d.ts +8 -0
- package/utils/validator.js +15 -1
package/models/system/file.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export declare const FileAttr: {
|
|
|
90
90
|
upload: sequelize.TinyIntegerDataType;
|
|
91
91
|
custom: sequelize.AbstractDataTypeConstructor;
|
|
92
92
|
tags: sequelize.AbstractDataTypeConstructor;
|
|
93
|
+
group: sequelize.StringDataType;
|
|
93
94
|
file_link: sequelize.EnumDataType<"no" | "yes">;
|
|
94
95
|
file_id: sequelize.StringDataType;
|
|
95
96
|
uid: sequelize.StringDataType;
|
package/models/system/file.js
CHANGED
|
@@ -95,6 +95,7 @@ exports.FileAttr = {
|
|
|
95
95
|
upload: sequelize.TINYINT({ length: 1 }),
|
|
96
96
|
custom: sequelize.JSON,
|
|
97
97
|
tags: sequelize.JSON,
|
|
98
|
+
group: sequelize.STRING({ length: 20 }),
|
|
98
99
|
file_link: sequelize.ENUM('no', 'yes'),
|
|
99
100
|
file_id: sequelize.STRING({ length: 15 }),
|
|
100
101
|
uid: sequelize.STRING({ length: 100 })
|
package/package.json
CHANGED
package/utils/file.d.ts
CHANGED
|
@@ -124,11 +124,12 @@ export declare class FileUtil {
|
|
|
124
124
|
tags?: TagFile;
|
|
125
125
|
group?: any;
|
|
126
126
|
}): Promise<any>;
|
|
127
|
-
uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, thumb, width, height, input, is_hidden, tags, group }?: {
|
|
127
|
+
uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, format, thumb, width, height, input, is_hidden, tags, group }?: {
|
|
128
128
|
parent_id?: number;
|
|
129
129
|
parent_slug?: string;
|
|
130
130
|
name?: any;
|
|
131
131
|
root?: boolean;
|
|
132
|
+
format?: boolean;
|
|
132
133
|
thumb?: boolean;
|
|
133
134
|
width?: number;
|
|
134
135
|
height?: number;
|
|
@@ -156,7 +157,8 @@ export declare class FileUtil {
|
|
|
156
157
|
group?: any;
|
|
157
158
|
}): Promise<any>;
|
|
158
159
|
allowedFileType(extension: any): Promise<any>;
|
|
159
|
-
formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
|
|
160
|
+
formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { format, use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
|
|
161
|
+
format?: boolean;
|
|
160
162
|
use_id?: boolean;
|
|
161
163
|
field?: any[];
|
|
162
164
|
formatDateTime?: string;
|
|
@@ -182,7 +184,8 @@ export declare class FileUtil {
|
|
|
182
184
|
tags: TagFile;
|
|
183
185
|
group: any;
|
|
184
186
|
}[]>;
|
|
185
|
-
insertFileUnique(results: Array<any>, { thumb, width, height }?: {
|
|
187
|
+
insertFileUnique(results: Array<any>, { format, thumb, width, height }?: {
|
|
188
|
+
format?: boolean;
|
|
186
189
|
thumb?: boolean;
|
|
187
190
|
width?: number;
|
|
188
191
|
height?: number;
|
package/utils/file.js
CHANGED
|
@@ -392,7 +392,7 @@ class FileUtil {
|
|
|
392
392
|
return (yield this.findAllFile({ where: Object.assign({ id }, where), full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
-
uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
395
|
+
uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, format = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
396
396
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
397
397
|
req.files = req.file ? [req.file] : (req.files || []);
|
|
398
398
|
if (req.files.length && slug) {
|
|
@@ -419,7 +419,7 @@ class FileUtil {
|
|
|
419
419
|
}
|
|
420
420
|
let results = yield this.upload(files);
|
|
421
421
|
results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, is_hidden, tags, group });
|
|
422
|
-
return yield this.insertFileUnique(results, { thumb, width, height });
|
|
422
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
423
423
|
}
|
|
424
424
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
425
425
|
});
|
|
@@ -557,7 +557,7 @@ class FileUtil {
|
|
|
557
557
|
return type;
|
|
558
558
|
});
|
|
559
559
|
}
|
|
560
|
-
formatFile(folder_id, user_id, reqs, files, { use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
560
|
+
formatFile(folder_id, user_id, reqs, files, { format = false, use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
561
561
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
562
562
|
try {
|
|
563
563
|
let result = yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -574,7 +574,7 @@ class FileUtil {
|
|
|
574
574
|
path = (index < 0) ? protocol + path : path;
|
|
575
575
|
}
|
|
576
576
|
let extension = mime.extension(reqs[key].mimetype);
|
|
577
|
-
let
|
|
577
|
+
let item = Object.assign(Object.assign({}, input), { folder_id,
|
|
578
578
|
user_id,
|
|
579
579
|
organ_id,
|
|
580
580
|
organ_by,
|
|
@@ -582,22 +582,25 @@ class FileUtil {
|
|
|
582
582
|
date_added, name: reqs[key].originalname || (0, helper_1.getSlug)(32), filename: reqs[key].Key || file.Key || input['filename'], path, mimetype: reqs[key].mimetype, filesize: reqs[key].size, extension: (extension ? "." + extension : ''), type: reqs[key].type || file.type || input['type'], is_hidden,
|
|
583
583
|
tags,
|
|
584
584
|
group });
|
|
585
|
+
if (format) {
|
|
586
|
+
item = yield this.afterQueryFile(item);
|
|
587
|
+
}
|
|
585
588
|
if (use_id) {
|
|
586
|
-
|
|
589
|
+
item['id'] = id;
|
|
587
590
|
}
|
|
588
591
|
if (reqs[key].mimetype && reqs[key].mimetype.split('/')[0] == "image") {
|
|
589
592
|
try {
|
|
590
593
|
let body = reqs[key].Body || reqs[key].buffer;
|
|
591
594
|
let image = yield jimp.read(body);
|
|
592
|
-
|
|
593
|
-
|
|
595
|
+
item['height'] = image.bitmap.height;
|
|
596
|
+
item['width'] = image.bitmap.width;
|
|
594
597
|
}
|
|
595
598
|
catch (err) { }
|
|
596
599
|
}
|
|
597
600
|
if (field.length) {
|
|
598
|
-
|
|
601
|
+
item = _.pick(item, field);
|
|
599
602
|
}
|
|
600
|
-
return
|
|
603
|
+
return item;
|
|
601
604
|
})));
|
|
602
605
|
return result;
|
|
603
606
|
}
|
|
@@ -606,7 +609,7 @@ class FileUtil {
|
|
|
606
609
|
}
|
|
607
610
|
});
|
|
608
611
|
}
|
|
609
|
-
insertFileUnique(results, { thumb = false, width = 0, height = 0 } = {}) {
|
|
612
|
+
insertFileUnique(results, { format = false, thumb = false, width = 0, height = 0 } = {}) {
|
|
610
613
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
611
614
|
try {
|
|
612
615
|
let data = yield file_1.FileModel.schema(this.ref, "_").bulkCreate(results);
|
|
@@ -614,15 +617,14 @@ class FileUtil {
|
|
|
614
617
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
615
618
|
}
|
|
616
619
|
let result = data.map(item => item.toJSON());
|
|
617
|
-
if (thumb) {
|
|
618
|
-
// create thumb
|
|
620
|
+
if (format || thumb) {
|
|
621
|
+
// format or create thumb
|
|
619
622
|
result = yield Promise.all(result.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return Object.assign(Object.assign({}, item), { thumb });
|
|
623
|
+
let include = (yield this.afterQueryFile(item)) || {};
|
|
624
|
+
if (thumb && item['type'] == 'i') {
|
|
625
|
+
include['thumb'] = yield this.findImageThumb(item, { width, height });
|
|
624
626
|
}
|
|
625
|
-
return item;
|
|
627
|
+
return Object.assign(Object.assign({}, item), include);
|
|
626
628
|
})));
|
|
627
629
|
}
|
|
628
630
|
return result;
|
|
@@ -630,7 +632,7 @@ class FileUtil {
|
|
|
630
632
|
catch (err) {
|
|
631
633
|
if (err.errors && err.errors[0].validatorKey == "not_unique") {
|
|
632
634
|
results = results.map(item => (Object.assign(Object.assign({}, item), { id: (0, uuid_1.v4)().replace(/-/gi, '').substring(0, 15) })));
|
|
633
|
-
return yield this.insertFileUnique(results, { thumb, width, height });
|
|
635
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
634
636
|
}
|
|
635
637
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
636
638
|
}
|
|
@@ -639,7 +641,7 @@ class FileUtil {
|
|
|
639
641
|
uploadRawFormat(files, { field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
|
|
640
642
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
641
643
|
let query = yield this.uploadRaw(files);
|
|
642
|
-
return yield this.formatFile(0, 0, files, query, { field });
|
|
644
|
+
return yield this.formatFile(0, 0, files, query, { format: true, field });
|
|
643
645
|
});
|
|
644
646
|
}
|
|
645
647
|
updateFile(id, input = {}, { paths = [] } = {}) {
|
package/utils/stream.js
CHANGED
|
@@ -289,7 +289,7 @@ class StreamUtil {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
if (field['field_type'] == "multiple" || field['field_type'] == "any") {
|
|
292
|
+
if ((field['field_type'] == "multiple" && field_data['self_table'] != "yes") || field['field_type'] == "any") {
|
|
293
293
|
delete attributes[field['field_slug']];
|
|
294
294
|
}
|
|
295
295
|
}
|
package/utils/validator.d.ts
CHANGED
|
@@ -57,5 +57,13 @@ export declare const convertService: ({ convert_type, schema }?: {
|
|
|
57
57
|
convert_type?: any[];
|
|
58
58
|
schema?: {};
|
|
59
59
|
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
60
|
+
export declare const entryValidateService: ({ module, schema }?: {
|
|
61
|
+
module?: string[];
|
|
62
|
+
schema?: {};
|
|
63
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
64
|
+
export declare const entryParamService: ({ module, schema }?: {
|
|
65
|
+
module?: string[];
|
|
66
|
+
schema?: {};
|
|
67
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
60
68
|
export declare const createdByValidate: (req: any, res: any, next: any) => Promise<any>;
|
|
61
69
|
export {};
|
package/utils/validator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createdByValidate = exports.convertService = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
|
|
3
|
+
exports.createdByValidate = exports.entryParamService = exports.entryValidateService = exports.convertService = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Joi = require("joi");
|
|
6
6
|
const errors_1 = require("../errors");
|
|
@@ -291,6 +291,20 @@ const convertService = ({ convert_type = [], schema = {} } = {}) => (req, res, n
|
|
|
291
291
|
return (0, exports.validateService)(Joi.object().keys(Object.assign({ ids: Joi.array().items(Joi.number()).min(1), convert_type: Joi.string().valid(...convert_type) }, schema)).unknown())(req, res, next);
|
|
292
292
|
});
|
|
293
293
|
exports.convertService = convertService;
|
|
294
|
+
const entryValidateService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
|
|
296
|
+
});
|
|
297
|
+
exports.entryValidateService = entryValidateService;
|
|
298
|
+
const entryParamService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
+
if (req.query.module) {
|
|
300
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { module: req.query.module });
|
|
301
|
+
}
|
|
302
|
+
if (req.query.entry_id) {
|
|
303
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { entry_id: req.query.entry_id });
|
|
304
|
+
}
|
|
305
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
|
|
306
|
+
});
|
|
307
|
+
exports.entryParamService = entryParamService;
|
|
294
308
|
exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
|
|
295
309
|
created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
|
|
296
310
|
}).unknown());
|