Add files via upload
This commit is contained in:
parent
e5337494e7
commit
bd579fe179
7 changed files with 251 additions and 0 deletions
1
README.txt
Normal file
1
README.txt
Normal file
|
|
@ -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
|
||||
102
app.py
Normal file
102
app.py
Normal file
|
|
@ -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/<filename>', 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)
|
||||
39
demoData.mod
Normal file
39
demoData.mod
Normal file
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
start.sh
Normal file
1
start.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
python3 app.py &>/dev/null &
|
||||
17
templates/header.html
Normal file
17
templates/header.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||||
<title>StreetPass Shop</title>
|
||||
|
||||
<!-- navi bar -->
|
||||
<nav class="navbar {% if mode == 'light' %}navbar-light bg-light{% elif mode == 'dark' %}navbar-dark bg-dark{% endif %}">
|
||||
<div class="container-fluid">
|
||||
<span class="navbar-brand text-center mb-0 h1">StreetPass Shop Uploader</span>
|
||||
</div>
|
||||
</nav>
|
||||
</head>
|
||||
</html>
|
||||
74
templates/index.html
Normal file
74
templates/index.html
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/sha256.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/pbkdf2.js"></script>
|
||||
{% include 'header.html' %}
|
||||
<body {% if mode == 'dark' %}class="text-white bg-secondary"{% endif %}>
|
||||
<div class="card {% if mode == 'dark' %}text-white bg-dark{% endif %} mb-3" style="width:90%; left: 5%; top:5px;">
|
||||
<div class="card-header">
|
||||
StreetPass Shop Store!
|
||||
<h3>Download the UniStore file <a href="INSERT_UNISTORE_LINK_HERE">here</a>!</h3>
|
||||
<div id="card-header" class="form-text">The UniStore updates every three hours.</div>
|
||||
<h3>In need of support? Check out our Discord <a href="https://discord.gg/INSERT_DISCORD_HERE">here</a>!</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="uploadForm" action="/uploadJson" method="post" enctype="multipart/form-data" onsubmit="return validateForm()">
|
||||
<div class="mb-3">
|
||||
<label for="streetPassFile" class="form-label">StreetPass Data Uploader</label>
|
||||
<input type="file" class="form-control" id="streetPassFile" name="streetPassFile" aria-describedby="streetPassFileHelp" required>
|
||||
<div id="streetPassFileHelp" class="form-text">Upload your StreetPass data extracted from the GodMode9 script here.</div>
|
||||
</div>
|
||||
<!-- Add a hidden input field to store the file hash -->
|
||||
<input type="hidden" id="fileHash" name="fileHash" value="">
|
||||
<input type="hidden" id="token" name="token" value="INSERT_TOKEN_HERE">
|
||||
<hr>
|
||||
<label for="extrainfo" class="form-label">Extra info</label>
|
||||
<div class="mb-3">
|
||||
<div id="streetPassFileHelp" class="form-text">Optionally put any extra info that you want to show with the StreetPass data in the shop here!</div>
|
||||
<textarea class="form-control" id="extraInfo" name="extraInfo"></textarea>
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="exampleCheck1" required>
|
||||
<label class="form-check-label" for="exampleCheck1">I agree to the <a href="toc.html">Terms</a> and <a href="toc.html">Conditions</a> that I probably did not read.</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<footer>Made by <a href="https://github.com/MattTheTekie">MattTheTekie</a> & <a href="https://github.com/Dakotath">Dakotath</a></footer>
|
||||
<script>
|
||||
function validateForm() {
|
||||
var fileInput = document.getElementById('streetPassFile');
|
||||
var fileSize = fileInput.files[0].size / (1024 * 1024); // Convert to MB
|
||||
if (fileSize < 54 || fileSize > 56) {
|
||||
alert('This is NOT StreetPass data. Stop using this site as a file host, or risk getting IP blocked!');
|
||||
return false; // Prevent form submission
|
||||
}
|
||||
|
||||
var tosCheckbox = document.getElementById('exampleCheck1');
|
||||
if (!tosCheckbox.checked) {
|
||||
alert('You must agree to the Terms and Conditions.');
|
||||
return false; // Prevent form submission
|
||||
}
|
||||
|
||||
// Calculate SHA-256 hash of the uploaded file and set it in the hidden input field
|
||||
var file = fileInput.files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(event) {
|
||||
var fileContent = event.target.result;
|
||||
var hash = CryptoJS.SHA256(fileContent).toString(CryptoJS.enc.Hex);
|
||||
document.getElementById('fileHash').value = hash;
|
||||
|
||||
// Now trigger the form submission
|
||||
document.getElementById('uploadForm').submit();
|
||||
};
|
||||
reader.readAsBinaryString(file);
|
||||
|
||||
return false; // Prevent default form submission
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
17
templates/toc.html
Normal file
17
templates/toc.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
{% include 'header.html' %}
|
||||
<body {% if mode == 'dark' %}class="text-white bg-secondary"{% endif %}>
|
||||
<div class="card {% if mode == 'dark' %}text-white bg-dark{% endif %} mb-3" style="width:90%; left: 5%; top:5px;">
|
||||
<div class="card-header">
|
||||
StreetPass Shop TOC
|
||||
</div>
|
||||
<hr>
|
||||
<h1>TOC</h1>
|
||||
<div class="mb-3">
|
||||
<p>I will NOT upload anything other then StreetPass data, and will NOT use this as a filehost!<p>
|
||||
</div>
|
||||
<footer>Made by <a href="https://github.com/MattTheTekie">MattTheTekie</a> & <a href="https://github.com/Dakotath">Dakotath</a></footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue