aboutsummaryrefslogtreecommitdiff
path: root/services/files
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-17 23:40:16 +0300
committereug-vs <eug-vs@keemail.me>2020-08-17 23:40:39 +0300
commit1cddff7de99c6b209d35137ceb7cde3045573dc0 (patch)
treedde301d6529fc1140e413c9cd3db8c4033cff552 /services/files
parentc43e6d185b7606ff8c0d038746b9e376e04143b5 (diff)
downloadwhich-api-1cddff7de99c6b209d35137ceb7cde3045573dc0.tar.gz
feat: cleanup after poll deletion
Diffstat (limited to 'services/files')
-rw-r--r--services/files/files.class.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/services/files/files.class.ts b/services/files/files.class.ts
index f2a0960..8308b12 100644
--- a/services/files/files.class.ts
+++ b/services/files/files.class.ts
@@ -24,7 +24,7 @@ export default class Files {
}
public isS3url(url: string): boolean {
- return url.startsWith(`https://${this.bucket}.s3`);
+ return url?.startsWith(`https://${this.bucket}.s3`);
}
public generateS3Path(prefix = '', ext = 'png'): string {
@@ -33,6 +33,11 @@ export default class Files {
return prefix ? `${prefix}/${fileName}` : fileName;
}
+ public getS3PathFromUrl(url: string): string {
+ const dotComIndex = url.indexOf('.com');
+ return url.slice(dotComIndex + 5);
+ }
+
async getUploadUrl(path: string): Promise<string> {
// Return signed upload URL
return this.s3.getSignedUrl('putObject', {
@@ -81,6 +86,13 @@ export default class Files {
return this.getDownloadUrl(s3Path);
}
+ async deleteFile(s3Path: string): Promise<void> {
+ return this.s3.deleteObject({
+ Bucket: this.bucket,
+ Key: s3Path
+ }).promise();
+ }
+
setup(app: Application): void {
this.app = app;
this.s3 = new S3({