Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
✨ Moved Spaces functions to Uberdeno
Browse files Browse the repository at this point in the history
  • Loading branch information
Schotsl committed Dec 1, 2022
1 parent 52d4160 commit e07e36d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions services/spacesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,43 @@ class SpacesClient {
});
}

async getFile(filename: string) {
const response = await this.bucket.listObjects({ prefix: filename });
const contents = response?.contents;

if (!contents || contents.length === 0) {
return null;
}

return {
name: contents[0].key!.replace(/^.*\/(.*)$/, "$1"),
size: contents[0].size!,
updated: contents[0].lastModified!,
download: spacesClient.signedGET(contents[0].key!),
};
}

async getFiles(directory: string) {
const response = await this.bucket.listObjects({ prefix: directory });
const contents = response?.contents;

if (!contents || contents.length === 0) {
return null;
}

// The first item is just the directory instead of a file so we'll remove it
contents.shift();

return contents.map((content) => {
return {
name: content.key!.replace(/^.*\/(.*)$/, "$1"),
size: content.size!,
updated: content.lastModified!,
download: spacesClient.signedGET(content.key!),
};
});
}

async deleteFile(filename: string) {
return await this.bucket.deleteObject(filename);
}
Expand Down

0 comments on commit e07e36d

Please sign in to comment.