mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 06:27:38 +01:00
Add delete unused uploads admin function
This commit is contained in:
parent
ed78a2e06f
commit
c1b4256d44
@ -26,7 +26,7 @@ from app.tasks.forumtasks import importTopicList, checkAllForumAccounts
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import *
|
||||
from app.utils import loginUser, rank_required, triggerNotif
|
||||
import datetime
|
||||
import datetime, os
|
||||
|
||||
@bp.route("/admin/", methods=["GET", "POST"])
|
||||
@rank_required(UserRank.ADMIN)
|
||||
@ -114,6 +114,35 @@ def admin_page():
|
||||
triggerNotif(package.author, current_user, msg, rel.getEditURL())
|
||||
db.session.commit()
|
||||
|
||||
elif action == "cleanuploads":
|
||||
upload_dir = app.config['UPLOAD_DIR']
|
||||
|
||||
(_, _, filenames) = next(os.walk(upload_dir))
|
||||
existing_uploads = set(filenames)
|
||||
|
||||
if len(existing_uploads) != 0:
|
||||
def getURLsFromDB(column):
|
||||
results = db.session.query(column).filter(column != None, column != "").all()
|
||||
return set([os.path.basename(x[0]) for x in results])
|
||||
|
||||
release_urls = getURLsFromDB(PackageRelease.url)
|
||||
screenshot_urls = getURLsFromDB(PackageScreenshot.url)
|
||||
|
||||
db_urls = release_urls.union(screenshot_urls)
|
||||
unreachable = existing_uploads.difference(db_urls)
|
||||
|
||||
import sys
|
||||
print("On Disk: ", existing_uploads, file=sys.stderr)
|
||||
print("In DB: ", db_urls, file=sys.stderr)
|
||||
print("Unreachable: ", unreachable, file=sys.stderr)
|
||||
|
||||
for filename in unreachable:
|
||||
os.remove(os.path.join(upload_dir, filename))
|
||||
|
||||
flash("Deleted " + str(len(unreachable)) + " unreachable uploads", "success")
|
||||
else:
|
||||
flash("No downloads to create", "danger")
|
||||
|
||||
else:
|
||||
flash("Unknown action: " + action, "danger")
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
<option value="recalcscores">Recalculate package scores</option>
|
||||
<option value="checkusers">Check forum users</option>
|
||||
<option value="importscreenshots">Import screenshots from VCS</option>
|
||||
<option value="cleanuploads">Delete unreachable uploads</option>
|
||||
<!-- <option value="importdepends">Import dependencies from downloads</option> -->
|
||||
<!-- <option value="modprovides">Set provides to mod name</option> -->
|
||||
<!-- <option value="vcsrelease">Create VCS releases</option> -->
|
||||
|
@ -73,7 +73,7 @@ def doFileUpload(file, fileType, fileTypeDesc):
|
||||
|
||||
ext = getExtension(file.filename)
|
||||
if ext is None or not ext in allowedExtensions:
|
||||
flash("Please upload load " + fileTypeDesc, "danger")
|
||||
flash("Please upload " + fileTypeDesc, "danger")
|
||||
return None, None
|
||||
|
||||
if isImage and not isAllowedImage(file.stream.read()):
|
||||
|
Loading…
Reference in New Issue
Block a user