Improve Docker configurations

This commit is contained in:
rubenwardy
2020-01-18 01:20:32 +00:00
parent 6f230ee4b2
commit 095494f96f
8 changed files with 30 additions and 17 deletions

View File

@@ -72,7 +72,7 @@ from flask_login import logout_user
@app.route("/uploads/<path:path>")
def send_upload(path):
return send_from_directory("public/uploads", path)
return send_from_directory(app.config['UPLOAD_DIR'], path)
@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
@app.route('/<path:path>/')

View File

@@ -25,10 +25,10 @@ from PIL import Image
ALLOWED_RESOLUTIONS=[(100,67), (270,180), (350,233)]
def mkdir(path):
assert(path != "" and path is not None)
if not os.path.isdir(path):
os.mkdir(path)
mkdir("app/public/thumbnails/")
def resize_and_crop(img_path, modified_path, size):
img = Image.open(img_path)
@@ -65,10 +65,15 @@ def make_thumbnail(img, level):
w, h = ALLOWED_RESOLUTIONS[level - 1]
mkdir("app/public/thumbnails/{:d}/".format(level))
upload_dir = current_app.config["UPLOAD_DIR"]
thumbnail_dir = current_app.config["THUMBNAIL_DIR"]
mkdir(thumbnail_dir)
cache_filepath = "public/thumbnails/{:d}/{}".format(level, img)
source_filepath = "public/uploads/" + img
output_dir = os.path.join(thumbnail_dir, str(level))
mkdir(output_dir)
resize_and_crop("app/" + source_filepath, "app/" + cache_filepath, (w, h))
cache_filepath = os.path.join(output_dir, img)
source_filepath = os.path.join(upload_dir, img)
resize_and_crop(source_filepath, cache_filepath, (w, h))
return send_file(cache_filepath)

View File

@@ -389,7 +389,7 @@ def makeVCSRelease(id, branch):
try:
filename = randomString(10) + ".zip"
destPath = os.path.join("app/public/uploads", filename)
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
with open(destPath, "wb") as fp:
repo.archive(fp, format="zip")
@@ -424,7 +424,7 @@ def importRepoScreenshot(id):
sourcePath = gitDir + "/screenshot." + ext
if os.path.isfile(sourcePath):
filename = randomString(10) + "." + ext
destPath = os.path.join("app/public/uploads", filename)
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
shutil.copyfile(sourcePath, destPath)
ss = PackageScreenshot()

View File

@@ -46,6 +46,8 @@ def randomString(n):
return ''.join(random.choice(string.ascii_lowercase + \
string.ascii_uppercase + string.digits) for _ in range(n))
assert(os.path.isdir(app.config["UPLOAD_DIR"]), "UPLOAD_DIR must exist")
def doFileUpload(file, fileType, fileTypeDesc):
if not file or file is None or file.filename == "":
flash("No selected file", "error")
@@ -73,7 +75,7 @@ def doFileUpload(file, fileType, fileTypeDesc):
file.stream.seek(0)
filename = randomString(10) + "." + ext
file.save(os.path.join("app/public/uploads", filename))
file.save(os.path.join(app.config["UPLOAD_DIR"], filename))
return "/uploads/" + filename
def make_flask_user_password(plaintext_str):