From bd579fe179d0fc829607cc57f8b56efb254d3b69 Mon Sep 17 00:00:00 2001 From: MattTheTekie <94870997+MattTheTekie@users.noreply.github.com> Date: Sat, 26 Aug 2023 15:18:08 -0400 Subject: [PATCH] Add files via upload --- README.txt | 1 + app.py | 102 ++++++++++++++++++++++++++++++++++++++++++ demoData.mod | 39 ++++++++++++++++ start.sh | 1 + templates/header.html | 17 +++++++ templates/index.html | 74 ++++++++++++++++++++++++++++++ templates/toc.html | 17 +++++++ 7 files changed, 251 insertions(+) create mode 100644 README.txt create mode 100644 app.py create mode 100644 demoData.mod create mode 100644 start.sh create mode 100644 templates/header.html create mode 100644 templates/index.html create mode 100644 templates/toc.html diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..18b1256 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +demoData.json should be used as the UniStore location. You can figure out GitHub Actions to download the file to a repo if you need. You can also add http(or s)://HOST/downloadJson \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..b00f496 --- /dev/null +++ b/app.py @@ -0,0 +1,102 @@ +from flask import Flask, render_template, request, send_file, send_from_directory, jsonify +import os +import json +import hashlib + +app = Flask(__name__) + +UPLOAD_FOLDER = 'temp_uploads' +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +SECRET_TOKEN = "YOUR_TOKEN_HERE" +ALLOWED_ORIGIN = "SET_DOMAIN" + +@app.route('/') +def main(): + return render_template("index.html", mode="dark") + +@app.route('/toc.html') +def toc(): + return render_template("toc.html", mode="dark") + +@app.route('/downloadFile/', methods=['GET']) +def download_file(filename): + try: + return send_from_directory('uploadedFiles', filename) + except FileNotFoundError: + return jsonify({"error": "File not found."}), 404 + +@app.route('/downloadJson') +def download_json(): + try: + return send_file("demoData.json", as_attachment=True) + except FileNotFoundError: + return jsonify({"error": "File not found."}), 404 + +@app.route('/uploadJson', methods=['POST']) +def upload_json(): + # Verify the Referer header + referer = request.headers.get("Referer") + if not referer or not referer.startswith(ALLOWED_ORIGIN): + return jsonify({"error": "Unauthorized access."}), 401 + + provided_token = request.form.get("token") + if provided_token != SECRET_TOKEN: + return jsonify({"error": "Unauthorized access."}), 401 + + # Load existing JSON data + with open("demoData.json", "r") as json_file: + js_in = json.load(json_file) + + cur_entries = len(js_in["storeContent"]) - 2 + + f = request.files["streetPassFile"] + file_hash = hashlib.sha256(f.read()).hexdigest() + + new_filename = "streetpass_" + str(cur_entries + 2) + f.save(os.path.join("uploadedFiles", new_filename)) + + extra_data = request.form.get("extraInfo", "") + + append_data = { + "info": { + "title": f"StreetPass Data {cur_entries + 2}", + "author": "MattTheTekie", + "description": f"Make sure to run the StreetPass2 GodMode9 script by Noxious Ninja after downloading the StreetPass data! {extra_data}", + "category": ["3DS"], + "console": ["3DS"], + "icon_index": 1, + "sheet_index": 0, + "last_updated": "2023-08-21", + "version": "v6.6.6" + }, + f"streetpass_{cur_entries + 2}": [ + { + "type": "downloadFile", + "hash": file_hash, + "file": f"http://streetpass.test72.eu.org/downloadFile/{new_filename}", + "message": "Downloading StreetPass Data... Make sure to run the StreetPass2 GodMode9 script by Noxious Ninja!", + "output": f"sdmc:/gm9/in/streetpass/{new_filename}" + } + ] + } + + js_in["storeContent"].append(append_data) + + with open("demoData.json", "w") as json_file: + json.dump(js_in, json_file, indent='\t') + + return 'StreetPass data submitted! For help check our Discord server here https://discord.gg/INSERT_DISCORD_HERE', 200 + +# ... (@app.route('/testJson') +def test_json(): + json_file = open("demoData.json", "r") + js_in = json.load(json_file) + json_file.close() + + ret_str = "Content length: " + str(len(js_in["storeContent"])) + + return ret_str, 200 + +if __name__ == '__main__': + app.run(host="127.0.0.1", port=8070, debug=True) diff --git a/demoData.mod b/demoData.mod new file mode 100644 index 0000000..9dec4c8 --- /dev/null +++ b/demoData.mod @@ -0,0 +1,39 @@ +{ + "storeInfo": { + "title": "StreetPass-Shop", + "author": "MattTheTekie", + "url": "https://raw.githubusercontent.com/sdkpaint/streetpass-3.0-config/master/unistore/StreetPass-Shop.unistore", + "file": "StreetPass-Shop.unistore", + "sheet": "StreetPass-Shop.t3x", + "sheetURL": "https://raw.githubusercontent.com/sdkpaint/streetpass-3.0-config/master/unistore/StreetPass-Shop.t3x", + "description": "Here you can find loads of StreetPass data!\nEnjoy browsing through the StreetPass shop! ~MattTheTekie!", + "version": 3, + "revision": 4 + }, + "storeContent": [ + { + "info": { + "title": "Noxious Ninja's StreetPass2 GodMode9 script", + "author": "NoxiousNinja", + "description": "Noxious Ninja's StreetPass2 GodMode9 script", + "category": [ + "3DS" + ], + "console": [ + "3DS" + ], + "icon_index": 0, + "sheet_index": 0, + "last_updated": "2023-08-21", + "version": "v0.0.0" + }, + "StreetPass2.gm9": [ + { + "type": "downloadFile", + "file": "https://gist.github.com/noxiousninja/c7969b0028b067335d360f020753ef49/raw/5ccf556d6ee3f0a98a7c50de125891e557645e6a/StreetPass2.gm9", + "output": "sdmc:/gm9/scripts/StreetPass2.gm9" + } + ] + } + ] +} \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..1300e1b --- /dev/null +++ b/start.sh @@ -0,0 +1 @@ +python3 app.py &>/dev/null & diff --git a/templates/header.html b/templates/header.html new file mode 100644 index 0000000..de72094 --- /dev/null +++ b/templates/header.html @@ -0,0 +1,17 @@ + + + + + + + + StreetPass Shop + + + + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..a533209 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,74 @@ + + + + + + + + {% include 'header.html' %} + +
+
+ StreetPass Shop Store! +

Download the UniStore file here!

+
The UniStore updates every three hours.
+

In need of support? Check out our Discord here!

+
+
+
+
+ + +
Upload your StreetPass data extracted from the GodMode9 script here.
+
+ + + +
+ +
+
Optionally put any extra info that you want to show with the StreetPass data in the shop here!
+ +
+
+ + +
+ +
+
+
+ + + + diff --git a/templates/toc.html b/templates/toc.html new file mode 100644 index 0000000..d4c4c2e --- /dev/null +++ b/templates/toc.html @@ -0,0 +1,17 @@ + + + {% include 'header.html' %} + +
+
+ StreetPass Shop TOC +
+
+

TOC

+
+

I will NOT upload anything other then StreetPass data, and will NOT use this as a filehost!

+

+ +
+ +