-
Notifications
You must be signed in to change notification settings - Fork 12
/
cdn.py
47 lines (44 loc) · 1.59 KB
/
cdn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Blueprint, make_response, request
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shopdeck.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from shopdeckdb.models import *
from django.core.exceptions import ObjectDoesNotExist
import os.path
print("Title CDN Services Starting Up")
#Implementing a system for games update soon
ccs = Blueprint("ccs", "ccs")
@ccs.route("/ccs/download/<tid>/tmd.<version>", methods=['GET'])
def download_tmd(tid, version):
try:
title = Title.objects.get(tid=str(tid))
except ObjectDoesNotExist:
return "Error"
try:
ds = Client3DS.objects.get(consoleid=request.args.get('deviceId'))
except ObjectDoesNotExist:
return "Error"
try:
owned = ownedTitle.objects.get(title=title, owner=ds)
except ObjectDoesNotExist:
return "error"
if owned.version < title.version:
owned.version = title.version
owned.save()
path = str(os.path.dirname(__file__))+"/cdn/"+str(tid)+"/tmd.bin"
if not os.path.isfile(path):
return "error"
f = open(path, mode="rb")
r = make_response(f.read())
r.headers.set("Content-Type", "application/octet-stream")
return r
@ccs.route("/ccs/download/<tid>/<app>", methods=['GET'])
def download_app(tid, app):
path = str(os.path.dirname(__file__))+"/cdn/"+str(tid)+"/"+str(app)+".app"
if not os.path.isfile(path):
return "error"
f = open(path, mode="rb")
r = make_response(f.read())
r.headers.set("Content-Type", "application/octet-stream")
return r