kap-r2 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ 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 fs_1 = require("fs");
8
7
  const promises_1 = require("fs/promises");
9
8
  const path_1 = __importDefault(require("path"));
10
9
  const https_1 = __importDefault(require("https"));
@@ -77,23 +76,21 @@ const action = async (context) => {
77
76
  method: "PUT",
78
77
  headers: request.headers,
79
78
  }, (res) => {
80
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
81
- resolve();
82
- }
83
- else {
84
- const chunks = [];
85
- res.on("data", (chunk) => chunks.push(chunk));
86
- res.on("end", () => reject(new Error(`HTTP ${res.statusCode}: ${Buffer.concat(chunks).toString()}`)));
87
- }
79
+ const chunks = [];
80
+ res.on("data", (chunk) => chunks.push(chunk));
81
+ res.on("end", () => {
82
+ const body = Buffer.concat(chunks).toString();
83
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
84
+ resolve();
85
+ }
86
+ else {
87
+ reject(new Error(`HTTP ${res.statusCode}: ${body}`));
88
+ }
89
+ });
88
90
  });
89
91
  req.on("error", reject);
90
- const stream = (0, fs_1.createReadStream)(filePath);
91
- let uploaded = 0;
92
- stream.on("data", (chunk) => {
93
- uploaded += Buffer.byteLength(chunk);
94
- context.setProgress("Uploading to R2…", uploaded / fileStats.size);
95
- });
96
- stream.pipe(req);
92
+ context.setProgress("Uploading to R2…", 0.5);
93
+ req.end(fileBuffer);
97
94
  });
98
95
  const baseUrl = publicUrl.replace(/\/$/, "");
99
96
  const uploadUrl = `${baseUrl}/${encodedKey}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kap-r2",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Share on Cloudflare R2",
5
5
  "license": "MIT",
6
6
  "repository": "tristanremy/kap-r2",