From a9b86866371521af5dcaafb931ba744198f39bbb Mon Sep 17 00:00:00 2001 From: Aditya Kresna Date: Sun, 23 Oct 2022 22:13:14 +0700 Subject: [PATCH 1/4] fix error S3 when using filesystem mode --- routes/files/bundle_filegroup.go | 48 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/routes/files/bundle_filegroup.go b/routes/files/bundle_filegroup.go index ff2ac4c..655a841 100644 --- a/routes/files/bundle_filegroup.go +++ b/routes/files/bundle_filegroup.go @@ -207,33 +207,35 @@ func BundleFileGroup(repo repository.Repository, s3Client *s3.Client) func(c *gi return } - go func(filePath string) { - keyName := filepath.Base(filePath) - bundledFile, err := os.Open(filePath) - if err != nil { - log.Printf("Error reading bundled file at %s, is the file removed? %s", filePath, err.Error()) - return - } - defer bundledFile.Close() + if appConfig.IsUsingS3Storage() { + go func(filePath string) { + keyName := filepath.Base(filePath) + bundledFile, err := os.Open(filePath) + if err != nil { + log.Printf("Error reading bundled file at %s, is the file removed? %s", filePath, err.Error()) + return + } + defer bundledFile.Close() - _, err = s3Client.PutObject(context.Background(), &s3.PutObjectInput{ - Bucket: aws.String(appConfig.GetS3Bucket()), - Key: &keyName, - Body: bundledFile, - Expires: fileGroup.ExpiredAt, // cache expiration - }) + _, err = s3Client.PutObject(context.Background(), &s3.PutObjectInput{ + Bucket: aws.String(appConfig.GetS3Bucket()), + Key: &keyName, + Body: bundledFile, + Expires: fileGroup.ExpiredAt, // cache expiration + }) - if err == nil { - fileGroup.FileKey = keyName - db.Save(&fileGroup) + if err == nil { + fileGroup.FileKey = keyName + db.Save(&fileGroup) - // remove local file because already uploaded to S3 - os.Remove(filePath) - return - } + // remove local file because already uploaded to S3 + os.Remove(filePath) + return + } - log.Println("error S3 upload", err) - }(fileGroup.FileKey) + log.Println("error S3 upload", err) + }(fileGroup.FileKey) + } pinCode := "" From 7a2c837e4188d8cdff7f411447b34b25433775e2 Mon Sep 17 00:00:00 2001 From: Aditya Kresna Date: Sun, 23 Oct 2022 22:13:30 +0700 Subject: [PATCH 2/4] update config example --- config.example.yaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index 051ea89..6fca6f1 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,10 +1,12 @@ +# Set host & port for hansip backend server server_api: - secure: false + secure: false # set true if the address is https host: localhost port: 8080 +# Set host & port for web application server server_web: - secure: false + secure: false # set true if the address is https host: localhost port: 8181 @@ -12,13 +14,18 @@ storage: type: filesystem # or s3 dirpaths: - upload: /tmp/hansip-files/uploaded - bundle: /tmp/hansip-files/bundled + # Directory when uploading files before processed + upload: ./hansip-files/uploaded + # Directory for storing files after processed, + # files on bundle directory will be removed if activates S3 after successfully uploaded + bundle: ./hansip-files/bundled db: type: sqlite # or postgresql sqlite: + # path for sqlite database file + # by default will use WAL mode for better concurrency path: ./hansip.db postgresql: From 68f9de7de6a554f88876b921afed2d1c0b12ef62 Mon Sep 17 00:00:00 2001 From: Aditya Kresna Date: Sun, 23 Oct 2022 22:13:36 +0700 Subject: [PATCH 3/4] ignore hansip files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 10bff72..ad9b531 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,6 @@ config.yaml *.db *.db-wal -*.db-shm \ No newline at end of file +*.db-shm + +hansip-files \ No newline at end of file From 51de88d443f90907f127ad1617aebbe0241464d7 Mon Sep 17 00:00:00 2001 From: Aditya Kresna Date: Sun, 23 Oct 2022 22:15:22 +0700 Subject: [PATCH 4/4] update changelog v0.1.3 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dab9c42..b2abca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +### v0.1.3 + +> 23 October 2022 + +- Fixed error S3 when using `filesystem` mode +- Updated `config.yaml` example for upload & bundle directory + ### v0.1.2 > 23 October 2022