Skip to content

Commit

Permalink
Merge pull request #54 from Thorfusion/dev
Browse files Browse the repository at this point in the history
Update to 1.1.0
  • Loading branch information
maggi373 authored May 25, 2024
2 parents 0e940b6 + 5eb2cf3 commit 444a582
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 43 deletions.
38 changes: 20 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.0.0"
__version__ = "1.1.0"

import os
from dotenv import load_dotenv
Expand Down Expand Up @@ -212,16 +212,17 @@ def newmodversion(id):
if "mod_delete_id" not in request.form:
return redirect(id)
Mod.delete_mod(request.form["mod_delete_id"])
return redirect(url_for("modlibrary"))
if "rehash_submit" in request.form:
if "rehash_id" not in request.form:
return redirect(url_for("clientlibrary"))

if request.form["rehash_md5"] != "":
version = Modversion.get_by_id(request.form["rehash_id"])
version.update_hash(request.form["rehash_md5"], request.form["rehash_url"])
version.update_hash(request.form["rehash_md5"], mirror_url + request.form["rehash_url"])
else:
version = Modversion.get_by_id(request.form["rehash_id"])
t = threading.Thread(target=version.rehash, args=(request.form["rehash_url"],))
t = threading.Thread(target=version.rehash, args=(mirror_url + request.form["rehash_url"],))
t.start()
print(request.form["rehash_id"])
print(request.form["rehash_md5"])
Expand All @@ -231,13 +232,13 @@ def newmodversion(id):
print(request.form["newmodvermanual_version"])
print(request.form["newmodvermanual_mcversion"])
print(request.form["newmodvermanual_url"])
filesie2 = Modversion.get_file_size(request.form["newmodvermanual_url"])
filesie2 = Modversion.get_file_size(mirror_url + request.form["newmodvermanual_url"])
print(filesie2)
if request.form["newmodvermanual_md5"] != "":
Modversion.new(id, request.form["newmodvermanual_version"], request.form["newmodvermanual_mcversion"], request.form["newmodvermanual_md5"], filesie2, "0")
else:
# Todo Add filesize rehash and md5 hash, if fails do not add
Modversion.new(id, request.form["newmodvermanual_version"], request.form["newmodvermanual_mcversion"], "0", filesie2, "0", request.form["newmodvermanual_url"])
Modversion.new(id, request.form["newmodvermanual_version"], request.form["newmodvermanual_mcversion"], "0", filesie2, "0", mirror_url + request.form["newmodvermanual_url"])
return redirect(id)


Expand Down Expand Up @@ -300,6 +301,11 @@ def modpack(id):
if "marked_submit" in request.form:
Build.update_checkbox_marked(request.form["marked_modid"], request.form["marked_check"])
return redirect(id)
if "deletemod_submit" in request.form:
if "modpack_delete_id" not in request.form:
return redirect(id)
modpack.delete_modpack(request.form["modpack_delete_id"])
return redirect(url_for("modpacklibrary"))

return render_template("modpack.html", modpack=builds, modpackname=modpack)

Expand Down Expand Up @@ -427,22 +433,15 @@ def modpackbuild(id):
if "token" not in session or not Session.verify_session(session["token"], request.remote_addr):
# New or invalid session, send to login
return redirect(url_for("login"))
listmod = Mod.get_all()


try:
listmod = Mod.get_all_pretty_names()
packbuild = Build.get_by_id(id)
modpackbuild = packbuild.get_modversions_minimal()
listmodversions = Modversion.get_all()
buildlist = Build_modversion.get_modpack_build(id)

packbuildname = Build.get_modpackname_by_id(id)
if modpackbuild:
mods = Mod.get_multi_by_id(
tuple(build_modversion.mod_id for build_modversion in modpackbuild))
mod_mapping = {mod.id: mod for mod in mods}
mod_version_combo = [(mod_mapping[build_modversion.mod_id],
build_modversion) for build_modversion in modpackbuild]
if not modpackbuild:
mod_version_combo = []
except connector.ProgrammingError as _:
raise _
Database.create_tables()
Expand Down Expand Up @@ -471,16 +470,19 @@ def modpackbuild(id):
if "delete_submit" in request.form:
if "delete_id" not in request.form:
return redirect(id)
Build_modversion.delete_build_modversion(request.form["delete_id"], id)
Build_modversion.delete_build_modversion(request.form["delete_id"])
return redirect(id)
if "deletebuild_submit" in request.form:
Build.delete_build(id)
return redirect(url_for("modpacklibrary"))
if "add_mod_submit" in request.form:
Modversion.add_modversion_to_selected_build(request.form["modversion"], request.form["modnames"], id, "0", request.form["newoptional"])
newoptional="0"
if "newoptional" in request.form:
newoptional=request.form['newoptional']
Modversion.add_modversion_to_selected_build(request.form["modversion"], request.form["modnames"], id, "0", newoptional)
return redirect(id)

