Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MECRED
Zipper
Commits
971e451d
Commit
971e451d
authored
1 year ago
by
Richard Fernando Heise Ferreira
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue-1/check-zip-empty' into 'master'
Issue
#1
: ADD check if there any files to zip See merge request
!1
parents
321bdca7
becf65b0
No related branches found
No related tags found
1 merge request
!1
Issue #1: ADD check if there any files to zip
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/proxy.py
+17
-3
17 additions, 3 deletions
app/proxy.py
with
17 additions
and
3 deletions
app/proxy.py
+
17
−
3
View file @
971e451d
...
@@ -57,17 +57,31 @@ def create_zip(files, collection_id):
...
@@ -57,17 +57,31 @@ def create_zip(files, collection_id):
@app.route
(
'
/<collection_id>
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/<collection_id>
'
,
methods
=
[
'
GET
'
])
def
download_zip
(
collection_id
):
def
download_zip
(
collection_id
):
try
:
try
:
if
os
.
path
.
exists
(
f
"
colecao_
{
collection_id
}
.zip
"
):
zip_filename
=
f
"
colecao_
{
collection_id
}
.zip
"
zip_path
=
os
.
path
.
abspath
(
f
"
colecao_
{
collection_id
}
.zip
"
)
if
os
.
path
.
exists
(
zip_filename
):
# Check if zip file is empty
with
ZipFile
(
zip_filename
,
'
r
'
)
as
zip
:
if
not
zip
.
namelist
():
# If namelist() returns an empty list, the zip is empty
return
"
Zip is empty
"
,
200
# Zip file exists and is not empty, send it
zip_path
=
os
.
path
.
abspath
(
zip_filename
)
return
send_file
(
zip_path
,
as_attachment
=
True
),
200
return
send_file
(
zip_path
,
as_attachment
=
True
),
200
ids
=
get_collection_ids
(
collection_id
)
ids
=
get_collection_ids
(
collection_id
)
downloaded_files
=
download_files
(
ids
)
downloaded_files
=
download_files
(
ids
)
# Check if downloaded_files is empty
if
not
downloaded_files
:
return
"
No files to zip
"
,
200
create_zip
(
downloaded_files
,
collection_id
)
create_zip
(
downloaded_files
,
collection_id
)
zip_path
=
os
.
path
.
abspath
(
f
"
colecao_
{
collection_id
}
.zip
"
)
zip_path
=
os
.
path
.
abspath
(
zip_filename
)
response
=
send_file
(
zip_path
,
as_attachment
=
True
)
response
=
send_file
(
zip_path
,
as_attachment
=
True
)
return
response
,
200
return
response
,
200
except
Exception
as
e
:
except
Exception
as
e
:
return
str
(
e
),
500
return
str
(
e
),
500
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
app
.
run
(
port
=
3333
)
app
.
run
(
port
=
3333
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment