kap-r2 1.0.2 → 1.0.4
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.js +20 -14
- package/package.json +1 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.shareServices = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const https_1 = __importDefault(require("https"));
|
|
11
|
+
const aws4_1 = __importDefault(require("aws4"));
|
|
6
12
|
const contentTypes = new Map([
|
|
7
13
|
[".gif", "image/gif"],
|
|
8
14
|
[".mp4", "video/mp4"],
|
|
@@ -38,16 +44,16 @@ const action = async (context) => {
|
|
|
38
44
|
return;
|
|
39
45
|
}
|
|
40
46
|
const filePath = await context.filePath();
|
|
41
|
-
const fileStats = await stat(filePath);
|
|
42
|
-
const fileBuffer = await readFile(filePath);
|
|
47
|
+
const fileStats = await (0, promises_1.stat)(filePath);
|
|
48
|
+
const fileBuffer = await (0, promises_1.readFile)(filePath);
|
|
43
49
|
context.setProgress("Uploading to R2…", 0);
|
|
44
|
-
const filename =
|
|
45
|
-
const key = directory ?
|
|
46
|
-
const extension =
|
|
50
|
+
const filename = path_1.default.basename(filePath);
|
|
51
|
+
const key = directory ? path_1.default.posix.join(directory, filename) : filename;
|
|
52
|
+
const extension = path_1.default.extname(filename);
|
|
47
53
|
const contentType = contentTypes.get(extension) || "application/octet-stream";
|
|
48
54
|
const host = `${bucket}.${accountId}.r2.cloudflarestorage.com`;
|
|
49
55
|
const encodedKey = key.split("/").map(encodeURIComponent).join("/");
|
|
50
|
-
const request =
|
|
56
|
+
const request = aws4_1.default.sign({
|
|
51
57
|
host,
|
|
52
58
|
path: `/${encodedKey}`,
|
|
53
59
|
method: "PUT",
|
|
@@ -64,7 +70,7 @@ const action = async (context) => {
|
|
|
64
70
|
});
|
|
65
71
|
try {
|
|
66
72
|
await new Promise((resolve, reject) => {
|
|
67
|
-
const req =
|
|
73
|
+
const req = https_1.default.request({
|
|
68
74
|
hostname: host,
|
|
69
75
|
path: `/${encodedKey}`,
|
|
70
76
|
method: "PUT",
|
|
@@ -80,7 +86,7 @@ const action = async (context) => {
|
|
|
80
86
|
}
|
|
81
87
|
});
|
|
82
88
|
req.on("error", reject);
|
|
83
|
-
const stream = createReadStream(filePath);
|
|
89
|
+
const stream = (0, fs_1.createReadStream)(filePath);
|
|
84
90
|
let uploaded = 0;
|
|
85
91
|
stream.on("data", (chunk) => {
|
|
86
92
|
uploaded += Buffer.byteLength(chunk);
|
|
@@ -154,4 +160,4 @@ const r2 = {
|
|
|
154
160
|
},
|
|
155
161
|
},
|
|
156
162
|
};
|
|
157
|
-
|
|
163
|
+
exports.shareServices = [r2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kap-r2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Share on Cloudflare R2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tristanremy/kap-r2",
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
"name": "Tristan Remy",
|
|
9
9
|
"url": "https://github.com/tristanremy"
|
|
10
10
|
},
|
|
11
|
-
"type": "module",
|
|
12
|
-
"exports": "./dist/index.js",
|
|
13
11
|
"main": "./dist/index.js",
|
|
14
12
|
"files": [
|
|
15
13
|
"dist"
|