@dyrected/storage-cloudinary 0.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 +3 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StorageAdapter, FileData } from '@dyrected/core';
|
|
2
|
+
export interface CloudinaryStorageConfig {
|
|
3
|
+
cloudName: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
apiSecret: string;
|
|
6
|
+
folder?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CloudinaryStorageAdapter implements StorageAdapter {
|
|
9
|
+
private config;
|
|
10
|
+
constructor(config: CloudinaryStorageConfig);
|
|
11
|
+
upload(args: {
|
|
12
|
+
filename: string;
|
|
13
|
+
buffer: Buffer;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
}): Promise<FileData>;
|
|
16
|
+
delete(args: {
|
|
17
|
+
filename: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
getURL(args: {
|
|
20
|
+
filename: string;
|
|
21
|
+
}): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1D,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,wBAAyB,YAAW,cAAc;IACjD,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,uBAAuB;IAQ7C,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4BvF,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;CAG3C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { v2 as cloudinary } from 'cloudinary';
|
|
2
|
+
export class CloudinaryStorageAdapter {
|
|
3
|
+
config;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
cloudinary.config({
|
|
7
|
+
cloud_name: config.cloudName,
|
|
8
|
+
api_key: config.apiKey,
|
|
9
|
+
api_secret: config.apiSecret,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async upload(args) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const uploadStream = cloudinary.uploader.upload_stream({
|
|
15
|
+
public_id: args.filename.split('.')[0], // Remove extension
|
|
16
|
+
folder: this.config.folder,
|
|
17
|
+
resource_type: 'auto',
|
|
18
|
+
}, (error, result) => {
|
|
19
|
+
if (error)
|
|
20
|
+
return reject(error);
|
|
21
|
+
if (!result)
|
|
22
|
+
return reject(new Error('Upload failed'));
|
|
23
|
+
resolve({
|
|
24
|
+
filename: result.public_id,
|
|
25
|
+
filesize: result.bytes,
|
|
26
|
+
mimeType: args.mimeType,
|
|
27
|
+
url: result.secure_url,
|
|
28
|
+
width: result.width,
|
|
29
|
+
height: result.height,
|
|
30
|
+
provider_metadata: result,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
uploadStream.end(args.buffer);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async delete(args) {
|
|
37
|
+
await cloudinary.uploader.destroy(args.filename);
|
|
38
|
+
}
|
|
39
|
+
getURL(args) {
|
|
40
|
+
return cloudinary.url(args.filename, { secure: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,UAAU,EAAqB,MAAM,YAAY,CAAC;AASjE,MAAM,OAAO,wBAAwB;IACf;IAApB,YAAoB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;QACjD,UAAU,CAAC,MAAM,CAAC;YAChB,UAAU,EAAE,MAAM,CAAC,SAAS;YAC5B,OAAO,EAAE,MAAM,CAAC,MAAM;YACtB,UAAU,EAAE,MAAM,CAAC,SAAS;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAA4D;QACvE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,aAAa,CACpD;gBACE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,mBAAmB;gBAC3D,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,aAAa,EAAE,MAAM;aACtB,EACD,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBAChB,IAAI,KAAK;oBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChC,IAAI,CAAC,MAAM;oBAAE,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;gBAEvD,OAAO,CAAC;oBACN,QAAQ,EAAE,MAAM,CAAC,SAAS;oBAC1B,QAAQ,EAAE,MAAM,CAAC,KAAK;oBACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,GAAG,EAAE,MAAM,CAAC,UAAU;oBACtB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,iBAAiB,EAAE,MAAM;iBAC1B,CAAC,CAAC;YACL,CAAC,CACF,CAAC;YAEF,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAA0B;QACrC,MAAM,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,IAA0B;QAC/B,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dyrected/storage-cloudinary",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"cloudinary": "^2.2.0",
|
|
12
|
+
"@dyrected/core": "0.0.1"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^20.12.12",
|
|
16
|
+
"typescript": "^5.4.5"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch"
|
|
21
|
+
}
|
|
22
|
+
}
|