Skip to content

Commit

Permalink
app: accept optional request data with utc timestamp, move version here
Browse files Browse the repository at this point in the history
* These parameters are (and should be) optional. Move them to request data
  where they can be ignored safely
  • Loading branch information
invisiblek committed Jan 3, 2017
1 parent b50768a commit 84ebbc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -19,10 +19,14 @@ Listens on port `5000` by default, this can be changed in local_config.py<br>
Example API Calls:
--
Obtaining rom list for a device:<br>
`/api/v1/<device>/<romtype>/<romversion (optional)>`<br>
`/api/v1/<device>/<romtype>`<br>
Request data (optional):<br>
`{"ro.build.date.utc": "<utc_timestamp>", "romversion": "<romversion>"}`<br><br>
`<device>` - Name of device. Example: `d2vzw`<br>
`<romtype>` - Type of rom. Example: `nightly`<br>
`<romversion>` - Version of rom. Example: `14.1`(optional)<br>
`<utc_timestamp>` - Timestamp for current build on device. Taken from build.prop usually. Example: `1483179136`(optional)


Requesting a file:<br>
`/api/v1/requestfile/<id>`<br>
Expand All @@ -31,5 +35,4 @@ Requesting a file:<br>

TODO
====
- Only present roms that are newer than the current rom
- Lots more I'm sure
- Lots I'm sure
17 changes: 11 additions & 6 deletions app.py
@@ -1,5 +1,6 @@
#!/usr/bin/python3

import datetime
import json
import local_config
import os
Expand All @@ -23,14 +24,18 @@

connect('lineage_updater', host=config['dbhost'])

@app.route("/api/<string:apiversion>/<string:device>/<string:romtype>/<string:romversion>")
@app.route("/api/<string:apiversion>/<string:device>/<string:romtype>")
def index(apiversion, device, romtype, romversion=None):
def index(apiversion, device, romtype):
if apiversion == "v1":
if romversion:
roms = Rom.objects(device=device, romtype=romtype, version=romversion)
else:
roms = Rom.objects(device=device, romtype=romtype)
r = request.get_json()
roms = Rom.objects(device=device, romtype=romtype)

if r:
if 'ro.build.date.utc' in r and r['ro.build.date.utc'].isdigit():
devicedate = datetime.datetime.utcfromtimestamp(int(r['ro.build.date.utc']))
roms = roms(datetime__gt=devicedate)
if 'romversion' in r:
roms = roms(version=r['romversion'])

return roms.to_json()

Expand Down

0 comments on commit 84ebbc6

Please sign in to comment.