Skip to content

Commit

Permalink
Fix pack zip package collision
Browse files Browse the repository at this point in the history
- Zip package storage path: `[full|custom]-archive/{re_code}/{uuid}.zip`.
  • Loading branch information
Triple-Z committed Apr 5, 2019
1 parent 6e1c9f7 commit 076e2fe
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 37 deletions.
46 changes: 23 additions & 23 deletions conf/nginx/api.safeu.a2os.club
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
# server_name api.safeu.a2os.club;
server_name _;
location / {
proxy_pass http://app_servers;
proxy_redirect default;
}
# return 301 https://$host$request_uri;
server_name api.safeu.a2os.club;
# server_name _;
# location / {
# proxy_pass http://app_servers;
# proxy_redirect default;
# }
return 301 https://$host$request_uri;
}
# HTTPS server
# server {
# # SSL configuration
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
server {
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

# server_name api.safeu.a2os.club;
# ssl on;
# ssl_certificate /opt/nginx/api.safeu.a2os.club/fullchain.pem;
# ssl_certificate_key /opt/nginx/api.safeu.a2os.club/privkey.pem;
server_name api.safeu.a2os.club;
ssl on;
ssl_certificate /opt/nginx/api.safeu.a2os.club/fullchain.pem;
ssl_certificate_key /opt/nginx/api.safeu.a2os.club/privkey.pem;

# location / {
# # First attempt to serve request as file, then
# # as directory, then fall back to displaying a 404.
# #try_files $uri $uri/ =404;
# proxy_pass http://app_servers;
# proxy_redirect default;
# }
# }
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://app_servers;
proxy_redirect default;
}
}
4 changes: 2 additions & 2 deletions deployments/development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ services:
context: ../..
dockerfile: ././build/package/safeu-backend-dev/Dockerfile-compose
volumes:
# - ../..:/go/src/a2os/safeu-backend/
- ../../log/web:/go/src/a2os/safeu-backend/log/
# - ../..:/go/src/a2os/safeu-backend/
environment:
- TZ=Asia/Shanghai
ports:
Expand Down Expand Up @@ -54,7 +54,7 @@ services:
- TZ=Asia/Shanghai
volumes:
- ../../conf/redis/redis.conf:/usr/local/etc/redis/redis.conf
# - ../../data-dev/redis:/data # for redis persistent storage
- ../../data-dev/redis:/data # for redis persistent storage
entrypoint: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
Expand Down
8 changes: 4 additions & 4 deletions deployments/production/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
volumes:
- ../../conf/nginx/nginx.prod.conf:/etc/nginx/nginx.conf
- ../../conf/nginx/api.safeu.a2os.club:/etc/nginx/sites-enabled/api.safeu.a2os.club
- ~/.acme.sh/api.safeu.a2os.club:/opt/nginx/api.safeu.a2os.club/
- /etc/letsencrypt/live/api.safeu.a2os.club:/opt/nginx/api.safeu.a2os.club/
environment:
- TZ=Asia/Shanghai
ports:
Expand All @@ -22,8 +22,8 @@ services:
context: ../..
dockerfile: ././build/package/safeu-backend/Dockerfile-compose
volumes:
# - ../..:/go/src/a2os/safeu-backend/
- ../../log/web1:/go/src/a2os/safeu-backend/log/
# - ../..:/go/src/a2os/safeu-backend/
environment:
- TZ=Asia/Shanghai
ports:
Expand All @@ -42,8 +42,8 @@ services:
context: ../..
dockerfile: ././build/package/safeu-backend/Dockerfile-compose
volumes:
# - ../..:/go/src/a2os/safeu-backend/
- ../../log/web2:/go/src/a2os/safeu-backend/log/
# - ../..:/go/src/a2os/safeu-backend/
environment:
- TZ=Asia/Shanghai
ports:
Expand Down Expand Up @@ -78,7 +78,7 @@ services:
- TZ=Asia/Shanghai
volumes:
- ../../conf/redis/redis.conf:/usr/local/etc/redis/redis.conf
# - ../../data/redis:/data # for redis persistent storage
- ../../data/redis:/data # for redis persistent storage
entrypoint: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
Expand Down
5 changes: 3 additions & 2 deletions faas/zip-items.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def handler(environ, start_response):
# zip name
re_code = request_body_json.get("re_code")
is_full = request_body_json.get("full")
uuid = request_body_json.get("uuid")
tmpdir = '/tmp/download/'

