ultra-image-uploader 1.0.0 → 2.0.1
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/README.md +204 -333
- package/dist/components/ImageUploader.d.ts +3 -50
- package/dist/components/ImageUploader.d.ts.map +1 -1
- package/dist/components/ImageUploader.js +86 -143
- package/dist/components/ImageUploader.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/providers/index.d.ts +23 -17
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +119 -27
- package/dist/providers/index.js.map +1 -1
- package/dist/types/index.d.ts +25 -32
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +14 -8
- package/dist/providers/BaseProvider.d.ts +0 -19
- package/dist/providers/BaseProvider.d.ts.map +0 -1
- package/dist/providers/BaseProvider.js +0 -48
- package/dist/providers/BaseProvider.js.map +0 -1
- package/dist/providers/CloudinaryProvider.d.ts +0 -17
- package/dist/providers/CloudinaryProvider.d.ts.map +0 -1
- package/dist/providers/CloudinaryProvider.js +0 -123
- package/dist/providers/CloudinaryProvider.js.map +0 -1
- package/dist/providers/ImgBBProvider.d.ts +0 -13
- package/dist/providers/ImgBBProvider.d.ts.map +0 -1
- package/dist/providers/ImgBBProvider.js +0 -68
- package/dist/providers/ImgBBProvider.js.map +0 -1
- package/dist/utils/imageUpload.d.ts +0 -11
- package/dist/utils/imageUpload.d.ts.map +0 -1
- package/dist/utils/imageUpload.js +0 -32
- package/dist/utils/imageUpload.js.map +0 -1
- package/dist/utils/upload.d.ts +0 -49
- package/dist/utils/upload.d.ts.map +0 -1
- package/dist/utils/upload.js +0 -62
- package/dist/utils/upload.js.map +0 -1
package/dist/providers/index.js
CHANGED
|
@@ -1,36 +1,128 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
* Upload providers - ImgBB and Cloudinary
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Upload to ImgBB
|
|
6
|
+
*/
|
|
7
|
+
async function uploadToImgBB(file, config, options) {
|
|
8
|
+
const formData = new FormData();
|
|
9
|
+
formData.append('image', file);
|
|
10
|
+
const response = await fetchWithProgress(`https://api.imgbb.com/1/upload?key=${config.apiKey}`, formData, options?.onProgress);
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
if (!data.success || !data.data?.url) {
|
|
13
|
+
throw new Error(data.error?.message || 'ImgBB upload failed');
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return {
|
|
16
|
+
url: data.data.url,
|
|
17
|
+
provider: 'imgbb',
|
|
18
|
+
originalFile: file,
|
|
19
|
+
metadata: {
|
|
20
|
+
deleteUrl: data.data.delete_url,
|
|
21
|
+
size: data.data.size,
|
|
22
|
+
width: data.data.width,
|
|
23
|
+
height: data.data.height,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Upload to Cloudinary
|
|
29
|
+
*/
|
|
30
|
+
async function uploadToCloudinary(file, config, options) {
|
|
31
|
+
if (!config.cloudName) {
|
|
32
|
+
throw new Error('Cloudinary cloudName is required');
|
|
17
33
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
const formData = new FormData();
|
|
35
|
+
formData.append('file', file);
|
|
36
|
+
formData.append('upload_preset', config.uploadPreset || 'unsigned_preset');
|
|
37
|
+
if (options?.transformOptions) {
|
|
38
|
+
const transforms = [];
|
|
39
|
+
if (options.transformOptions.width)
|
|
40
|
+
transforms.push(`w_${options.transformOptions.width}`);
|
|
41
|
+
if (options.transformOptions.height)
|
|
42
|
+
transforms.push(`h_${options.transformOptions.height}`);
|
|
43
|
+
if (options.transformOptions.crop)
|
|
44
|
+
transforms.push(`c_${options.transformOptions.crop}`);
|
|
45
|
+
if (options.transformOptions.quality)
|
|
46
|
+
transforms.push(`q_${options.transformOptions.quality}`);
|
|
47
|
+
if (transforms.length > 0) {
|
|
48
|
+
formData.append('transformation', transforms.join(','));
|
|
22
49
|
}
|
|
23
|
-
return provider;
|
|
24
50
|
}
|
|
25
|
-
|
|
26
|
-
|
|
51
|
+
const response = await fetchWithProgress(`https://api.cloudinary.com/v1_1/${config.cloudName}/image/upload`, formData, options?.onProgress);
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
if (!data.secure_url) {
|
|
54
|
+
throw new Error(data.error?.message || 'Cloudinary upload failed');
|
|
27
55
|
}
|
|
28
|
-
|
|
29
|
-
|
|
56
|
+
return {
|
|
57
|
+
url: data.secure_url,
|
|
58
|
+
provider: 'cloudinary',
|
|
59
|
+
originalFile: file,
|
|
60
|
+
metadata: {
|
|
61
|
+
publicId: data.public_id,
|
|
62
|
+
width: data.width,
|
|
63
|
+
height: data.height,
|
|
64
|
+
format: data.format,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Fetch with progress tracking
|
|
70
|
+
*/
|
|
71
|
+
function fetchWithProgress(url, formData, onProgress) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const xhr = new XMLHttpRequest();
|
|
74
|
+
if (onProgress) {
|
|
75
|
+
xhr.upload.addEventListener('progress', (e) => {
|
|
76
|
+
if (e.lengthComputable) {
|
|
77
|
+
onProgress({
|
|
78
|
+
loaded: e.loaded,
|
|
79
|
+
total: e.total,
|
|
80
|
+
percentage: Math.round((e.loaded / e.total) * 100),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
xhr.onload = () => {
|
|
86
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
87
|
+
resolve(new Response(xhr.responseText, { status: xhr.status }));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
reject(new Error(`HTTP ${xhr.status}`));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
xhr.onerror = () => reject(new Error('Network error'));
|
|
94
|
+
xhr.ontimeout = () => reject(new Error('Request timeout'));
|
|
95
|
+
xhr.open('POST', url);
|
|
96
|
+
xhr.timeout = 60000;
|
|
97
|
+
xhr.send(formData);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Upload a single image
|
|
102
|
+
*/
|
|
103
|
+
export async function uploadImage(file, provider, config, options) {
|
|
104
|
+
if (provider === 'imgbb') {
|
|
105
|
+
return uploadToImgBB(file, config, options);
|
|
30
106
|
}
|
|
107
|
+
return uploadToCloudinary(file, config, options);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Upload multiple images
|
|
111
|
+
*/
|
|
112
|
+
export async function uploadImages(files, provider, config, options) {
|
|
113
|
+
return Promise.all(files.map((file) => uploadImage(file, provider, config, options)));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Upload to ImgBB (convenience function)
|
|
117
|
+
*/
|
|
118
|
+
export async function uploadImagesToImageBB(images, apiKey) {
|
|
119
|
+
const results = await uploadImages(images, 'imgbb', { apiKey });
|
|
120
|
+
return { urls: results.map((r) => r.url) };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Upload to Cloudinary (convenience function)
|
|
124
|
+
*/
|
|
125
|
+
export async function uploadImagesToCloudinary(files, config, options) {
|
|
126
|
+
return uploadImages(files, 'cloudinary', config, options);
|
|
31
127
|
}
|
|
32
|
-
// Singleton instance
|
|
33
|
-
const registry = new ProviderRegistry();
|
|
34
|
-
export { registry as providerRegistry, ProviderRegistry };
|
|
35
|
-
export { ImgBBProvider, CloudinaryProvider };
|
|
36
128
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,IAAU,EACV,MAAsB,EACtB,OAAuB;IAEvB,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAE/B,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CACtC,sCAAsC,MAAM,CAAC,MAAM,EAAE,EACrD,QAAQ,EACR,OAAO,EAAE,UAAU,CACpB,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,qBAAqB,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;QAClB,QAAQ,EAAE,OAAO;QACjB,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE;YACR,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU;YAC/B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;YACpB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACtB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;SACzB;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAC/B,IAAU,EACV,MAAsB,EACtB,OAAuB;IAEvB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAA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ACzC,MAAc,EACd,MAAc;IAEd,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAChE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,KAAa,EACb,MAAoD,EACpD,OAAuB;IAEvB,OAAO,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core types
|
|
2
|
+
* Core types for Ultra Image Uploader
|
|
3
3
|
*/
|
|
4
4
|
export type UploadProvider = 'imgbb' | 'cloudinary';
|
|
5
|
-
export interface UploadProgress {
|
|
6
|
-
loaded: number;
|
|
7
|
-
total: number;
|
|
8
|
-
percentage: number;
|
|
9
|
-
}
|
|
10
|
-
export type ProgressCallback = (progress: UploadProgress) => void;
|
|
11
5
|
export interface UploadResult {
|
|
12
6
|
url: string;
|
|
13
7
|
provider: UploadProvider;
|
|
14
8
|
originalFile: File;
|
|
15
9
|
metadata?: Record<string, unknown>;
|
|
16
10
|
}
|
|
11
|
+
export interface UploadProgress {
|
|
12
|
+
loaded: number;
|
|
13
|
+
total: number;
|
|
14
|
+
percentage: number;
|
|
15
|
+
}
|
|
17
16
|
export interface UploadOptions {
|
|
18
|
-
onProgress?:
|
|
17
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
19
18
|
transformOptions?: ImageTransformOptions;
|
|
20
19
|
}
|
|
21
20
|
export interface ImageTransformOptions {
|
|
@@ -26,15 +25,18 @@ export interface ImageTransformOptions {
|
|
|
26
25
|
format?: string;
|
|
27
26
|
}
|
|
28
27
|
export interface ProviderConfig {
|
|
29
|
-
apiKey
|
|
30
|
-
uploadPreset?: string;
|
|
28
|
+
apiKey?: string;
|
|
31
29
|
cloudName?: string;
|
|
30
|
+
uploadPreset?: string;
|
|
32
31
|
baseUrl?: string;
|
|
33
32
|
}
|
|
34
|
-
export interface
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export interface FileValidationOptions {
|
|
34
|
+
maxSize?: number;
|
|
35
|
+
minWidth?: number;
|
|
36
|
+
maxWidth?: number;
|
|
37
|
+
minHeight?: number;
|
|
38
|
+
maxHeight?: number;
|
|
39
|
+
allowedTypes?: string[];
|
|
38
40
|
}
|
|
39
41
|
export interface ValidationError {
|
|
40
42
|
code: string;
|
|
@@ -45,23 +47,14 @@ export interface ValidationResult {
|
|
|
45
47
|
valid: boolean;
|
|
46
48
|
errors?: ValidationError[];
|
|
47
49
|
}
|
|
48
|
-
export interface
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
name: UploadProvider;
|
|
58
|
-
upload(file: File, config: ProviderConfig, options?: UploadOptions): Promise<UploadResult>;
|
|
59
|
-
uploadMultiple(files: File[], config: ProviderConfig, options?: UploadOptions): Promise<UploadResult[]>;
|
|
60
|
-
validate(file: File, validationOptions?: FileValidationOptions): ValidationResult | Promise<ValidationResult>;
|
|
61
|
-
}
|
|
62
|
-
export interface UploadError extends Error {
|
|
63
|
-
code: string;
|
|
64
|
-
provider: UploadProvider;
|
|
65
|
-
details?: unknown;
|
|
50
|
+
export interface ThemeConfig {
|
|
51
|
+
primary?: string;
|
|
52
|
+
background?: string;
|
|
53
|
+
border?: string;
|
|
54
|
+
text?: string;
|
|
55
|
+
textSecondary?: string;
|
|
56
|
+
error?: string;
|
|
57
|
+
success?: string;
|
|
58
|
+
radius?: string;
|
|
66
59
|
}
|
|
67
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,YAAY,CAAC;AAEpD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,YAAY,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,cAAc,CAAC;IACzB,YAAY,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ultra-image-uploader",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A modern,
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "A modern, beautiful React image upload component with ImgBB & Cloudinary support",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
8
16
|
"files": [
|
|
9
17
|
"dist",
|
|
10
18
|
"README.md",
|
|
@@ -29,11 +37,9 @@
|
|
|
29
37
|
"react-component",
|
|
30
38
|
"image-uploader",
|
|
31
39
|
"multiple-upload",
|
|
32
|
-
"cloudinary-upload",
|
|
33
|
-
"imgbb-upload",
|
|
34
40
|
"progress-tracking",
|
|
35
41
|
"file-validation",
|
|
36
|
-
"
|
|
42
|
+
"auto-imports"
|
|
37
43
|
],
|
|
38
44
|
"author": "Digontha Das",
|
|
39
45
|
"license": "MIT",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base provider class for image uploads
|
|
3
|
-
*/
|
|
4
|
-
import type { ImageProvider, UploadResult, ProviderConfig, UploadOptions, FileValidationOptions, ValidationResult, UploadProvider } from '../types';
|
|
5
|
-
export declare abstract class BaseImageProvider implements ImageProvider {
|
|
6
|
-
abstract name: UploadProvider;
|
|
7
|
-
abstract upload(file: File, config: ProviderConfig, options?: UploadOptions): Promise<UploadResult>;
|
|
8
|
-
abstract uploadMultiple(files: File[], config: ProviderConfig, options?: UploadOptions): Promise<UploadResult[]>;
|
|
9
|
-
validate(file: File, validationOptions?: FileValidationOptions): Promise<ValidationResult>;
|
|
10
|
-
protected createUploadError(code: string, message: string, details?: unknown): Error;
|
|
11
|
-
protected readFileAsDataURL(file: File): Promise<string>;
|
|
12
|
-
protected createFormData(file: File, additionalData?: Record<string, string>): FormData;
|
|
13
|
-
protected trackProgress(xhr: XMLHttpRequest, onProgress?: (progress: {
|
|
14
|
-
loaded: number;
|
|
15
|
-
total: number;
|
|
16
|
-
percentage: number;
|
|
17
|
-
}) => void): void;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=BaseProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProvider.d.ts","sourceRoot":"","sources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-
* Base provider class for image uploads
|
|
3
|
-
*/
|
|
4
|
-
import { validateFileComplete } from '../utils/validation';
|
|
5
|
-
export class BaseImageProvider {
|
|
6
|
-
async validate(file, validationOptions) {
|
|
7
|
-
return validateFileComplete(file, validationOptions);
|
|
8
|
-
}
|
|
9
|
-
createUploadError(code, message, details) {
|
|
10
|
-
const error = new Error(message);
|
|
11
|
-
error.code = code;
|
|
12
|
-
error.provider = this.name;
|
|
13
|
-
error.details = details;
|
|
14
|
-
return error;
|
|
15
|
-
}
|
|
16
|
-
async readFileAsDataURL(file) {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const reader = new FileReader();
|
|
19
|
-
reader.onload = () => resolve(reader.result);
|
|
20
|
-
reader.onerror = () => reject(new Error('Failed to read file'));
|
|
21
|
-
reader.readAsDataURL(file);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
createFormData(file, additionalData) {
|
|
25
|
-
const formData = new FormData();
|
|
26
|
-
formData.append('image', file);
|
|
27
|
-
if (additionalData) {
|
|
28
|
-
Object.entries(additionalData).forEach(([key, value]) => {
|
|
29
|
-
formData.append(key, value);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return formData;
|
|
33
|
-
}
|
|
34
|
-
trackProgress(xhr, onProgress) {
|
|
35
|
-
if (!onProgress)
|
|
36
|
-
return;
|
|
37
|
-
xhr.upload.addEventListener('progress', (event) => {
|
|
38
|
-
if (event.lengthComputable) {
|
|
39
|
-
onProgress({
|
|
40
|
-
loaded: event.loaded,
|
|
41
|
-
total: event.total,
|
|
42
|
-
percentage: Math.round((event.loaded / event.total) * 100),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=BaseProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProvider.js","sourceRoot":"","sources":["../../src/providers/BaseProvider.ts"],"names":[],"mappings":"A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tD,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAES,aAAa,CACrB,GAAmB,EACnB,UAAsF;QAEtF,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;YAChD,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;gBAC3B,UAAU,CAAC;oBACT,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;iBAC3D,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cloudinary image upload provider
|
|
3
|
-
*/
|
|
4
|
-
import type { UploadResult, ProviderConfig, UploadOptions, ImageTransformOptions } from '../types';
|
|
5
|
-
import { BaseImageProvider } from './BaseProvider';
|
|
6
|
-
export declare class CloudinaryProvider extends BaseImageProvider {
|
|
7
|
-
name: "cloudinary";
|
|
8
|
-
upload(file: File, config: ProviderConfig, options?: UploadOptions): Promise<UploadResult>;
|
|
9
|
-
uploadMultiple(files: File[], config: ProviderConfig, options?: UploadOptions): Promise<UploadResult[]>;
|
|
10
|
-
private addTransformOptions;
|
|
11
|
-
private uploadWithProgress;
|
|
12
|
-
/**
|
|
13
|
-
* Generate a transformed URL for an already uploaded Cloudinary image
|
|
14
|
-
*/
|
|
15
|
-
static generateTransformedUrl(urlOrPublicId: string, transformations: ImageTransformOptions): string;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=CloudinaryProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CloudinaryProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CloudinaryProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAyBnD,qBAAa,kBAAmB,SAAQ,iBAAiB;IACvD,IAAI,EAAG,YAAY,CAAU;IAEvB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAyD1F,cAAc,CAClB,KAAK,EAAE,IAAI,EAAE,EACb,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC;IAK1B,OAAO,CAAC,mBAAmB;YAwBb,kBAAkB;IA4BhC;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAC3B,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,qBAAqB,GACrC,MAAM;CAwBV"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cloudinary image upload provider
|
|
3
|
-
*/
|
|
4
|
-
import { BaseImageProvider } from './BaseProvider';
|
|
5
|
-
export class CloudinaryProvider extends BaseImageProvider {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.name = 'cloudinary';
|
|
9
|
-
}
|
|
10
|
-
async upload(file, config, options) {
|
|
11
|
-
if (!config.cloudName) {
|
|
12
|
-
throw this.createUploadError('MISSING_CONFIG', 'Cloudinary cloud name is required');
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
const formData = this.createFormData(file);
|
|
16
|
-
formData.append('upload_preset', config.uploadPreset || 'unsigned_preset');
|
|
17
|
-
// Add transformation options if provided
|
|
18
|
-
if (options?.transformOptions) {
|
|
19
|
-
this.addTransformOptions(formData, options.transformOptions);
|
|
20
|
-
}
|
|
21
|
-
const response = await this.uploadWithProgress(formData, config, options?.onProgress);
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
if (!data.secure_url) {
|
|
24
|
-
throw this.createUploadError('UPLOAD_FAILED', data.error?.message || 'Image upload failed', data.error);
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
url: data.secure_url,
|
|
28
|
-
provider: this.name,
|
|
29
|
-
originalFile: file,
|
|
30
|
-
metadata: {
|
|
31
|
-
publicId: data.public_id,
|
|
32
|
-
version: data.version,
|
|
33
|
-
width: data.width,
|
|
34
|
-
height: data.height,
|
|
35
|
-
format: data.format,
|
|
36
|
-
bytes: data.bytes,
|
|
37
|
-
resourceType: data.resource_type,
|
|
38
|
-
createdAt: data.created_at,
|
|
39
|
-
originalFilename: data.original_filename,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
if (error instanceof Error) {
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
throw this.createUploadError('UNKNOWN_ERROR', 'An unknown error occurred', error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async uploadMultiple(files, config, options) {
|
|
51
|
-
const uploadPromises = files.map((file) => this.upload(file, config, options));
|
|
52
|
-
return Promise.all(uploadPromises);
|
|
53
|
-
}
|
|
54
|
-
addTransformOptions(formData, options) {
|
|
55
|
-
const transformationParts = [];
|
|
56
|
-
if (options.width) {
|
|
57
|
-
transformationParts.push(`w_${options.width}`);
|
|
58
|
-
}
|
|
59
|
-
if (options.height) {
|
|
60
|
-
transformationParts.push(`h_${options.height}`);
|
|
61
|
-
}
|
|
62
|
-
if (options.crop) {
|
|
63
|
-
transformationParts.push(`c_${options.crop}`);
|
|
64
|
-
}
|
|
65
|
-
if (options.quality) {
|
|
66
|
-
transformationParts.push(`q_${options.quality}`);
|
|
67
|
-
}
|
|
68
|
-
if (options.format) {
|
|
69
|
-
transformationParts.push(`f_${options.format}`);
|
|
70
|
-
}
|
|
71
|
-
if (transformationParts.length > 0) {
|
|
72
|
-
formData.append('transformation', transformationParts.join(','));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async uploadWithProgress(formData, config, onProgress) {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const xhr = new XMLHttpRequest();
|
|
78
|
-
const uploadUrl = `https://api.cloudinary.com/v1_1/${config.cloudName}/image/upload`;
|
|
79
|
-
this.trackProgress(xhr, onProgress);
|
|
80
|
-
xhr.onload = () => {
|
|
81
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
82
|
-
resolve(new Response(xhr.responseText, { status: xhr.status }));
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
reject(new Error(`HTTP error! status: ${xhr.status}`));
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
xhr.onerror = () => reject(new Error('Network error occurred'));
|
|
89
|
-
xhr.ontimeout = () => reject(new Error('Request timeout'));
|
|
90
|
-
xhr.open('POST', uploadUrl);
|
|
91
|
-
xhr.timeout = 60000; // 60 seconds timeout
|
|
92
|
-
xhr.send(formData);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Generate a transformed URL for an already uploaded Cloudinary image
|
|
97
|
-
*/
|
|
98
|
-
static generateTransformedUrl(urlOrPublicId, transformations) {
|
|
99
|
-
const transformationParts = [];
|
|
100
|
-
if (transformations.width)
|
|
101
|
-
transformationParts.push(`w_${transformations.width}`);
|
|
102
|
-
if (transformations.height)
|
|
103
|
-
transformationParts.push(`h_${transformations.height}`);
|
|
104
|
-
if (transformations.crop)
|
|
105
|
-
transformationParts.push(`c_${transformations.crop}`);
|
|
106
|
-
if (transformations.quality)
|
|
107
|
-
transformationParts.push(`q_${transformations.quality}`);
|
|
108
|
-
if (transformations.format)
|
|
109
|
-
transformationParts.push(`f_${transformations.format}`);
|
|
110
|
-
const transformationString = transformationParts.join(',');
|
|
111
|
-
// If it's already a full URL, extract the public ID and rebuild
|
|
112
|
-
if (urlOrPublicId.startsWith('http')) {
|
|
113
|
-
const url = new URL(urlOrPublicId);
|
|
114
|
-
const pathParts = url.pathname.split('/');
|
|
115
|
-
const versionIndex = pathParts.findIndex((part) => part.startsWith('v'));
|
|
116
|
-
const publicId = pathParts.slice(versionIndex + 1).join('/');
|
|
117
|
-
return `${url.origin}/image/upload/${transformationString}/${publicId}`;
|
|
118
|
-
}
|
|
119
|
-
// If it's just a public ID, construct the URL
|
|
120
|
-
return `https://res.cloudinary.com/image/upload/${transformationString}/${urlOrPublicId}`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=CloudinaryProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CloudinaryProvider.js","sourceRoot":"","sources":["../../src/providers/CloudinaryProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAyBnD,MAAM,OAAO,kBAAmB,SAAQ,iBAAiB;IAAzD;;QACE,SAAI,GAAG,YAAqB,CAAC;IAsJ/B,CAAC;IApJC,KAAK,CAAC,MAAM,CAAC,IAAU,EAAE,MAAsB,EAAE,OAAuB;QACtE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,iBAAiB,CAC1B,gBAAgB,EAChB,mCAAmC,CACpC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC3C,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,YAAY,IAAI,iBAAiB,CAAC,CAAC;YAE3E,yCAAyC;YACzC,IAAI,OAAO,EAAE,gBAAgB,EAAE,C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UploadOptions } from '../types';
|
|
5
|
-
import { BaseImageProvider } from './BaseProvider';
|
|
6
|
-
export declare class ImgBBProvider extends BaseImageProvider {
|
|
7
|
-
name: "imgbb";
|
|
8
|
-
private readonly baseUrl;
|
|
9
|
-
upload(file: File, config: ProviderConfig, options?: UploadOptions): Promise<UploadResult>;
|
|
10
|
-
uploadMultiple(files: File[], config: ProviderConfig, options?: UploadOptions): Promise<UploadResult[]>;
|
|
11
|
-
private uploadWithProgress;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=ImgBBProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImgBBProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ImgBBProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAmBnD,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,IAAI,EAAG,OAAO,CAAU;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAEtD,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IA8C1F,cAAc,CAClB,KAAK,EAAE,IAAI,EAAE,EACb,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC;YAKZ,kBAAkB;CA0BjC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImgBB image upload provider
|
|
3
|
-
*/
|
|
4
|
-
import { BaseImageProvider } from './BaseProvider';
|
|
5
|
-
export class ImgBBProvider extends BaseImageProvider {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.name = 'imgbb';
|
|
9
|
-
this.baseUrl = 'https://api.imgbb.com/1/upload';
|
|
10
|
-
}
|
|
11
|
-
async upload(file, config, options) {
|
|
12
|
-
try {
|
|
13
|
-
const formData = this.createFormData(file);
|
|
14
|
-
// Add expiration if needed (24 hours by default, can be customized)
|
|
15
|
-
if (!formData.has('expiration')) {
|
|
16
|
-
formData.append('expiration', ''); // No expiration by default
|
|
17
|
-
}
|
|
18
|
-
const response = await this.uploadWithProgress(formData, config, options?.onProgress);
|
|
19
|
-
const data = await response.json();
|
|
20
|
-
if (!data.success || !data.data?.url) {
|
|
21
|
-
throw this.createUploadError('UPLOAD_FAILED', data.error?.message || 'Image upload failed', data.error);
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
url: data.data.url,
|
|
25
|
-
provider: this.name,
|
|
26
|
-
originalFile: file,
|
|
27
|
-
metadata: {
|
|
28
|
-
deleteUrl: data.data.delete_url,
|
|
29
|
-
displayUrl: data.data.display_url,
|
|
30
|
-
size: data.data.size,
|
|
31
|
-
width: data.data.width,
|
|
32
|
-
height: data.data.height,
|
|
33
|
-
expiration: data.data.expiration,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if (error instanceof Error) {
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
throw this.createUploadError('UNKNOWN_ERROR', 'An unknown error occurred', error);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async uploadMultiple(files, config, options) {
|
|
45
|
-
const uploadPromises = files.map((file) => this.upload(file, config, options));
|
|
46
|
-
return Promise.all(uploadPromises);
|
|
47
|
-
}
|
|
48
|
-
async uploadWithProgress(formData, config, onProgress) {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const xhr = new XMLHttpRequest();
|
|
51
|
-
this.trackProgress(xhr, onProgress);
|
|
52
|
-
xhr.onload = () => {
|
|
53
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
54
|
-
resolve(new Response(xhr.responseText, { status: xhr.status }));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
reject(new Error(`HTTP error! status: ${xhr.status}`));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
xhr.onerror = () => reject(new Error('Network error occurred'));
|
|
61
|
-
xhr.ontimeout = () => reject(new Error('Request timeout'));
|
|
62
|
-
xhr.open('POST', `${this.baseUrl}?key=${config.apiKey}`);
|
|
63
|
-
xhr.timeout = 60000; // 60 seconds timeout
|
|
64
|
-
xhr.send(formData);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=ImgBBProvider.js.map
|