return render_template("modpackbuild.html", mod_version_combo=mod_version_combo, listmod=listmod, packbuild=packbuild, packbuildname=packbuildname, listmodversions=listmodversions)
return render_template("modpackbuild.html", listmod=listmod, packbuild=packbuild, packbuildname=packbuildname, listmodversions=listmodversions, buildlist=buildlist)


@app.route("/modlibrary", methods=["GET"])
Expand Down
23 changes: 20 additions & 3 deletions models/build_modversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def __init__(self, id, modversion_id, build_id, created_at, updated_at, optional
self.optional = optional

@classmethod
def delete_build_modversion(cls, modversion_id, build_id):
def delete_build_modversion(cls, id):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s AND build_id = %s", (modversion_id, build_id))
cur.execute("DELETE FROM build_modversion WHERE id = %s", (id,))
conn.commit()
return None

Expand All @@ -28,4 +28,21 @@ def update_optional(cls, modversion_id, optional, build_id):
SET optional = %s
WHERE modversion_id = %s AND build_id = %s;""", (optional, modversion_id, build_id))
conn.commit()
return None
return None

@staticmethod
def get_modpack_build(id):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute(
"""SELECT build_modversion.id, build_modversion.optional, modversions.version, modversions.id AS modverid, mods.name, mods.pretty_name, mods.id AS modid
FROM build_modversion
INNER JOIN modversions ON build_modversion.modversion_id = modversions.id
INNER JOIN mods ON modversions.mod_id = mods.id
WHERE build_id = %s
"""
, (id,))
rows = cur.fetchall()
if rows:
return rows
return []
14 changes: 11 additions & 3 deletions models/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ def update(cls, id, name, description, author, link, pretty_name, side, note):

@classmethod
def delete_mod(cls, id):
# deleting mods code has been disabled, the code needs to be checked and deleting mods needs to be better protected against accedental deletion
return None
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT * FROM modversions WHERE mod_id = %s", (id,))
modversions = cur.fetchall()
if modversions:
for mv in modversions:
cur.execute("DELETE FROM build_modversion WHERE modversion_id = %s", (mv["id"],))
cur.execute("DELETE * FROM modversions WHERE mod_id = %s", (id,))
cur.execute("DELETE FROM modversions WHERE mod_id = %s", (id,))
cur.execute("DELETE FROM mods WHERE id=%s", (id,))
conn.commit()
return None
Expand Down Expand Up @@ -94,6 +92,16 @@ def get_all():
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 []

@staticmethod
def get_all_pretty_names():
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT id, pretty_name FROM mods")
rows = cur.fetchall()
if rows:
return rows
return []

def get_versions(self):
conn = Database.get_connection()
Expand Down
14 changes: 14 additions & 0 deletions models/modpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ def new(cls, name, slug, hidden, private, user_id):
return None
return cls(id, name, slug, now, now, hidden, private)

@classmethod
def delete_modpack(cls, id):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT * FROM builds WHERE modpack_id = %s", (id,))
modversions = cur.fetchall()
if modversions:
for mv in modversions:
cur.execute("DELETE FROM build_modversion WHERE build_id = %s", (mv["id"],))
cur.execute("DELETE FROM builds WHERE modpack_id = %s", (id,))
cur.execute("DELETE FROM modpacks WHERE id=%s", (id,))
conn.commit()
return None

@classmethod
def update_checkbox(cls, id, value, column, table):
conn = Database.get_connection()
Expand Down
4 changes: 2 additions & 2 deletions models/modversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def get_by_id(cls, id):
def get_all():
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT * FROM modversions")
cur.execute("SELECT id, mod_id, version, mcversion FROM modversions")
rows = cur.fetchall()
if rows:
return [Modversion(row["id"], row["mod_id"], row["version"], row["mcversion"], row["md5"], row["created_at"], row["updated_at"], row["filesize"]) for row in rows]
return rows
return []

def get_file_size(url):
Expand Down
9 changes: 7 additions & 2 deletions static/js/solderpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function submitbuttonpress(id, val, submitid) {
document.querySelector(submit2).click();
}

function submitbuttonpress2(version, name, url, urlform, submitid) {
function submitbuttonpress2(version, name, urlform, submitid) {
versionname = document.getElementById(version).value;
urllink = url + name + '/' + name + '-' + versionname + '.zip';
urllink = name + '/' + name + '-' + versionname + '.zip';
document.getElementById(urlform).value = urllink;

submit2 = '[name="' + submitid + '"]';
Expand Down Expand Up @@ -157,6 +157,11 @@ function hideoptions(optiontoshow){
document.querySelector('[name="' + "modfirst" + '"]').selected = true;
}

function undisable(id){
// gets the value of selected option
document.getElementById(id).removeAttribute("disabled")
}

function zipfile_mods(modslug, mcversion, modversion, input, verchange) {
// selects the file
let dataSelect = document.getElementById(input);
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.0.0</p>
<p class="">Version 1.1.0</p>
</div>

</div>
Expand Down
5 changes: 5 additions & 0 deletions templates/modpack.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<label class="form-check-label" for="private">Private</label>
</div>
<input class="btn btn-success" type="submit" value="Add build" name="form-submit" id="form-submit"></input>
<button type="button" id="deletemod" class="btn btn-danger" disabled onclick="submitbuttonpress('modpack_delete_id', '{{ modpackname.id }}', 'deletemod_submit')">Delete Modpack</button> <input class="form-check-input" type="checkbox" value="1" id="delete_disable" name="delete_disable" onchange="undisable('deletemod')">
</form>
{% if success %}
<div class="alert alert-success loginfail mx-auto" role="alert">
Expand All @@ -138,6 +139,10 @@
<p>Failed!</p>
</div>
{% endif %}
<form method="post" action="">
<input type="text" class="form-control invisible" name="modpack_delete_id" id="modpack_delete_id" readonly>
<input class="btn btn-danger invisible" type="submit" name="deletemod_submit" id="deletemod_submit" value="Delete">
</form>
</div>

<script src="{{ url_for('static',filename='js/solderpy.js') }}"></script>
Expand Down
26 changes: 15 additions & 11 deletions templates/modpackbuild.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@
</tr>
</thead>
<tbody class="">
{%for combo in mod_version_combo%}
{% for combo in buildlist %}
<tr>
<td class="tablewidth70 tablemaxwidth">{{combo[0].pretty_name}} ({{combo[0].name}})</td>
<td class="tablewidth70 tablemaxwidth">{{combo.pretty_name}} ({{combo.name}})</td>
<td class="tablewidth20">
<select class="form-select" name="selmodver_{{combo[0].id}}" id="selmodver_{{combo[0].id}}" onchange="submitoptionpress('selmodver_oldver', '{{combo[1].id}}', 'selmodver_ver', 'selmodver_{{combo[0].id}}', 'selmodver_submit');">
{%for modlist in listmodversions%}
{%if combo[0].id == modlist.mod_id %}
<option {%if combo[1].version == modlist.version %} selected="selected" {%endif%} value="{{modlist.id}}">{{modlist.version}}</option>
<select class="form-select" name="selmodver_{{combo.modid}}" id="selmodver_{{combo.modid}}" onchange="submitoptionpress('selmodver_oldver', '{{combo.modverid}}', 'selmodver_ver', 'selmodver_{{combo.modid}}', 'selmodver_submit');">
{%for modlist in listmodversions%}
{% if modlist.mcversion == None or modlist.mcversion == packbuild.minecraft %}
{%if combo.modid == modlist.mod_id %}
<option {%if combo.version == modlist.version %} selected="selected" {%endif%} value="{{modlist.id}}">{{modlist.version}}</option>
{% endif %}
{%endif%}
{%endfor%}
</select>
</td>
<td>
<input class="form-check-input" type="checkbox" value="" id="optional_{{combo[1].id}}" onclick="submitecheckedpress('optional_modid', '{{combo[1].id}}', 'optional_check', 'optional_{{combo[1].id}}', 'optional_submit')" {% if combo[1].optional
<input class="form-check-input" type="checkbox" value="" id="optional_{{combo.modverid}}" onclick="submitecheckedpress('optional_modid', '{{combo.modverid}}', 'optional_check', 'optional_{{combo.modverid}}', 'optional_submit')" {% if combo.optional
%}checked{% endif %}>
</td>
<td>
<div class="maxcont">
<button type="button" class="btn btn-danger buttonwidth" onclick="submitbuttonpress('delete_id', '{{combo[1].id}}', 'delete_submit')">Remove</button>
<button type="button" class="btn btn-danger buttonwidth" onclick="submitbuttonpress('delete_id', '{{combo.id}}', 'delete_submit')">Remove</button>
</div>
</td>
</tr>
Expand Down Expand Up @@ -69,8 +71,8 @@
<option class="is-invalid" name="modfirst2" hidden="true" selected="selected">Select mod</option>
{%for lmod in listmod%}
<option value="{{lmod.id}}"
{%for combo in mod_version_combo%}
{% if combo[0].id == lmod.id %}
{%for combo in buildlist%}
{% if combo.modid == lmod.id %}
hidden="true"
{% endif %}
{%endfor%}>{{lmod.pretty_name}}</option>
Expand All @@ -81,8 +83,10 @@
<label for="modversion" class="form-label">Modversion</label>
<select class="form-select" name="modversion" id="modversion">
<option class="is-invalid" name="modfirst">Select mod first</option>
{%for modlist in listmodversions%}
{%for modlist in listmodversions%}
{% if modlist.mcversion == None or modlist.mcversion == packbuild.minecraft %}
<option value="{{modlist.id}}" id="modversion_{{modlist.mod_id}}" name="modlist" hidden="true">{{modlist.version}}</option>
{% endif %}
{%endfor%}
</select>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/modversion.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<th scope="col">Download URL</th>
<th scope="col">Filesize</th>
<th>
<button type="button" class="btn btn-success tableaddversion" onclick="copyformtext('newmodvermanual_version', 'version');copyformtext('newmodvermanual_mcversion', 'mcversion');copyformtext('newmodvermanual_md5', 'md5');submitbuttonpress2('version', '{{ mod.name }}', '{{mirror_url}}', 'newmodvermanual_url', 'newmodvermanual_submit')">Add Version</button>
<button type="button" class="btn btn-success tableaddversion" onclick="copyformtext('newmodvermanual_version', 'version');copyformtext('newmodvermanual_mcversion', 'mcversion');copyformtext('newmodvermanual_md5', 'md5');submitbuttonpress2('version', '{{ mod.name }}', 'newmodvermanual_url', 'newmodvermanual_submit')">Add Version</button>
</th>
</tr>
</thead>
Expand All @@ -37,7 +37,7 @@
<td>{{versions.filesize}} bytes</td>
<td>
<div class="maxcont">
<button type="button" class="btn btn-primary buttonwidth" onclick="buttonpress('rehash_url', '{{mirror_url}}{{ mod.name }}/{{ mod.name }}-{{versions.version}}.zip'); copyformtext('rehash_md5', 'md5_{{versions.id}}'); submitbuttonpress('rehash_id', '{{versions.id}}', 'rehash_submit')">Rehash</button>
<button type="button" class="btn btn-primary buttonwidth" onclick="buttonpress('rehash_url', '{{ mod.name }}/{{ mod.name }}-{{versions.version}}.zip'); copyformtext('rehash_md5', 'md5_{{versions.id}}'); submitbuttonpress('rehash_id', '{{versions.id}}', 'rehash_submit')">Rehash</button>
<button type="button" class="btn btn-danger" onclick="submitbuttonpress('delete_id', '{{versions.id}}', 'deleteversion_submit')">Delete</button>
<button type="button" class="btn btn-secondary" onclick="submitbuttonpress('addtoselbuild_id', '{{versions.id}}', 'addtoselbuild_submit')">AddToSelBuild</button>
</div>
Expand Down Expand Up @@ -117,7 +117,7 @@
<textarea name="internal_note" id="internal_note" class="form-control" rows="5">{{ mod.note }}</textarea>
</div>
<input class="btn btn-success" type="submit" value="Save changes" name="form-submit" id="form-submit">
<button type="button" class="btn btn-danger" disabled onclick="submitbuttonpress('mod_delete_id', '{{ mod.id }}', 'deletemod_submit')">Delete Mod</button>
<button type="button" id="deletemod" class="btn btn-danger" disabled onclick="submitbuttonpress('mod_delete_id', '{{ mod.id }}', 'deletemod_submit')">Delete Mod</button> <input class="form-check-input" type="checkbox" value="1" id="delete_disable" name="delete_disable" onchange="undisable('deletemod')">
</form>
{% if success %}
<div class="alert alert-success loginfail mx-auto" role="alert">
Expand Down

0 comments on commit 444a582

Please sign in to comment.