Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chiefs
ChiefSend
Commits
1b16e96d
Commit
1b16e96d
authored
Oct 02, 2020
by
Lukas Böhm
Browse files
zipping
parent
30839b9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/routes.py
View file @
1b16e96d
...
...
@@ -6,7 +6,7 @@ from app import app, db
from
flask
import
redirect
,
url_for
,
render_template
,
send_from_directory
,
current_app
,
abort
from
app.models
import
Share
,
Attachment
from
app.forms
import
UploadForm
from
shutil
import
rmtree
from
shutil
import
rmtree
,
make_archive
@
app
.
route
(
'/privacy'
)
...
...
@@ -16,7 +16,7 @@ def privacy():
@
app
.
route
(
'/about'
)
def
about
():
return
'<h1> :( </h1>'
return
render_template
(
'About.html'
)
@
app
.
route
(
'/'
)
...
...
@@ -24,6 +24,12 @@ def index():
return
redirect
(
url_for
(
'upload'
))
@
app
.
route
(
'/expired'
)
@
app
.
errorhandler
(
404
)
def
expired
(
e
=
None
):
return
render_template
(
'Expired.html'
)
@
app
.
route
(
'/upload'
,
methods
=
[
'GET'
,
'POST'
])
def
upload
():
form
=
UploadForm
()
...
...
@@ -48,6 +54,12 @@ def upload():
file
.
save
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share_id
,
fn
))
att
=
Attachment
(
filename
=
fn
,
share_id
=
share_id
)
db
.
session
.
add
(
att
)
# create zip
make_archive
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
up
.
id
),
'zip'
,
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
up
.
id
)
)
# wrap it up
db
.
session
.
commit
()
return
redirect
(
url_for
(
'shared'
,
share_id
=
share_id
))
...
...
@@ -92,14 +104,14 @@ def download(share_id):
@
app
.
route
(
'/media/<string:share_id>/<string:filename>'
,
methods
=
[
'GET'
])
def
media
(
share_id
,
filename
):
share
=
Share
.
query
.
get_or_404
(
share_id
)
if
check_expired
(
share
):
return
redirect
(
url_for
(
'expired'
))
else
:
return
send_from_directory
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share_id
),
filename
=
filename
,
as_attachment
=
True
)
check_expired
(
share
)
return
send_from_directory
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share_id
),
filename
=
filename
,
as_attachment
=
True
)
@
app
.
route
(
'/expired'
)
@
app
.
errorhandler
(
404
)
def
expired
(
e
=
None
):
return
render_template
(
'Expired.html'
)
@
app
.
route
(
'/zip/<string:share_id>'
)
def
zip
(
share_id
):
share
=
Share
.
query
.
get_or_404
(
share_id
)
check_expired
(
share
)
return
send_from_directory
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
]),
filename
=
str
(
share
.
id
)
+
'.zip'
,
as_attachment
=
True
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment