diff --git a/README.md b/README.md index 9a5a49f..ae3d0bf 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,18 @@ Uploading an image by URL: Fetching a file in a specific size(e.g. 320x240): -``` +```bash http://some.host/somename.png?w=320&h=240 ``` returns the image cropped to the desired size +Deleting an image, it requires jwt config to be set: + +```bash +curl --location --request DELETE 'http://some.host/somename.png' --header 'Authorization: Bearer ey......' +``` + ## Running imgpush requires docker diff --git a/app/app.py b/app/app.py index a91dfe2..94a10a3 100644 --- a/app/app.py +++ b/app/app.py @@ -260,6 +260,18 @@ def get_image(filename): return send_from_directory(settings.IMAGES_DIR, filename) +# https://github.com/hauxir/imgpush/pull/33 +@app.route(f"{settings.IMAGES_ROOT}/", methods=["DELETE"]) +def delete_image(filename): + if getattr(g.get("user"), "role", None) != "admin": + return jsonify(error="Permission denied"), 403 + path = os.path.join(settings.IMAGES_DIR, filename) + if os.path.isfile(path): + os.remove(path) + else: + return jsonify(error="File not found"), 404 + + return Response(status=204) if __name__ == "__main__": app.run(host="0.0.0.0", port=settings.PORT, threaded=True)