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
094835ee
Commit
094835ee
authored
Jan 02, 2021
by
Lukas Böhm
🎱
Browse files
store filesize and dont always zip if not neccecary
parent
3f3cf943
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/__init__.py
View file @
094835ee
...
...
@@ -29,7 +29,7 @@ task_queue = Queue(connection=redis)
from
app.models
import
*
db
.
create_all
()
db
.
session
.
commit
()
#
db.create_all()
#
db.session.commit()
from
app
import
routes
app/models.py
View file @
094835ee
import
os
from
datetime
import
timedelta
,
datetime
,
timezone
from
flask
import
current_app
from
werkzeug.security
import
generate_password_hash
from
app
import
db
...
...
@@ -14,6 +13,7 @@ class Share(db.Model):
download_limit
=
db
.
Column
(
'DownloadLimit'
,
db
.
Integer
,
nullable
=
False
)
is_public
=
db
.
Column
(
'Public'
,
db
.
Boolean
,
nullable
=
False
,
default
=
False
)
password
=
db
.
Column
(
'Password'
,
db
.
String
,
nullable
=
True
)
is_zipped
=
db
.
Column
(
'Zipped'
,
db
.
Boolean
,
nullable
=
False
,
default
=
False
)
files
=
db
.
relationship
(
'Attachment'
,
backref
=
'share'
)
...
...
@@ -45,6 +45,7 @@ class Attachment(db.Model):
id
=
db
.
Column
(
'ID'
,
db
.
INTEGER
,
primary_key
=
True
,
unique
=
True
)
filename
=
db
.
Column
(
'filename'
,
db
.
String
(),
nullable
=
False
)
filesize
=
db
.
Column
(
'filesize'
,
db
.
Integer
(),
nullable
=
False
,
default
=
0
)
share_id
=
db
.
Column
(
'ShareID'
,
db
.
String
(
64
),
db
.
ForeignKey
(
'Share.ID'
),
nullable
=
False
)
def
__repr__
(
self
):
...
...
@@ -56,4 +57,9 @@ class Attachment(db.Model):
self
.
share_id
=
share_id
self
.
filename
=
fn
file
.
save
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share_id
,
fn
))
path
=
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share_id
,
fn
)
try
:
file
.
save
(
path
)
self
.
filesize
=
os
.
path
.
getsize
(
path
)
except
OSError
as
e
:
print
(
e
)
\ No newline at end of file
app/routes.py
View file @
094835ee
...
...
@@ -47,9 +47,9 @@ def about():
return
render_template
(
'About.html'
)
#
@app.route('/')
#
def index():
#
return redirect(url_for('upload'))
@
app
.
route
(
'/'
)
def
index
():
return
redirect
(
url_for
(
'upload'
))
@
app
.
errorhandler
(
HTTPException
)
...
...
@@ -68,9 +68,10 @@ def public():
return
render_template
(
'Public.html'
,
shares
=
shares
)
@
app
.
route
(
'/'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/upload'
,
methods
=
[
'GET'
,
'POST'
])
def
upload
():
from
flask
import
request
req
=
request
form
=
UploadForm
()
if
form
.
validate_on_submit
():
# create share
...
...
@@ -87,11 +88,13 @@ def upload():
for
file
in
form
.
files
.
data
:
db
.
session
.
add
(
Attachment
(
share_id
=
share
.
id
,
file
=
file
))
# create zip
make_archive
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share
.
id
),
'zip'
,
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share
.
id
)
)
if
len
(
share
.
files
)
>=
3
or
(
len
(
share
.
files
)
>=
2
and
sum
([
att
.
filesize
for
att
in
share
.
files
])
>
(
25
*
1000
*
1000
)):
share
.
is_zipped
=
True
make_archive
(
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share
.
id
),
'zip'
,
os
.
path
.
join
(
current_app
.
config
[
'MEDIA_LOCATION'
],
share
.
id
)
)
# put timer into scheduler queue
if
share
.
expires
:
que
.
enqueue_in
(
time_delta
=
timedelta
(
minutes
=
form
.
timer
.
data
),
func
=
delete_share
,
args
=
[
share
.
id
])
...
...
app/templates/About.html
View file @
094835ee
...
...
@@ -2,7 +2,7 @@
{% block page %}
<h1>
Über
</h1>
<p>
Diese
s
eite ist aus Trauer um Firefox Send entstanden.
</p>
<p>
Diese
S
eite ist aus Trauer um Firefox Send entstanden.
</p>
{% block preview %}
<meta
property=
"og:type"
content=
"website"
>
...
...
app/templates/Download.html
View file @
094835ee
...
...
@@ -16,6 +16,8 @@
<div
class=
"card mb-4 shadow-sm text-center"
>
<div
class=
"card-header"
>
<h4
class=
"my-0 font-weight-normal"
>
{{ up.name }}
</h4>
<p>
verbleibende Downloads: {{ up.download_limit }}
</p>
<p>
verfügbar bis: {{ up.expires }}
</p>
</div>
<div
class=
"card-body"
>
...
...
@@ -36,11 +38,13 @@
{% endfor %}
</ul>
{% if up.is_zipped %}
<div
class=
"input-group"
>
<a
href=
"{{ url_for('zip_attachments', share_id=up.id) }}"
download
class=
"btn btn-block btn-outline-primary"
>
Dateien gepackt herunterladen
</a>
</div>
{% endif %}
</div>
</div>
...
...
app/templates/Public.html
View file @
094835ee
...
...
@@ -15,37 +15,40 @@
</p>
</div>
{# TODO live search bar
<div
class=
"row"
>
<input
type=
"text"
class=
"form-control"
placeholder=
"Suche ..."
/>
</div>
#}
{% for row in shares|batch(3) %}
<div
class=
"row"
>
{% for item in row %}
<div
class=
"col md-4 my-4"
>
<div
class=
"border rounded p-4 h-100"
>
<h3
class=
"mb-4 font-weight-normal"
>
{{ item.name }}
</h3>
<p
class=
"lead"
>
{{ len(item.files) }} Dateien
</p>
<p
class=
"card-text"
>
<small
class=
"text-muted"
>
Downloads verbleibend: {{ item.download_limit }},
</small>
<br>
<small
class=
"text-muted"
>
Verfügbar bis: {{ item.expires }}
</small>
</p>
<a
href=
"{{ url_for('download', share_id=item.id) }}"
>
<button
class=
"btn btn-lg btn-primary"
type=
"button"
>
Öffnen
</button>
</a>
{% if shares %}
{% for row in shares|batch(3) %}
<div
class=
"row"
>
{% for item in row %}
<div
class=
"col md-4 my-4"
>
<div
class=
"border rounded p-4 h-100"
>
<h3
class=
"mb-4 font-weight-normal"
>
{{ item.name }}
</h3>
<p
class=
"lead"
>
{{ len(item.files) }} Dateien
</p>
<p
class=
"card-text"
>
<small
class=
"text-muted"
>
Downloads verbleibend: {{ item.download_limit }},
</small>
<br>
<small
class=
"text-muted"
>
Verfügbar bis: {{ item.expires }}
</small>
</p>
<a
href=
"{{ url_for('download', share_id=item.id) }}"
>
<button
class=
"btn btn-lg btn-primary"
type=
"button"
>
Öffnen
</button>
</a>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% else %}
<div
class=
"row text-center mx-auto"
>
<p>
Es wurden noch keine öffentlichen Shares hochgeladen.
</p>
</div>
{% endf
or
%}
{% end
i
f %}
{% endblock content %}
\ No newline at end of file
app/templates/Upload.html
View file @
094835ee
...
...
@@ -28,11 +28,7 @@
{{ form.download_limit(class='selectpicker col') }}
</div>
<div
class=
"progress form-group d-none"
>
<div
class=
"progress-bar"
role=
"progressbar"
aria-valuemin=
"0"
aria-valuemax=
"100"
></div>
</div>
<div
class=
"row"
>
<div
class=
"row form-group"
>
<p
class=
"custom-control custom-switch col"
>
{{ form.is_public(class='custom-control-input') }}
{{ form.is_public.label(class='custom-control-label') }}
...
...
@@ -42,6 +38,10 @@
</div>
</div>
<div
class=
"progress form-group d-none"
>
<div
class=
"progress-bar"
role=
"progressbar"
aria-valuemin=
"0"
aria-valuemax=
"100"
></div>
</div>
<div
class=
"form-group"
>
{{ form.submit(class='btn btn-lg btn-block btn-primary') }}
<button
type=
"button"
class=
"btn btn-lg btn-block btn-secondary d-none"
id=
"abort"
>
Abbruch
</button>
...
...
migrations/versions/5834713e12c7_.py
View file @
094835ee
...
...
@@ -23,7 +23,7 @@ def upgrade():
sa
.
Column
(
'Name'
,
sa
.
String
(
length
=
64
),
nullable
=
True
),
sa
.
Column
(
'Expires'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'DownloadLimit'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'Public'
,
sa
.
Boolean
(),
nullable
=
False
),
sa
.
Column
(
'Public'
,
sa
.
Boolean
(),
nullable
=
False
,
server_default
=
str
(
False
)
),
sa
.
Column
(
'Password'
,
sa
.
String
(),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'ID'
),
sa
.
UniqueConstraint
(
'ID'
)
...
...
migrations/versions/cbc456705c64_add_filesize_and_zipping_property.py
0 → 100644
View file @
094835ee
"""add filesize and zipping property
Revision ID: cbc456705c64
Revises: 5834713e12c7
Create Date: 2021-01-02 01:51:17.571727
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'cbc456705c64'
down_revision
=
'5834713e12c7'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
add_column
(
'Attachment'
,
sa
.
Column
(
'filesize'
,
sa
.
Integer
(),
nullable
=
False
,
server_default
=
str
(
0
)))
op
.
add_column
(
'Share'
,
sa
.
Column
(
'Zipped'
,
sa
.
Boolean
(),
nullable
=
False
,
server_default
=
str
(
False
)))
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
drop_column
(
'Share'
,
'Zipped'
)
op
.
drop_column
(
'Attachment'
,
'filesize'
)
# ### end Alembic commands ###
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