From 7dbfdb30566796d0bbed52a010119adc7a34c211 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Wed, 22 Feb 2023 08:00:20 +0100 Subject: [PATCH] fix(#181): check if folder exists in S3 --- src/Repository.ts | 2 +- src/source/GitHubStream.ts | 6 +++++- src/storage/S3.ts | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Repository.ts b/src/Repository.ts index eee1ce0..0389b95 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -1,7 +1,7 @@ import { join } from "path"; import storage from "./storage"; import { RepositoryStatus, Source, Tree, TreeElement, TreeFile } from "./types"; -import { Readable, Transform } from "stream"; +import { Readable } from "stream"; import User from "./User"; import GitHubStream from "./source/GitHubStream"; import GitHubDownload from "./source/GitHubDownload"; diff --git a/src/source/GitHubStream.ts b/src/source/GitHubStream.ts index 72d1eac..ac8b454 100644 --- a/src/source/GitHubStream.ts +++ b/src/source/GitHubStream.ts @@ -80,7 +80,11 @@ export default class GitHubStream extends GitHubBase implements SourceBase { } async getFiles() { - return this.getTree(this.branch.commit); + let commit = this.branch?.commit; + if (!commit && this.repository.model.source.commit) { + commit = this.repository.model.source.commit; + } + return this.getTree(commit); } private async getTree( diff --git a/src/storage/S3.ts b/src/storage/S3.ts index 1044b91..e8765b9 100644 --- a/src/storage/S3.ts +++ b/src/storage/S3.ts @@ -45,7 +45,15 @@ export default class S3Storage implements StorageBase { .promise(); return true; } catch (err) { - return false; + // check if it is a directory + const data = await this.client + .listObjectsV2({ + Bucket: config.S3_BUCKET, + Prefix: path, + MaxKeys: 1, + }) + .promise(); + return (data.Contents?.length || 0) > 0; } }