@streamscloud/kit 0.82.4 → 0.83.0
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.
|
@@ -5,8 +5,8 @@ export declare class FileValidationLocalization {
|
|
|
5
5
|
get audioOnly(): string;
|
|
6
6
|
get maxSize(): (size: string) => string;
|
|
7
7
|
get extensions(): (list: string) => string;
|
|
8
|
-
get maxDimensions(): (
|
|
9
|
-
get minDimensions(): (
|
|
8
|
+
get maxDimensions(): (longSide: number, shortSide: number) => string;
|
|
9
|
+
get minDimensions(): (longSide: number, shortSide: number) => string;
|
|
10
10
|
get maxDuration(): (seconds: number) => string;
|
|
11
11
|
get aspectRatio(): (ratios: string) => string;
|
|
12
12
|
get aspectRatioRange(): (min: string, max: string) => string;
|
|
@@ -63,12 +63,12 @@ const loc = {
|
|
|
63
63
|
no: (list) => `Tillatte filtyper: ${list}`
|
|
64
64
|
},
|
|
65
65
|
maxDimensions: {
|
|
66
|
-
en: (
|
|
67
|
-
no: (
|
|
66
|
+
en: (longSide, shortSide) => `Maximum dimensions: ${longSide}×${shortSide}px, either orientation`,
|
|
67
|
+
no: (longSide, shortSide) => `Maks oppløsning: ${longSide}×${shortSide}px, liggende eller stående`
|
|
68
68
|
},
|
|
69
69
|
minDimensions: {
|
|
70
|
-
en: (
|
|
71
|
-
no: (
|
|
70
|
+
en: (longSide, shortSide) => `Minimum dimensions: ${longSide}×${shortSide}px, either orientation`,
|
|
71
|
+
no: (longSide, shortSide) => `Min oppløsning: ${longSide}×${shortSide}px, liggende eller stående`
|
|
72
72
|
},
|
|
73
73
|
maxDuration: {
|
|
74
74
|
en: (seconds) => `Maximum duration: ${seconds}s`,
|
|
@@ -21,13 +21,13 @@ export declare const FileRules: {
|
|
|
21
21
|
AudioDuration: (maxSeconds: number, message?: string) => FileValidationRule;
|
|
22
22
|
AudioOnly: (message?: string) => FileValidationRule;
|
|
23
23
|
Extensions: (extensions: string[], message?: string) => FileValidationRule;
|
|
24
|
-
ImageDimensions: (
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
ImageDimensions: (limits: {
|
|
25
|
+
max1: number;
|
|
26
|
+
max2: number;
|
|
27
27
|
}, message?: string) => FileValidationRule;
|
|
28
|
-
ImageMinDimensions: (
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
ImageMinDimensions: (limits: {
|
|
29
|
+
min1: number;
|
|
30
|
+
min2: number;
|
|
31
31
|
}, message?: string) => FileValidationRule;
|
|
32
32
|
MaxSize: (bytes: number, message?: string) => FileValidationRule;
|
|
33
33
|
Mime: (accept: string, message?: string) => FileValidationRule;
|
|
@@ -43,9 +43,9 @@ export declare const FileRules: {
|
|
|
43
43
|
max?: AspectRatioBound;
|
|
44
44
|
}, message?: string, tolerancePercent?: number) => FileValidationRule;
|
|
45
45
|
VideoOrientation: (orientation: VideoOrientationValue, message?: string, tolerancePercent?: number) => FileValidationRule;
|
|
46
|
-
VideoDimensions: (
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
VideoDimensions: (limits: {
|
|
47
|
+
max1: number;
|
|
48
|
+
max2: number;
|
|
49
49
|
}, message?: string) => FileValidationRule;
|
|
50
50
|
VideoDuration: (maxSeconds: number, message?: string) => FileValidationRule;
|
|
51
51
|
};
|
|
@@ -55,6 +55,16 @@ const resolveBound = (value) => {
|
|
|
55
55
|
return Number.isFinite(ratio) ? ratio : null;
|
|
56
56
|
};
|
|
57
57
|
const formatBound = (value) => (value === undefined ? '' : typeof value === 'number' ? String(value) : value);
|
|
58
|
+
const toSides = (a, b) => ({ long: Math.max(a, b), short: Math.min(a, b) });
|
|
59
|
+
const exceedsMax = (size, limits) => {
|
|
60
|
+
const actual = toSides(size.width, size.height);
|
|
61
|
+
const limit = toSides(limits.max1, limits.max2);
|
|
62
|
+
return actual.long > limit.long || actual.short > limit.short;
|
|
63
|
+
};
|
|
64
|
+
const maxDimensionsMessage = (limits) => {
|
|
65
|
+
const limit = toSides(limits.max1, limits.max2);
|
|
66
|
+
return messages.maxDimensions(limit.long, limit.short);
|
|
67
|
+
};
|
|
58
68
|
const formatExtensions = (extensions) => extensions.map((ext) => '.' + ext.replace(/^\./, '')).join(', ');
|
|
59
69
|
const messages = new FileValidationLocalization();
|
|
60
70
|
/**
|
|
@@ -96,13 +106,15 @@ export const FileRules = {
|
|
|
96
106
|
const allowed = extensions.map((ext) => ext.replace(/^\./, '').toLowerCase());
|
|
97
107
|
return allowed.includes(extension) ? null : (message ?? messages.extensions(formatExtensions(extensions)));
|
|
98
108
|
},
|
|
99
|
-
ImageDimensions: (
|
|
100
|
-
const
|
|
101
|
-
return
|
|
109
|
+
ImageDimensions: (limits, message) => async (file) => {
|
|
110
|
+
const size = await readImageDimensions(file);
|
|
111
|
+
return exceedsMax(size, limits) ? (message ?? maxDimensionsMessage(limits)) : null;
|
|
102
112
|
},
|
|
103
|
-
ImageMinDimensions: (
|
|
113
|
+
ImageMinDimensions: (limits, message) => async (file) => {
|
|
104
114
|
const { width, height } = await readImageDimensions(file);
|
|
105
|
-
|
|
115
|
+
const actual = toSides(width, height);
|
|
116
|
+
const limit = toSides(limits.min1, limits.min2);
|
|
117
|
+
return actual.long < limit.long || actual.short < limit.short ? (message ?? messages.minDimensions(limit.long, limit.short)) : null;
|
|
106
118
|
},
|
|
107
119
|
MaxSize: (bytes, message) => (file) => file.size > bytes ? (message ?? messages.maxSize(StringHelper.toFileSizeString(bytes))) : null,
|
|
108
120
|
Mime: (accept, message) => {
|
|
@@ -151,9 +163,9 @@ export const FileRules = {
|
|
|
151
163
|
const ok = orientation === 'landscape' ? actual > 1 + margin : orientation === 'portrait' ? actual < 1 - margin : Math.abs(actual - 1) <= margin;
|
|
152
164
|
return ok ? null : (message ?? messages.orientation(orientation));
|
|
153
165
|
},
|
|
154
|
-
VideoDimensions: (
|
|
155
|
-
const
|
|
156
|
-
return
|
|
166
|
+
VideoDimensions: (limits, message) => async (file) => {
|
|
167
|
+
const size = await readMedia(file);
|
|
168
|
+
return exceedsMax(size, limits) ? (message ?? maxDimensionsMessage(limits)) : null;
|
|
157
169
|
},
|
|
158
170
|
VideoDuration: (maxSeconds, message) => async (file) => {
|
|
159
171
|
const durationSec = await readDuration(file);
|