@sqrzro/server 2.0.0-bz.4 → 2.0.0-bz.5
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/dist/ImageService.d.ts +7 -0
- package/dist/ImageService.js +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.validateImage = void 0;
|
|
5
|
+
const DEFAULT_TYPES = ['image/png', 'image/jpeg', 'image/jpg'];
|
|
6
|
+
// 5MB
|
|
7
|
+
const DEFAULT_MAX_SIZE = 5242880;
|
|
8
|
+
async function validateImage(image, config) {
|
|
9
|
+
if (!image) {
|
|
10
|
+
return Promise.resolve([null, { image: 'IMAGE_UNDEFINED' }]);
|
|
11
|
+
}
|
|
12
|
+
if (!(image instanceof File)) {
|
|
13
|
+
return Promise.resolve([null, { image: 'IMAGE_NOT_VALID' }]);
|
|
14
|
+
}
|
|
15
|
+
if (!(config?.types || DEFAULT_TYPES).includes(image.type)) {
|
|
16
|
+
return Promise.resolve([null, { image: 'IMAGE_TYPE_NOT_VALID' }]);
|
|
17
|
+
}
|
|
18
|
+
if (image.size > (config?.maxSize || DEFAULT_MAX_SIZE)) {
|
|
19
|
+
return Promise.resolve([null, { image: 'IMAGE_TOO_HEAVY' }]);
|
|
20
|
+
}
|
|
21
|
+
return Promise.resolve([image, null]);
|
|
22
|
+
}
|
|
23
|
+
exports.validateImage = validateImage;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './LoginRequest';
|
|
|
2
2
|
export * from './AuthService';
|
|
3
3
|
export * from './PasswordService';
|
|
4
4
|
export * from './DataService';
|
|
5
|
+
export * from './ImageService';
|
|
5
6
|
export * from './RequestService';
|
|
6
7
|
export * from './SessionService';
|
|
7
8
|
export * from './interfaces';
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./LoginRequest"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./AuthService"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./PasswordService"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./DataService"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./ImageService"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./RequestService"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./SessionService"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./interfaces"), exports);
|