fdsfds
parent
a46b3cbd3f
commit
0bb4e457a0
|
@ -192,7 +192,7 @@ def api_comment(v):
|
||||||
file=request.files["file"]
|
file=request.files["file"]
|
||||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(name)
|
url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ def edit_comment(cid, v):
|
||||||
file=request.files["file"]
|
file=request.files["file"]
|
||||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(name)
|
url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ def edit_post(pid, v):
|
||||||
file=request.files["file"]
|
file=request.files["file"]
|
||||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(name)
|
url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
@ -691,13 +691,13 @@ def thumbnail_thread(pid):
|
||||||
db.close()
|
db.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||||
|
|
||||||
with open(name, "wb") as file:
|
with open(name, "wb") as file:
|
||||||
for chunk in image_req.iter_content(1024):
|
for chunk in image_req.iter_content(1024):
|
||||||
file.write(chunk)
|
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.add(post)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
@ -916,7 +916,7 @@ def submit_post(v):
|
||||||
file=request.files["file2"]
|
file=request.files["file2"]
|
||||||
if not file.content_type.startswith('image/'): return {"error": "That wasn't an image!"}, 400
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(name)
|
url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
@ -1015,7 +1015,7 @@ def submit_post(v):
|
||||||
), 403
|
), 403
|
||||||
|
|
||||||
if file.content_type.startswith('image/'):
|
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)
|
file.save(name)
|
||||||
new_post.url = request.host_url + process_image(name)
|
new_post.url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ def settings_profile_post(v):
|
||||||
if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400
|
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
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(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
|
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
|
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)
|
file.save(name)
|
||||||
url = request.host_url + process_image(name)
|
url = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ def settings_images_profile(v):
|
||||||
|
|
||||||
file = request.files["profile"]
|
file = request.files["profile"]
|
||||||
|
|
||||||
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
highres = request.host_url + process_image(name)
|
highres = request.host_url + process_image(name)
|
||||||
|
|
||||||
|
@ -736,8 +736,8 @@ def settings_images_profile(v):
|
||||||
|
|
||||||
if not imageurl: abort(400)
|
if not imageurl: abort(400)
|
||||||
|
|
||||||
if v.highres and '/images/' in v.highres : os.remove('images/' + v.highres.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])
|
if v.profileurl and '/images/' in v.profileurl : os.remove('/images/' + v.profileurl.split('/images/')[1])
|
||||||
v.highres = highres
|
v.highres = highres
|
||||||
v.profileurl = imageurl
|
v.profileurl = imageurl
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
@ -760,12 +760,12 @@ def settings_images_banner(v):
|
||||||
|
|
||||||
file = request.files["banner"]
|
file = request.files["banner"]
|
||||||
|
|
||||||
name = f'images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
bannerurl = request.host_url + process_image(name)
|
bannerurl = request.host_url + process_image(name)
|
||||||
|
|
||||||
if bannerurl:
|
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
|
v.bannerurl = bannerurl
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -990,8 +990,8 @@ def settings_name_change(v):
|
||||||
def settings_song_change(v):
|
def settings_song_change(v):
|
||||||
song=request.values.get("song").strip()
|
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:
|
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")
|
os.remove(f"/songs/{v.song}.mp3")
|
||||||
v.song = None
|
v.song = None
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
g.db.commit()
|
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 "&" 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
|
v.song = id
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -1032,11 +1032,11 @@ def settings_song_change(v):
|
||||||
error=f"Duration of the video must not exceed 10 minutes.")
|
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:
|
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")
|
os.remove(f"/songs/{v.song}.mp3")
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'outtmpl': 'songs/%(title)s.%(ext)s',
|
'outtmpl': '/songs/%(title)s.%(ext)s',
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
'key': 'FFmpegExtractAudio',
|
'key': 'FFmpegExtractAudio',
|
||||||
|
@ -1053,10 +1053,10 @@ def settings_song_change(v):
|
||||||
v=v,
|
v=v,
|
||||||
error=f"Age-restricted videos aren't allowed.")
|
error=f"Age-restricted videos aren't allowed.")
|
||||||
|
|
||||||
files = os.listdir("songs/")
|
files = os.listdir("/songs/")
|
||||||
paths = [path.join("songs/", basename) for basename in files]
|
paths = [path.join("/songs/", basename) for basename in files]
|
||||||
songfile = max(paths, key=path.getctime)
|
songfile = max(paths, key=path.getctime)
|
||||||
os.rename(songfile, f"songs/{id}.mp3")
|
os.rename(songfile, f"/songs/{id}.mp3")
|
||||||
|
|
||||||
v.song = id
|
v.song = id
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
|
@ -265,7 +265,7 @@ def static_service(path):
|
||||||
@app.get('/hostedimages/<path:path>')
|
@app.get('/hostedimages/<path:path>')
|
||||||
@limiter.exempt
|
@limiter.exempt
|
||||||
def images(path):
|
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.remove("Cache-Control")
|
||||||
resp.headers.add("Cache-Control", "public, max-age=2628000")
|
resp.headers.add("Cache-Control", "public, max-age=2628000")
|
||||||
if request.path.endswith('.webp'):
|
if request.path.endswith('.webp'):
|
||||||
|
|
|
@ -307,7 +307,7 @@ def songs(id):
|
||||||
|
|
||||||
@app.get("/song/<song>")
|
@app.get("/song/<song>")
|
||||||
def 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.remove("Cache-Control")
|
||||||
resp.headers.add("Cache-Control", "public, max-age=2628000")
|
resp.headers.add("Cache-Control", "public, max-age=2628000")
|
||||||
return resp
|
return resp
|
||||||
|
|
Loading…
Reference in New Issue