kap-r2 1.0.3 → 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 +9 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.shareServices = void 0;
|
|
7
|
-
const
|
|
8
|
-
const promises_1 = require("
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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
11
|
const aws4_1 = __importDefault(require("aws4"));
|
|
12
12
|
const contentTypes = new Map([
|
|
13
13
|
[".gif", "image/gif"],
|
|
@@ -47,9 +47,9 @@ const action = async (context) => {
|
|
|
47
47
|
const fileStats = await (0, promises_1.stat)(filePath);
|
|
48
48
|
const fileBuffer = await (0, promises_1.readFile)(filePath);
|
|
49
49
|
context.setProgress("Uploading to R2…", 0);
|
|
50
|
-
const filename =
|
|
51
|
-
const key = directory ?
|
|
52
|
-
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);
|
|
53
53
|
const contentType = contentTypes.get(extension) || "application/octet-stream";
|
|
54
54
|
const host = `${bucket}.${accountId}.r2.cloudflarestorage.com`;
|
|
55
55
|
const encodedKey = key.split("/").map(encodeURIComponent).join("/");
|
|
@@ -70,7 +70,7 @@ const action = async (context) => {
|
|
|
70
70
|
});
|
|
71
71
|
try {
|
|
72
72
|
await new Promise((resolve, reject) => {
|
|
73
|
-
const req =
|
|
73
|
+
const req = https_1.default.request({
|
|
74
74
|
hostname: host,
|
|
75
75
|
path: `/${encodedKey}`,
|
|
76
76
|
method: "PUT",
|
|
@@ -86,7 +86,7 @@ const action = async (context) => {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
req.on("error", reject);
|
|
89
|
-
const stream = (0,
|
|
89
|
+
const stream = (0, fs_1.createReadStream)(filePath);
|
|
90
90
|
let uploaded = 0;
|
|
91
91
|
stream.on("data", (chunk) => {
|
|
92
92
|
uploaded += Buffer.byteLength(chunk);
|