Skip to content

Commit

Permalink
Merge pull request #70 from Thorfusion/dev
Browse files Browse the repository at this point in the history
Adds more MCIL stuff
  • Loading branch information
maggi373 authored Jun 1, 2024
2 parents 26ecde7 + 225a928 commit b222712
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 87 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '21 15 * * 5'

Expand Down
2 changes: 1 addition & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@api.route("/api/")
def api_info():
return jsonify({"api": "solder.py", "version": "v1.2.3", "stream": "DEV"})
return jsonify({"api": "solder.py", "version": "v1.3.0", "stream": "DEV"})


@api.route("/api/verify")
Expand Down
25 changes: 18 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.3"
__version__ = "1.3.0"

import os
from dotenv import load_dotenv
Expand Down Expand Up @@ -48,7 +48,7 @@
app.register_blueprint(api)

app.config["UPLOAD_FOLDER"] = "./mods/"
ALLOWED_EXTENSIONS = {'zip'}
ALLOWED_EXTENSIONS = {'zip', 'jar'}

app.secret_key = secrets.token_hex()

Expand Down Expand Up @@ -176,8 +176,9 @@ def newmodversion(id):
# New or invalid session, send to login
return redirect(url_for("login"))
if "form-submit" in request.form:
radio = request.form['flexRadioDefault']
Mod.update(id, request.form["name"], request.form["description"], request.form["author"], request.form["link"], request.form["pretty_name"], radio, request.form["internal_note"])
mod_side = request.form['flexRadioDefault']
mod_type = request.form['type']
Mod.update(id, request.form["name"], request.form["description"], request.form["author"], request.form["link"], request.form["pretty_name"], mod_side, mod_type, request.form["internal_note"])
return redirect(id)
if "deleteversion_submit" in request.form:
if "delete_id" not in request.form:
Expand Down Expand Up @@ -225,8 +226,9 @@ def newmod():
# New or invalid session, send to login
return redirect(url_for("login"))
if request.method == "POST":
radio = request.form['flexRadioDefault']
Mod.new(request.form["name"], request.form["description"], request.form["author"], request.form["link"], request.form["pretty_name"], radio, request.form["internal_note"])
mod_side = request.form['flexRadioDefault']
mod_type = request.form['type']
Mod.new(request.form["name"], request.form["description"], request.form["author"], request.form["link"], request.form["pretty_name"], mod_side, mod_type, request.form["internal_note"])
return redirect(url_for("modlibrary"))

return render_template("newmod.html")
Expand Down Expand Up @@ -493,7 +495,7 @@ def modlibrary_post():
markedbuild="0"
if "markedbuild" in request.form:
markedbuild=request.form['markedbuild']
Modversion.new(request.form["modid"], request.form["mcversion"] + "-" + request.form["version"], request.form["mcversion"], request.form["md5"], request.form["filesize"], markedbuild)
Modversion.new(request.form["modid"], request.form["mcversion"] + "-" + request.form["version"], request.form["mcversion"], request.form["md5"], request.form["filesize"], markedbuild, "0", request.form["jarmd5"])
if 'file' not in request.files:
print('No file part')
return redirect(url_for("modlibrary"))
Expand All @@ -509,6 +511,15 @@ def modlibrary_post():
if R2_BUCKET != None:
keyname = "mods/" + request.form["mod"] + "/" + filename
R2.upload_file(app.config["UPLOAD_FOLDER"] + request.form["mod"] + "/" + filename, R2_BUCKET, keyname, ExtraArgs={'ContentType': 'application/zip'})
jarfilew = request.files['jarfile']
if jarfilew and allowed_file(jarfilew.filename):
jarfilename = secure_filename(jarfilew.filename)
print("saving jar")
createFolder(app.config["UPLOAD_FOLDER"] + secure_filename(request.form["mod"]) + "/")
jarfilew.save(os.path.join(app.config["UPLOAD_FOLDER"] + secure_filename(request.form["mod"]) + "/", jarfilename))
if R2_BUCKET != None:
jarkeyname = "mods/" + request.form["mod"] + "/" + jarfilename
R2.upload_file(app.config["UPLOAD_FOLDER"] + request.form["mod"] + "/" + jarfilename, R2_BUCKET, jarkeyname, ExtraArgs={'ContentType': 'application/zip'})
return redirect(url_for("modlibrary"))

return redirect(url_for("modlibrary"))
Expand Down
4 changes: 4 additions & 0 deletions models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def create_tables() -> bool:
author VARCHAR(255),
link VARCHAR(255),
side enum('CLIENT', 'SERVER', 'BOTH'),
modtype enum('MOD', 'LAUNCHER', 'RES', 'CONFIG', 'MCIL', 'NONE') DEFAULT 'NONE',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
note TEXT
Expand All @@ -102,6 +103,7 @@ def create_tables() -> bool:
version VARCHAR(255) NOT NULL,
mcversion VARCHAR(255),
md5 VARCHAR(255) NOT NULL,
jarmd5 VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
filesize INT
Expand Down Expand Up @@ -268,6 +270,7 @@ def migratetechnic_tables() -> bool:
cur.execute(
"""ALTER TABLE mods
ADD COLUMN side enum('CLIENT', 'SERVER', 'BOTH') AFTER link,
ADD COLUMN modtype enum('MOD', 'LAUNCHER', 'RES', 'CONFIG', 'MCIL', 'NONE') DEFAULT 'NONE',
ADD COLUMN note VARCHAR(255)
"""
)
Expand All @@ -283,6 +286,7 @@ def migratetechnic_tables() -> bool:
)
cur.execute(
"""ALTER TABLE modversions
ADD COLUMN jarmd5 VARCHAR(255) AFTER md5,
ADD COLUMN mcversion VARCHAR(255) AFTER version
"""
)
Expand Down
24 changes: 13 additions & 11 deletions models/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .modversion import Modversion

class Mod:
def __init__(self, id, name, description, author, link, created_at, updated_at, pretty_name, side, note):
def __init__(self, id, name, description, author, link, created_at, updated_at, pretty_name, side, modtype, note):
self.id = id
self.name = name
self.description = description
Expand All @@ -13,27 +13,28 @@ def __init__(self, id, name, description, author, link, created_at, updated_at,
self.updated_at = updated_at
self.pretty_name = pretty_name
self.side = side
self.modtype = modtype
self.note = note

@classmethod
def new(cls, name, description, author, link, pretty_name, side, note):
def new(cls, name, description, author, link, pretty_name, side, modtype, note):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
now = datetime.datetime.now()
cur.execute("INSERT INTO mods (name, description, author, link, created_at, updated_at, pretty_name, side, note) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", (name, description, author, link, now, now, pretty_name, side, note))
cur.execute("INSERT INTO mods (name, description, author, link, created_at, updated_at, pretty_name, side, modtype, note) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (name, description, author, link, now, now, pretty_name, side, modtype, note))
conn.commit()
cur.execute("SELECT LAST_INSERT_ID() AS id")
id = cur.fetchone()["id"]
return cls(id, name, description, author, link, now, now, pretty_name, side, note)
return cls(id, name, description, author, link, now, now, pretty_name, side, modtype, note)

@classmethod
def update(cls, id, name, description, author, link, pretty_name, side, note):
def update(cls, id, name, description, author, link, pretty_name, side, modtype, note):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
now = datetime.datetime.now()
cur.execute("""UPDATE mods
SET name = %s, description = %s, author = %s, link = %s, updated_at = %s, pretty_name = %s, side = %s, note = %s
WHERE id = %s;""", (name, description, author, link, now, pretty_name, side, note, id))
SET name = %s, description = %s, author = %s, link = %s, updated_at = %s, pretty_name = %s, side = %s, modtype = %s, note = %s
WHERE id = %s;""", (name, description, author, link, now, pretty_name, side, modtype, note, id))
conn.commit()
cur.execute("SELECT LAST_INSERT_ID() AS id")
id = cur.fetchone()["id"]
Expand All @@ -60,7 +61,7 @@ def get_by_id(cls, id):
cur.execute("SELECT * FROM mods WHERE id = %s", (id,))
row = cur.fetchone()
if row:
return cls(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["note"])
return cls(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["modtype"], row["note"])
return None

@staticmethod
Expand All @@ -70,7 +71,7 @@ def get_multi_by_id(ids: tuple):
cur.execute(f"SELECT * FROM mods WHERE id IN ({','.join(['%s'] * len(ids))})", ids)
rows = cur.fetchall()
if rows:
return [Mod(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["note"]) for row in rows]
return [Mod(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["modtype"], row["note"]) for row in rows]
return None

@classmethod
Expand All @@ -80,7 +81,7 @@ def get_by_name(cls, name):
cur.execute("SELECT * FROM mods WHERE name = %s", (name,))
row = cur.fetchone()
if row:
return cls(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["note"])
return cls(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["modtype"], row["note"])
return None

@staticmethod
Expand All @@ -90,7 +91,7 @@ def get_all():
cur.execute("SELECT * FROM mods")
rows = cur.fetchall()
if rows:
return [Mod(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["note"]) for row in rows]
return [Mod(row["id"], row["name"], row["description"], row["author"], row["link"], row["created_at"], row["updated_at"], row["pretty_name"], row["side"], row["modtype"], row["note"]) for row in rows]
return []

@staticmethod
Expand Down Expand Up @@ -141,5 +142,6 @@ def to_json(self):
"updated_at": self.updated_at,
"pretty_name": self.pretty_name,
"side": self.side,
"type": self.modtype,
"note": self.note
}
12 changes: 11 additions & 1 deletion models/modversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, id, mod_id, version, mcversion, md5, created_at, updated_at,
self.optional = optional

@classmethod
def new(cls, mod_id, version, mcversion, md5, filesize, markedbuild, url="0"):
def new(cls, mod_id, version, mcversion, md5, filesize, markedbuild, url="0", jarmd5="0"):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
now = datetime.datetime.now()
Expand All @@ -32,6 +32,8 @@ def new(cls, mod_id, version, mcversion, md5, filesize, markedbuild, url="0"):
version = Modversion.get_by_id(id)
t = threading.Thread(target=version.rehash, args=(url,))
t.start()
if jarmd5 != "0":
Modversion.update_modversion_jarmd5(id, jarmd5)
return cls(id, mod_id, version, mcversion, md5, now, now, filesize)

@classmethod
Expand Down Expand Up @@ -74,6 +76,14 @@ def update_modversion_in_build(cls, oldmodver_id, modver_id, build_id):
cur.execute("UPDATE build_modversion SET modversion_id = %s WHERE modversion_id = %s AND build_id = %s", (modver_id, oldmodver_id, build_id))
conn.commit()
return None

@classmethod
def update_modversion_jarmd5(cls, id, jarmd5):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("UPDATE modversions SET jarmd5 = %s WHERE id = %s", (jarmd5, id))
conn.commit()
return None

@classmethod
def delete_modversion(cls, id):
Expand Down
10 changes: 0 additions & 10 deletions static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ main {
}

.grid2 {
grid-column: 1;
grid-row: 2;
}

.grid3 {
grid-column: 2;
grid-row: 1;
}

.grid4 {
grid-column: 2;
grid-row: 2;
}
25 changes: 25 additions & 0 deletions static/js/solderpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ function hashmd5() {
reader.readAsArrayBuffer(file);
}

function hashjarmd5(id) {
let fileSelect = document.getElementById(id)
let files = fileSelect.files
let file = files[0]

var reader = new FileReader();
reader.onload = function (event) {
document.getElementById('jarmd5').value = md5(event.target.result)
};
reader.readAsArrayBuffer(file);
}


// Calculates the filesize
function filesizecalc(input) {
Expand Down Expand Up @@ -192,20 +204,32 @@ function zipfile_mods(modslug, mcversion, modversion, input, verchange) {
var mods = zip.folder("mods");
// adds the file uploaded inside mods folder with correct naming scheme
mods.file(modslugname + "-" + mcversionname + "-" + modversionname + ".jar", data);
jardataSelect = document.getElementById("jarfile")
let jarfinalfile = new File([data], modslugname + "-" + mcversionname + "-" + modversionname + ".jar",{type:"application/zip", lastModified:new Date().getTime()});

let jarcontainer = new DataTransfer();
jarcontainer.items.add(jarfinalfile);

jardataSelect.files = jarcontainer.files;

hashjarmd5("jarfile")

document.getElementById("filetypejar").checked = true;
}
if (data.name == "modpack.jar") { // if the filename is detected to be modpack.jar
// adds a folder "bin" inside zipfile
var bin = zip.folder("bin");
// adds the file uploaded inside bin folder with correct naming scheme
bin.file("modpack.jar", data);
document.getElementById('jarmd5').value = "0";
document.getElementById("filetypelauncher").checked = true;
}
if (data.type == "application/json") { // if the filetype is detected to be json
// adds a folder "bin" inside zipfile
var bin = zip.folder("bin");
// adds the file uploaded inside bin folder with correct naming scheme
bin.file("version.json", data);
document.getElementById('jarmd5').value = "0";
document.getElementById("filetypelauncher").checked = true;

}
Expand All @@ -218,6 +242,7 @@ function zipfile_mods(modslug, mcversion, modversion, input, verchange) {
}
if (data.type == "application/x-zip-compressed") { // if the filetype is detected to be zip
zipfile_md5(data)
document.getElementById('jarmd5').value = "0";
document.getElementById("filetypezip").checked = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</ul>
</nav>
<div class="flex-column flex-shrink-0 p-3 text-white navcontainer2">
<p class="">Version 1.2.3</p>
<p class="">Version 1.3.0</p>
</div>

</div>
Expand Down
14 changes: 10 additions & 4 deletions templates/modlibrary.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
<div class="mb-3">
<input type="text" class="form-control invisible" name="modid" id="modid" readonly>
</div>
<div class="mb-3">
<a href="{{ url_for('newmod') }}"><button type="button" class="btn btn-success tablewidth2">New
mod</button></a>
</div>
<div class="mb-3">
<input class="form-control" type="file" id="jarfile" name="jarfile" hidden>
<label for="jarmd5" class="form-label">MD5 for jarfile</label>
<input type="text" class="form-control" name="jarmd5" id="jarmd5" value="" readonly>
</div>
</form>

{% if success %}
Expand All @@ -114,10 +123,7 @@
{% endif %}
<div class="divider">
</div>
<div class="">
<a href="{{ url_for('newmod') }}"><button type="button" class="btn btn-success tablewidth2">New
mod</button></a>
</div>

</div>


Expand Down
23 changes: 13 additions & 10 deletions templates/modpack.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@
<input type="text" class="form-control" name="mcversion" id="mcversion" required></input>
</div>
<div class="mb-3 gridswrapper">
<label for="clonebuild" class="form-label grid1">Clone build</label>
<label for="clonebuildman" class="form-label grid3">Clone Build ID</label>
<select class="form-select grid2" name="clonebuild" id="clonebuild">
<option value="">N/A</option>
{%for mod in modpack%}
<option value="{{mod.id}}">{{mod.version}}</option>
{%endfor%}
</select>

<input type="text" class="form-control grid4" name="clonebuildman" id="clonebuildman"></input>
<div class="mb-3 grid1">
<label for="clonebuild" class="form-label">Clone build</label>
<select class="form-select" name="clonebuild" id="clonebuild">
<option value="">N/A</option>
{%for mod in modpack%}
<option value="{{mod.id}}">{{mod.version}}</option>
{%endfor%}
</select>
</div>
<div class="mb-3 grid2">
<label for="clonebuildman" class="form-label grid3">Clone Build ID</label>
<input type="text" class="form-control" name="clonebuildman" id="clonebuildman"></input>
</div>
</div>
<div class="mb-3">
<label for="min_java" class="form-label">Minium Java Version</label>
Expand Down
Loading

0 comments on commit b222712

Please sign in to comment.