@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.
@@ -1502,9 +1502,40 @@ var SftpStorageService = class {
1502
1502
  };
1503
1503
  });
1504
1504
  }
1505
+ async ensureDirectoriesExist(remotePath) {
1506
+ var _a, _b;
1507
+ const parts = remotePath.split("/");
1508
+ parts.pop();
1509
+ let current = "";
1510
+ for (const part of parts) {
1511
+ if (!part)
1512
+ continue;
1513
+ current += `/${part}`;
1514
+ try {
1515
+ await this.client.stat(current);
1516
+ } catch (err) {
1517
+ 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"));
1518
+ if (isNoEntry) {
1519
+ try {
1520
+ await this.client.mkdir(current);
1521
+ } catch (mkdirErr) {
1522
+ throw new Error(
1523
+ `Failed to create directory ${current}: ${mkdirErr.message}`
1524
+ );
1525
+ }
1526
+ } else {
1527
+ throw new Error(
1528
+ `Failed to check directory ${current}: ${err.message}`
1529
+ );
1530
+ }
1531
+ }
1532
+ }
1533
+ }
1505
1534
  async upload(key, body) {
1506
1535
  return this.withClient(async () => {
1507
- const remotePath = `${this.bucketName}/${key}`;
1536
+ let remotePath = `${this.bucketName}/${key}`;
1537
+ remotePath = remotePath + "";
1538
+ await this.ensureDirectoriesExist(remotePath);
1508
1539
  if (body instanceof Readable) {
1509
1540
  await this.client.put(body, remotePath);
1510
1541
  } else if (body instanceof Buffer) {