Skip to content

Commit

Permalink
feat: delete images
Browse files Browse the repository at this point in the history
incorporated code from hauxir#33
  • Loading branch information
sdip15fa committed Jan 28, 2023
1 parent a46d5e4 commit 7584888
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}/<string:filename>", 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)

0 comments on commit 7584888

Please sign in to comment.