Compare commits
No commits in common. "94fa825e67761a606035d78fc87e22573ccefc1a" and "6fe9ba59a7eb3e20afdc09f195767e24eff9ec1b" have entirely different histories.
94fa825e67
...
6fe9ba59a7
22
overwrought_master.py
Executable file → Normal file
22
overwrought_master.py
Executable file → Normal file
|
@ -251,34 +251,22 @@ def post_pack():
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
mods_remote = res.json()
|
mods_remote = res.json()
|
||||||
mods = [mod for mod in mods if mod.filename not in mods_remote]
|
mods = [mod for mod in mods if mod.filename not in mods_remote]
|
||||||
|
files = {}
|
||||||
for mod in mods:
|
for mod in mods:
|
||||||
files = {}
|
|
||||||
files[mod.filename] = open(os.path.join('mods', mod.filename), 'rb')
|
files[mod.filename] = open(os.path.join('mods', mod.filename), 'rb')
|
||||||
res = requests.post(
|
|
||||||
url=config_master.remote_addr + '/post',
|
|
||||||
data=data,
|
|
||||||
files=files
|
|
||||||
)
|
|
||||||
res.raise_for_status()
|
|
||||||
files[mod.filename].close()
|
|
||||||
print(f"{mod.filename} uploaded.")
|
|
||||||
|
|
||||||
|
|
||||||
files = {}
|
|
||||||
files['modpack.db'] = open('modpack.db', 'rb')
|
|
||||||
files[config_master.modpack_name + '.html'] = open(
|
files[config_master.modpack_name + '.html'] = open(
|
||||||
config_master.modpack_name +'.html', 'rb')
|
config_master.modpack_name, 'rb')
|
||||||
|
|
||||||
res = requests.post(
|
res = requests.post(
|
||||||
url=config_master.remote_addr + '/post',
|
url=config_master.remote_addr + '/post',
|
||||||
data=data,
|
data=data,
|
||||||
files=files
|
files=files
|
||||||
)
|
)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
|
|
||||||
for file in files.values():
|
for file in files.values():
|
||||||
file.close()
|
file.close()
|
||||||
print("modpack.db uploaded.")
|
|
||||||
print(f"{config_master.modpack_name}.html uploaded.")
|
|
||||||
print('Success!')
|
print('Success!')
|
||||||
|
|
||||||
|
|
||||||
|
|
26
overwrought_server.py
Executable file → Normal file
26
overwrought_server.py
Executable file → Normal file
|
@ -2,7 +2,6 @@
|
||||||
"""
|
"""
|
||||||
The overwrought server, for exchanging mods from master to slave recipients.
|
The overwrought server, for exchanging mods from master to slave recipients.
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import threading
|
import threading
|
||||||
|
@ -14,22 +13,6 @@ import config_server
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['db_lock'] = threading.Lock()
|
app.config['db_lock'] = threading.Lock()
|
||||||
os.makedirs('mods', exist_ok=True)
|
|
||||||
|
|
||||||
def init_db():
|
|
||||||
"""
|
|
||||||
If no database is found, a dummy database is created to allow the
|
|
||||||
initial modpack upload to go smoothly.
|
|
||||||
"""
|
|
||||||
con = sqlite3.connect('modpack.db')
|
|
||||||
cur = con.cursor()
|
|
||||||
try:
|
|
||||||
cur.execute("SELECT filename FROM mod").fetchone()
|
|
||||||
except sqlite3.OperationalError:
|
|
||||||
cur.execute("CREATE TABLE mod(filename TEXT)")
|
|
||||||
con.commit()
|
|
||||||
con.close()
|
|
||||||
init_db()
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
@ -64,20 +47,17 @@ def post():
|
||||||
if not argon2.verify(password, config_server.pw_hash):
|
if not argon2.verify(password, config_server.pw_hash):
|
||||||
abort(401)
|
abort(401)
|
||||||
|
|
||||||
files = request.files.to_dict()
|
|
||||||
if 'modpack.db' in files:
|
|
||||||
db = request.files.get('database')
|
db = request.files.get('database')
|
||||||
app.config.get('db_lock').acquire()
|
app.config.get('db_lock').acquire()
|
||||||
db.save('modpack.db')
|
db.save('modpack.db')
|
||||||
app.config.get('db_lock').release()
|
app.config.get('db_lock').release()
|
||||||
files.pop('modpack.db')
|
|
||||||
|
|
||||||
if config_server.modpack_name + '.html' in files:
|
|
||||||
summary = request.files.get(config_server.modpack_name + '.html')
|
summary = request.files.get(config_server.modpack_name + '.html')
|
||||||
summary.save(config_server.modpack_name + '.html')
|
summary.save(config_server.modpack_name + '.html')
|
||||||
files.pop(config_server.modpack_name + '.html')
|
|
||||||
|
|
||||||
for fname, file in files.items():
|
for fname, file in request.files.items():
|
||||||
|
if not fname.endswith('.jar'):
|
||||||
|
continue
|
||||||
file.save(os.path.join(config_server.mods_dir, fname))
|
file.save(os.path.join(config_server.mods_dir, fname))
|
||||||
|
|
||||||
def generate_hash(password):
|
def generate_hash(password):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user