Skip to content

Commit

Permalink
add file size to download pages
Browse files Browse the repository at this point in the history
* defaults to 0.00 MB if no size is defined in the database

Change-Id: Iaab0d3139cdba437c7f42d4e996e67b133f53d1f
  • Loading branch information
invisiblek committed Nov 8, 2017
1 parent 7b2553e commit aa09569
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/add_rom.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"filename": "cm-14.1-mako-signed.zip",
"datetime": "2012-07-07",
"url": "https://mirrorbits.lineageos.org/full/mako/20120707/cm-14.1-mako-signed.zip",
"romtype": "nightly"
"romtype": "nightly",
"size": "123456789"
}
3 changes: 2 additions & 1 deletion seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ VERSION=14.1
DATETIME="2017-07-07"
ROMTYPE="nightly"
MD5SUM=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
SIZE="123456789"
URL=https://mirrobits.lineageos.org/full/${DEVICE}/${DATETIME}/${FILENAME}


flask addrom --filename $FILENAME --device $DEVICE --version $VERSION --datetime $DATETIME --romtype $ROMTYPE --md5sum $MD5SUM --url $URL
flask addrom --filename $FILENAME --device $DEVICE --version $VERSION --datetime $DATETIME --romtype $ROMTYPE --md5sum $MD5SUM --url $URL --size $SIZE

done
7 changes: 4 additions & 3 deletions updater/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def decorated_function(*args, **kwargs):
@click.option('--datetime', '-t', 'datetime', required=True)
@click.option('--romtype', '-r', 'romtype', required=True)
@click.option('--md5sum', '-m', 'md5sum', required=True)
@click.option('--size', '-s', 'size', required=True)
@click.option('--url', '-u', 'url', required=True)
def addrom(filename, device, version, datetime, romtype, md5sum, url):
Rom(filename=filename, datetime=datetime, device=device, version=version, romtype=romtype, md5sum=md5sum, url=url).save()
def addrom(filename, device, version, datetime, romtype, md5sum, size, url):
Rom(filename=filename, datetime=datetime, device=device, version=version, romtype=romtype, md5sum=md5sum, romsize=size, url=url).save()

@app.cli.command()
@click.option('--filename', '-f', 'filename', required=True)
Expand Down Expand Up @@ -165,7 +166,7 @@ def test_auth():
@api_key_required
def add_build():
data = request.get_json()
validate = {"filename": "str", "device": "str", "version": "str", "md5sum": "str", "url": "str", "romtype": "str"}
validate = {"filename": "str", "device": "str", "version": "str", "md5sum": "str", "url": "str", "romtype": "str", "romsize": "int"}

#bad data sent
if not data:
Expand Down
4 changes: 3 additions & 1 deletion updater/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

from mongoengine import Document, BooleanField, DateTimeField, StringField
from mongoengine import Document, BooleanField, DateTimeField, StringField, IntField

from datetime import datetime, timedelta

Expand All @@ -15,6 +15,7 @@ class Rom(Document):
romtype = StringField(required=True)
md5sum = StringField(required=True)
url = StringField()
romsize = IntField()

@classmethod
def get_roms(cls, device, romtype=None, before=3600):
Expand Down Expand Up @@ -60,6 +61,7 @@ class Incremental(Document):
romtype = StringField(required=True)
md5sum = StringField(required=True)
url = StringField()
romsize = IntField()
from_incremental = StringField(required=True)
to_incremental = StringField(required=True)

Expand Down
2 changes: 2 additions & 0 deletions updater/templates/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h4>Builds for {{active_device.model}}</h4>
<th>Type</th>
<th>Version</th>
<th>File</th>
<th>Size</th>
<th>Date</th>
</tr>
</thead>
Expand All @@ -33,6 +34,7 @@ <h4>Builds for {{active_device.model}}</h4>
<td>
<a href="{{rom.url}}">{{rom.filename}}</a> <br /><small><a href="{{rom.url}}?sha256">sha256</a> <a href="{{rom.url}}?sha1">sha1</a></small>
</td>
<td>{% if rom.romsize %} {{'%0.2f'| format(rom.romsize/1024/1024|float)}} {% else %} 0.00 {% endif %} MB</td>
<td>{{rom.datetime.strftime("%Y-%m-%d %H:%M:%S %Z")}}</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit aa09569

Please sign in to comment.