Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/sugarlabs-appstore/aslo-v4
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Jul 22, 2020
2 parents 985231f + 346214d commit 9b0c368
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions aslo4-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git/
1 change: 1 addition & 0 deletions aslo4-server/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn --preload wsgi:app
55 changes: 55 additions & 0 deletions aslo4-server/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import flask
from flask import request, Response
import urllib.request

app = flask.Flask(__name__)
app.config["DEBUG"] = True

DOMAIN = "http://sugarstore.netlify.app/api"
OLD_DOMAIN = \
"http://activities.sugarlabs.org/services/" \
"update-aslo.php?id={i}&appVersion={v}"

RDF_HEADERS = """<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" \
xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF:RDF>"""


@app.route('/update-aslo.php', methods=['GET'])
def update_aslo():
xml = RDF_HEADERS
bundle_id = request.args.get("id")
app_version = request.args.get("appVersion")
try:
float(app_version)
except ValueError:
response = Response(xml, mimetype='text/xml')
response.headers.add('Access-Control-Allow-Origin', '*')
return response

if float(app_version) < 0.116:
with urllib.request.urlopen(
OLD_DOMAIN.format(i=bundle_id, v=app_version)
) as f:
xml = f.read().decode('utf-8')
else:
with urllib.request.urlopen(
'{domain}/{bundle_id}.xml'.format(
domain=DOMAIN, bundle_id=bundle_id)
) as f:
xml = f.read().decode('utf-8')

response = Response(xml, mimetype='text/xml')
response.headers.add('Access-Control-Allow-Origin', '*')
return response


@app.route('/wake', methods=['GET'])
def wake():
response = flask.jsonify({"test": "Ok"})
response.headers.add('Access-Control-Allow-Origin', '*')
return response


if __name__ == "__main__":
app.run()
3 changes: 3 additions & 0 deletions aslo4-server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gunicorn
flask
flask-cors
1 change: 1 addition & 0 deletions aslo4-server/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.8.4
4 changes: 4 additions & 0 deletions aslo4-server/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from app import app

if __name__ == "__main__":
app.run()
2 changes: 1 addition & 1 deletion aslo4/rdf/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def parse(self):
max_version=self.compatibility['max'],
update_link=self.url,
sha_type="sha256",
sha_hash=get_sha256(self.bundle_path),
sha_hash=get_sha256(self.bundle_path)['sha256'],
update_size=self.get_bundle_size(),
update_info="{}/{}.html".format(self.info_url, self.bundle_id)
)

0 comments on commit 9b0c368

Please sign in to comment.