master
Aevann1 2021-12-13 03:00:08 +02:00
parent a46b3cbd3f
commit 0bb4e457a0
5 changed files with 25 additions and 25 deletions

View File

@ -192,7 +192,7 @@ def api_comment(v):
file=request.files["file"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)
@ -722,7 +722,7 @@ def edit_comment(cid, v):
file=request.files["file"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)

View File

@ -422,7 +422,7 @@ def edit_post(pid, v):
file=request.files["file"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)
@ -691,13 +691,13 @@ def thumbnail_thread(pid):
db.close()
return
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
with open(name, "wb") as file:
for chunk in image_req.iter_content(1024):
file.write(chunk)
post.thumburl = f"https://{site}/" + process_image(name, True)
post.thumburl = f"https://{site}" + process_image(name, True)
db.add(post)
db.commit()
db.close()
@ -916,7 +916,7 @@ def submit_post(v):
file=request.files["file2"]
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)
@ -1015,7 +1015,7 @@ def submit_post(v):
), 403
if file.content_type.startswith('image/'):
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
new_post.url = request.host_url + process_image(name)

View File

@ -128,7 +128,7 @@ def settings_profile_post(v):
if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400
else: return render_template("settings_profile.html", v=v, error=f"Image files only."), 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)
@ -318,7 +318,7 @@ def settings_profile_post(v):
if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400
else: return render_template("settings_profile.html", v=v, error=f"Image files only."), 400
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = request.host_url + process_image(name)
@ -724,7 +724,7 @@ def settings_images_profile(v):
file = request.files["profile"]
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
highres = request.host_url + process_image(name)
@ -736,8 +736,8 @@ def settings_images_profile(v):
if not imageurl: abort(400)
if v.highres and '/images/' in v.highres : os.remove('images/' + v.highres.split('/images/')[1])
if v.profileurl and '/images/' in v.profileurl : os.remove('images/' + v.profileurl.split('/images/')[1])
if v.highres and '/images/' in v.highres : os.remove('/images/' + v.highres.split('/images/')[1])
if v.profileurl and '/images/' in v.profileurl : os.remove('/images/' + v.profileurl.split('/images/')[1])
v.highres = highres
v.profileurl = imageurl
g.db.add(v)
@ -760,12 +760,12 @@ def settings_images_banner(v):
file = request.files["banner"]
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
bannerurl = request.host_url + process_image(name)
if bannerurl:
if v.bannerurl and '/images/' in v.bannerurl : os.remove('images/' + v.bannerurl.split('/images/')[1])
if v.bannerurl and '/images/' in v.bannerurl : os.remove('/images/' + v.bannerurl.split('/images/')[1])
v.bannerurl = bannerurl
g.db.add(v)
g.db.commit()
@ -990,8 +990,8 @@ def settings_name_change(v):
def settings_song_change(v):
song=request.values.get("song").strip()
if song == "" and v.song and path.isfile(f"songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"songs/{v.song}.mp3")
if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
v.song = None
g.db.add(v)
g.db.commit()
@ -1010,7 +1010,7 @@ def settings_song_change(v):
if "?" in id: id = id.split("?")[0]
if "&" in id: id = id.split("&")[0]
if path.isfile(f'songs/{id}.mp3'):
if path.isfile(f'/songs/{id}.mp3'):
v.song = id
g.db.add(v)
g.db.commit()
@ -1032,11 +1032,11 @@ def settings_song_change(v):
error=f"Duration of the video must not exceed 10 minutes.")
if v.song and path.isfile(f"songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"songs/{v.song}.mp3")
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
ydl_opts = {
'outtmpl': 'songs/%(title)s.%(ext)s',
'outtmpl': '/songs/%(title)s.%(ext)s',
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
@ -1053,10 +1053,10 @@ def settings_song_change(v):
v=v,
error=f"Age-restricted videos aren't allowed.")
files = os.listdir("songs/")
paths = [path.join("songs/", basename) for basename in files]
files = os.listdir("/songs/")
paths = [path.join("/songs/", basename) for basename in files]
songfile = max(paths, key=path.getctime)
os.rename(songfile, f"songs/{id}.mp3")
os.rename(songfile, f"/songs/{id}.mp3")
v.song = id
g.db.add(v)

View File

@ -265,7 +265,7 @@ def static_service(path):
@app.get('/hostedimages/<path:path>')
@limiter.exempt
def images(path):
resp = make_response(send_from_directory('../images', path.replace('.WEBP','.webp')))
resp = make_response(send_from_directory('/images', path.replace('.WEBP','.webp')))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=2628000")
if request.path.endswith('.webp'):

View File

@ -307,7 +307,7 @@ def songs(id):
@app.get("/song/<song>")
def song(song):
resp = make_response(send_from_directory('songs/', song))
resp = make_response(send_from_directory('/songs', song))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=2628000")
return resp