os.system("rm -rf /tmp/*")
Expand Down Expand Up @@ -78,9 +79,9 @@ def handler(environ, start_response):
part_size = oss2.determine_part_size(total_size, preferred_size = 128 * 1024)

if is_full:
zip_path = 'full-archive/' + re_code + '.zip'
zip_path = 'full-archive/' + re_code + '/' + uuid + '.zip'
else:
zip_path = 'custom-archive/' + re_code + '.zip'
zip_path = 'custom-archive/' + re_code + '/' + uuid + '.zip'

# use the last bucket to upload zip package
upload_id = bucket.init_multipart_upload(zip_path).upload_id
Expand Down
15 changes: 10 additions & 5 deletions item/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func DownloadItems(c *gin.Context) {
zipPack.Type = resJson["type"]
zipPack.ArchiveType = common.ARCHIVE_FULL
zipPack.DownCount = common.INFINITE_DOWNLOAD
zipPack.ExpiredAt = itemList[0].ExpiredAt // 过期时间跟随生成压缩包的文件有效时间

db.Create(&zipPack)
log.Println("Generated the full files zip package for retrieve code \"", retrieveCode, "\"")
Expand Down Expand Up @@ -293,13 +294,15 @@ func DownloadItems(c *gin.Context) {
Bucket: resJson["bucket"],
Endpoint: resJson["endpoint"],
Path: resJson["path"],
ExpiredAt: itemList[0].ExpiredAt, // 过期时间跟随生成压缩包的文件有效时间
}
// 先清除数据库之前同提取码的自定义压缩包记录
var deleteZipPacks []Item
db.Where("re_code = ? AND (status = ? OR status = ?) AND archive_type = ?", retrieveCode, common.UPLOAD_FINISHED, common.FILE_ACTIVE, common.ARCHIVE_CUSTOM).Find(&deleteZipPacks)
for _, deleteZipPack := range deleteZipPacks {
db.Delete(&deleteZipPack)
}
// [4.5.2019] 不需要,不同压缩包可以共存
//var deleteZipPacks []Item
//db.Where("re_code = ? AND (status = ? OR status = ?) AND archive_type = ?", retrieveCode, common.UPLOAD_FINISHED, common.FILE_ACTIVE, common.ARCHIVE_CUSTOM).Find(&deleteZipPacks)
//for _, deleteZipPack := range deleteZipPacks {
// db.Delete(&deleteZipPack)
//}

db.Create(&zipPack)
log.Println("Generated the custom files zip package for retrieve code \"", retrieveCode, "\"")
Expand All @@ -322,6 +325,7 @@ func DownloadItems(c *gin.Context) {
func ZipItemsFaaS(zipItems []ZipItem, retrieveCode string, isFull bool, endpoint string) map[string]string {
reqJson := map[string]interface{}{
"re_code": retrieveCode,
"uuid": uuid.Must(uuid.NewV4()).String(),
"items": zipItems,
"full": isFull,
}
Expand All @@ -335,6 +339,7 @@ func ZipItemsFaaS(zipItems []ZipItem, retrieveCode string, isFull bool, endpoint
// 请求函数计算
res, err := http.Post(endpoint, "application/json", bytes.NewBuffer(bytesRepresentation))
if err != nil {
// TODO: 加入重试机制
log.Println(err)
}

Expand Down
2 changes: 1 addition & 1 deletion runner.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build_name: runner-build
build_log: runner-build-errors.log
valid_ext: .go, .tpl, .tmpl, .html
no_rebuild_ext: .tpl, .tmpl, .html
ignored: assets, tmp, vendor, db-data, data, log, api, build, deployments
ignored: assets, tmp, vendor, db-data, data, data-dev, log, api, build, deployments
build_delay: 600
colors: 1
log_color_main: cyan
Expand Down

0 comments on commit 076e2fe

Please sign in to comment.