@qrvey/object-storage 1.0.3-beta → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # @qrvey/object-storage
2
2
 
3
3
  ![install size](https://packagephobia.com/badge?p=%40qrvey%2Fobject-storage)
4
- ![coverage](https://img.shields.io/badge/unit_test_coverage-8%25-brightgreen)
4
+ ![coverage](https://img.shields.io/badge/unit_test_coverage-29%25-brightgreen)
5
5
 
6
6
  The `@qrvey/object-storage` package provides a unified interface for ...
7
7
 
package/dist/cjs/index.js CHANGED
@@ -1508,9 +1508,40 @@ var SftpStorageService = class {
1508
1508
  };
1509
1509
  });
1510
1510
  }
1511
+ async ensureDirectoriesExist(remotePath) {
1512
+ var _a, _b;
1513
+ const parts = remotePath.split("/");
1514
+ parts.pop();
1515
+ let current = "";
1516
+ for (const part of parts) {
1517
+ if (!part)
1518
+ continue;
1519
+ current += `/${part}`;
1520
+ try {
1521
+ await this.client.stat(current);
1522
+ } catch (err) {
1523
+ const isNoEntry = err.code === "ENOENT" || ((_a = err.message) == null ? void 0 : _a.includes("No such file")) || ((_b = err.message) == null ? void 0 : _b.includes("does not exist"));
1524
+ if (isNoEntry) {
1525
+ try {
1526
+ await this.client.mkdir(current);
1527
+ } catch (mkdirErr) {
1528
+ throw new Error(
1529
+ `Failed to create directory ${current}: ${mkdirErr.message}`
1530
+ );
1531
+ }
1532
+ } else {
1533
+ throw new Error(
1534
+ `Failed to check directory ${current}: ${err.message}`
1535
+ );
1536
+ }
1537
+ }
1538
+ }
1539
+ }
1511
1540
  async upload(key, body) {
1512
1541
  return this.withClient(async () => {
1513
- const remotePath = `${this.bucketName}/${key}`;
1542
+ let remotePath = `${this.bucketName}/${key}`;
1543
+ remotePath = remotePath + "";
1544
+ await this.ensureDirectoriesExist(remotePath);
1514
1545
  if (body instanceof stream.Readable) {
1515
1546
  await this.client.put(body, remotePath);
1516
1547
  } else if (body instanceof Buffer) {