Skip to content

Commit c7e499b

Browse files
committed
Merge branch 'release/v0.1.3'
2 parents f6514c2 + 51de88d commit c7e499b

File tree

4 files changed

+46
-28
lines changed

4 files changed

+46
-28
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ config.yaml
5454

5555
*.db
5656
*.db-wal
57-
*.db-shm
57+
*.db-shm
58+
59+
hansip-files

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
### v0.1.3
6+
7+
> 23 October 2022
8+
9+
- Fixed error S3 when using `filesystem` mode
10+
- Updated `config.yaml` example for upload & bundle directory
11+
512
### v0.1.2
613

714
> 23 October 2022

config.example.yaml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1+
# Set host & port for hansip backend server
12
server_api:
2-
secure: false
3+
secure: false # set true if the address is https
34
host: localhost
45
port: 8080
56

7+
# Set host & port for web application server
68
server_web:
7-
secure: false
9+
secure: false # set true if the address is https
810
host: localhost
911
port: 8181
1012

1113
storage:
1214
type: filesystem # or s3
1315

1416
dirpaths:
15-
upload: /tmp/hansip-files/uploaded
16-
bundle: /tmp/hansip-files/bundled
17+
# Directory when uploading files before processed
18+
upload: ./hansip-files/uploaded
19+
# Directory for storing files after processed,
20+
# files on bundle directory will be removed if activates S3 after successfully uploaded
21+
bundle: ./hansip-files/bundled
1722

1823
db:
1924
type: sqlite # or postgresql
2025

2126
sqlite:
27+
# path for sqlite database file
28+
# by default will use WAL mode for better concurrency
2229
path: ./hansip.db
2330

2431
postgresql:

routes/files/bundle_filegroup.go

+25-23
Original file line numberDiff line numberDiff line change
@@ -207,33 +207,35 @@ func BundleFileGroup(repo repository.Repository, s3Client *s3.Client) func(c *gi
207207
return
208208
}
209209

210-
go func(filePath string) {
211-
keyName := filepath.Base(filePath)
212-
bundledFile, err := os.Open(filePath)
213-
if err != nil {
214-
log.Printf("Error reading bundled file at %s, is the file removed? %s", filePath, err.Error())
215-
return
216-
}
217-
defer bundledFile.Close()
210+
if appConfig.IsUsingS3Storage() {
211+
go func(filePath string) {
212+
keyName := filepath.Base(filePath)
213+
bundledFile, err := os.Open(filePath)
214+
if err != nil {
215+
log.Printf("Error reading bundled file at %s, is the file removed? %s", filePath, err.Error())
216+
return
217+
}
218+
defer bundledFile.Close()
218219

219-
_, err = s3Client.PutObject(context.Background(), &s3.PutObjectInput{
220-
Bucket: aws.String(appConfig.GetS3Bucket()),
221-
Key: &keyName,
222-
Body: bundledFile,
223-
Expires: fileGroup.ExpiredAt, // cache expiration
224-
})
220+
_, err = s3Client.PutObject(context.Background(), &s3.PutObjectInput{
221+
Bucket: aws.String(appConfig.GetS3Bucket()),
222+
Key: &keyName,
223+
Body: bundledFile,
224+
Expires: fileGroup.ExpiredAt, // cache expiration
225+
})
225226

226-
if err == nil {
227-
fileGroup.FileKey = keyName
228-
db.Save(&fileGroup)
227+
if err == nil {
228+
fileGroup.FileKey = keyName
229+
db.Save(&fileGroup)
229230

230-
// remove local file because already uploaded to S3
231-
os.Remove(filePath)
232-
return
233-
}
231+
// remove local file because already uploaded to S3
232+
os.Remove(filePath)
233+
return
234+
}
234235

235-
log.Println("error S3 upload", err)
236-
}(fileGroup.FileKey)
236+
log.Println("error S3 upload", err)
237+
}(fileGroup.FileKey)
238+
}
237239

238240
pinCode := ""
239241

0 commit comments

Comments
 (0)