Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
4f63b03a
Commit
4f63b03a
authored
7 years ago
by
Megan Henning
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #758 from scitran/zip-options-analyses
Add zip options to analysis files
parents
1ff963d7
3926723e
No related branches found
Branches containing commit
Tags
1.0.63
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/handlers/listhandler.py
+39
-8
39 additions, 8 deletions
api/handlers/listhandler.py
with
39 additions
and
8 deletions
api/handlers/listhandler.py
+
39
−
8
View file @
4f63b03a
...
...
@@ -342,7 +342,8 @@ class FileListHandler(ListHandler):
self
.
abort
(
400
,
'
ticket not for this resource or source IP
'
)
return
ticket
def
_build_zip_info
(
self
,
filepath
):
@staticmethod
def
build_zip_info
(
filepath
):
"""
Builds a json response containing member and comment info for a zipfile
"""
...
...
@@ -436,7 +437,7 @@ class FileListHandler(ListHandler):
# Request for info about zipfile
elif
self
.
is_true
(
'
info
'
):
try
:
info
=
self
.
_
build_zip_info
(
filepath
)
info
=
self
.
build_zip_info
(
filepath
)
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
return
info
...
...
@@ -815,13 +816,43 @@ class AnalysesHandler(ListHandler):
util
.
path_from_hash
(
fileinfo
[
'
hash
'
])
)
filename
=
fileinfo
[
'
name
'
]
self
.
response
.
app_iter
=
open
(
filepath
,
'
rb
'
)
self
.
response
.
headers
[
'
Content-Length
'
]
=
str
(
fileinfo
[
'
size
'
])
# must be set after setting app_iter
if
self
.
is_true
(
'
view
'
):
self
.
response
.
headers
[
'
Content-Type
'
]
=
str
(
fileinfo
.
get
(
'
mimetype
'
,
'
application/octet-stream
'
))
# Request for info about zipfile
if
self
.
is_true
(
'
info
'
):
try
:
info
=
FileListHandler
.
build_zip_info
(
filepath
)
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
return
info
# Request to download zipfile member
elif
self
.
get_param
(
'
member
'
)
is
not
None
:
zip_member
=
self
.
get_param
(
'
member
'
)
try
:
with
zipfile
.
ZipFile
(
filepath
)
as
zf
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
util
.
guess_mimetype
(
zip_member
)
self
.
response
.
write
(
zf
.
open
(
zip_member
).
read
())
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
except
KeyError
:
self
.
abort
(
400
,
'
zip file contains no such member
'
)
# log download if we haven't already for this ticket
if
ticket
:
if
not
ticket
.
get
(
'
logged
'
,
False
):
self
.
log_user_access
(
AccessType
.
download_file
,
cont_name
=
cont_name
,
cont_id
=
_id
)
config
.
db
.
downloads
.
update_one
({
'
_id
'
:
ticket_id
},
{
'
$set
'
:
{
'
logged
'
:
True
}})
else
:
self
.
log_user_access
(
AccessType
.
download_file
,
cont_name
=
cont_name
,
cont_id
=
_id
)
# Request to download the file itself
else
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
application/octet-stream
'
self
.
response
.
headers
[
'
Content-Disposition
'
]
=
'
attachment; filename=
'
+
str
(
filename
)
self
.
response
.
app_iter
=
open
(
filepath
,
'
rb
'
)
self
.
response
.
headers
[
'
Content-Length
'
]
=
str
(
fileinfo
[
'
size
'
])
# must be set after setting app_iter
if
self
.
is_true
(
'
view
'
):
self
.
response
.
headers
[
'
Content-Type
'
]
=
str
(
fileinfo
.
get
(
'
mimetype
'
,
'
application/octet-stream
'
))
else
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
application/octet-stream
'
self
.
response
.
headers
[
'
Content-Disposition
'
]
=
'
attachment; filename=
'
+
str
(
filename
)
# log download if we haven't already for this ticket
if
ticket
:
...
...
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