@m11s-io/decap-cms-media-library-s3 0.1.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.
- package/dist/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +69 -0
- package/dist/index.mjs +48 -0
- package/package.json +25 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
upload_url?: string;
|
|
3
|
+
}
|
|
4
|
+
interface InitArgs {
|
|
5
|
+
options?: Options;
|
|
6
|
+
handleInsert: (url: string) => void;
|
|
7
|
+
}
|
|
8
|
+
interface Instance {
|
|
9
|
+
show: (args?: {
|
|
10
|
+
imagesOnly?: boolean;
|
|
11
|
+
}) => void;
|
|
12
|
+
hide: () => void;
|
|
13
|
+
onClearControl: () => void;
|
|
14
|
+
onRemoveControl: () => void;
|
|
15
|
+
enableStandalone: () => boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const S3MediaLibrary: {
|
|
18
|
+
name: string;
|
|
19
|
+
init({ options, handleInsert }: InitArgs): Instance;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { S3MediaLibrary as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
upload_url?: string;
|
|
3
|
+
}
|
|
4
|
+
interface InitArgs {
|
|
5
|
+
options?: Options;
|
|
6
|
+
handleInsert: (url: string) => void;
|
|
7
|
+
}
|
|
8
|
+
interface Instance {
|
|
9
|
+
show: (args?: {
|
|
10
|
+
imagesOnly?: boolean;
|
|
11
|
+
}) => void;
|
|
12
|
+
hide: () => void;
|
|
13
|
+
onClearControl: () => void;
|
|
14
|
+
onRemoveControl: () => void;
|
|
15
|
+
enableStandalone: () => boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const S3MediaLibrary: {
|
|
18
|
+
name: string;
|
|
19
|
+
init({ options, handleInsert }: InitArgs): Instance;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { S3MediaLibrary as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => index_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var S3MediaLibrary = {
|
|
27
|
+
name: "s3",
|
|
28
|
+
init({ options = {}, handleInsert }) {
|
|
29
|
+
var _a;
|
|
30
|
+
const uploadUrl = (_a = options.upload_url) != null ? _a : "http://localhost:8082/upload";
|
|
31
|
+
const input = document.createElement("input");
|
|
32
|
+
input.type = "file";
|
|
33
|
+
input.style.display = "none";
|
|
34
|
+
document.body.appendChild(input);
|
|
35
|
+
input.addEventListener("change", async () => {
|
|
36
|
+
var _a2;
|
|
37
|
+
const file = (_a2 = input.files) == null ? void 0 : _a2[0];
|
|
38
|
+
if (!file) return;
|
|
39
|
+
const formData = new FormData();
|
|
40
|
+
formData.append("file", file);
|
|
41
|
+
try {
|
|
42
|
+
const res = await fetch(uploadUrl, { method: "POST", body: formData });
|
|
43
|
+
const data = await res.json();
|
|
44
|
+
if (data.error) throw new Error(data.error);
|
|
45
|
+
handleInsert(data.url);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("S3 upload failed:", err);
|
|
48
|
+
alert(`Upload failed: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
input.value = "";
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
show({ imagesOnly } = {}) {
|
|
54
|
+
input.accept = imagesOnly ? "image/*" : "image/*,video/*,.pdf";
|
|
55
|
+
input.click();
|
|
56
|
+
},
|
|
57
|
+
hide() {
|
|
58
|
+
},
|
|
59
|
+
onClearControl() {
|
|
60
|
+
},
|
|
61
|
+
onRemoveControl() {
|
|
62
|
+
},
|
|
63
|
+
enableStandalone() {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var index_default = S3MediaLibrary;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var S3MediaLibrary = {
|
|
3
|
+
name: "s3",
|
|
4
|
+
init({ options = {}, handleInsert }) {
|
|
5
|
+
var _a;
|
|
6
|
+
const uploadUrl = (_a = options.upload_url) != null ? _a : "http://localhost:8082/upload";
|
|
7
|
+
const input = document.createElement("input");
|
|
8
|
+
input.type = "file";
|
|
9
|
+
input.style.display = "none";
|
|
10
|
+
document.body.appendChild(input);
|
|
11
|
+
input.addEventListener("change", async () => {
|
|
12
|
+
var _a2;
|
|
13
|
+
const file = (_a2 = input.files) == null ? void 0 : _a2[0];
|
|
14
|
+
if (!file) return;
|
|
15
|
+
const formData = new FormData();
|
|
16
|
+
formData.append("file", file);
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch(uploadUrl, { method: "POST", body: formData });
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
if (data.error) throw new Error(data.error);
|
|
21
|
+
handleInsert(data.url);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error("S3 upload failed:", err);
|
|
24
|
+
alert(`Upload failed: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
input.value = "";
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
show({ imagesOnly } = {}) {
|
|
30
|
+
input.accept = imagesOnly ? "image/*" : "image/*,video/*,.pdf";
|
|
31
|
+
input.click();
|
|
32
|
+
},
|
|
33
|
+
hide() {
|
|
34
|
+
},
|
|
35
|
+
onClearControl() {
|
|
36
|
+
},
|
|
37
|
+
onRemoveControl() {
|
|
38
|
+
},
|
|
39
|
+
enableStandalone() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var index_default = S3MediaLibrary;
|
|
46
|
+
export {
|
|
47
|
+
index_default as default
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@m11s-io/decap-cms-media-library-s3",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "S3-compatible media library plugin for Decap CMS",
|
|
5
|
+
"main": "dist/index.umd.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"dev": "tsup --watch"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"decap-cms",
|
|
16
|
+
"netlify-cms",
|
|
17
|
+
"s3",
|
|
18
|
+
"minio",
|
|
19
|
+
"media-library"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsup": "^8"
|
|
24
|
+
}
|
|
25
|
+
}
|