Skip to content

Commit

Permalink
Merge branch 'release/v0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
slaveofcode committed Oct 23, 2022
2 parents f6514c2 + 51de88d commit c7e499b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ config.yaml

*.db
*.db-wal
*.db-shm
*.db-shm

hansip-files
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# 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

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:
Expand Down
48 changes: 25 additions & 23 deletions routes/files/bundle_filegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""

Expand Down

0 comments on commit c7e499b

Please sign in to comment.