Skip to content

Commit

Permalink
Added route for deleting slide from file system (#25)
Browse files Browse the repository at this point in the history
* Added route for deleting slide

* removed incorrect comment

* Secured delete slide route

* Removed auth checker from SlideLoader

* removed globals for auth checker

Co-Authored-By: Ryan Birmingham <[email protected]>

* Fixed typo

Co-Authored-By: Ryan Birmingham <[email protected]>

Co-authored-by: Ryan Birmingham <[email protected]>
  • Loading branch information
Vedant1202 and birm authored Apr 14, 2020
1 parent 4623d7d commit 4e25bd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN pip3 install -r requirements.txt
EXPOSE 4000

#debug/dev only
#ENV FLASK_APP SlideServer.py
#CMD python -m flask run --host=0.0.0.0 --port=4000
# ENV FLASK_APP SlideServer.py
# CMD python -m flask run --host=0.0.0.0 --port=4000

#prod only
CMD gunicorn -w 4 -b 0.0.0.0:4000 SlideServer:app --timeout 400
35 changes: 32 additions & 3 deletions SlideServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import string
import sys
import pyvips
from os import listdir
from os.path import isfile, join


import urllib
import flask
import flask_cors
Expand All @@ -14,6 +18,7 @@
import dev_utils
import requests


try:
from io import BytesIO
except ImportError:
Expand All @@ -28,7 +33,7 @@
app.config['TOKEN_SIZE'] = 10
app.config['SECRET_KEY'] = os.urandom(24)

ALLOWED_EXTENSIONS = set(['svs', 'tif', 'tiff', 'vms', 'vmu', 'ndpi', 'scn', 'mrxs', 'bif', 'svslide'])
ALLOWED_EXTENSIONS = set(['svs', 'tif', 'tiff', 'vms', 'vmu', 'ndpi', 'scn', 'mrxs', 'bif', 'svslide'])


def allowed_file(filename):
Expand Down Expand Up @@ -131,6 +136,29 @@ def finish_upload(token):
# get info associated with token
# move the file out of temp to upload dir

# Delete the requested slide
@app.route('/slide/delete', methods=['POST'])
def slide_delete():
body = flask.request.get_json()

if not body:
return flask.Response(json.dumps({"error": "Missing JSON body"}), status=400)

filename = body['filename']
if filename and allowed_file(filename):
filename = secure_filename(filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
if os.path.isfile(filepath):
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return flask.Response(json.dumps({"deleted": filename, "success": True}))
else:
return flask.Response(json.dumps({"error": "File with name '" + filename + "' does not exist"}), status=400)

else:
return flask.Response(json.dumps({"error": "Invalid filename"}), status=400)

# check for file if it exists or not
# delete the file

@app.route("/test", methods=['GET'])
def testRoute():
Expand All @@ -152,13 +180,13 @@ def singleThumb(filepath):
def multiSlide(filepathlist):
return json.dumps(dev_utils.getMetadataList(json.loads(filepathlist), app.config['UPLOAD_FOLDER']))


@app.route("/getSlide/<image_name>")
def getSlide(image_name):
if(os.path.isfile("/images/"+image_name)):
return flask.send_from_directory(app.config["UPLOAD_FOLDER"], filename=image_name, as_attachment=True)
else:
return flask.Response(json.dumps({"error": "File does not exist"}), status=404)

return flask.Response(json.dumps({"error": "File does not exist"}), status=404)

# using the token from the start url upload endpoint
@app.route('/urlupload/continue/<token>', methods=['POST'])
Expand Down Expand Up @@ -196,3 +224,4 @@ def urlUploadStatus():
return flask.Response(json.dumps({"uploaded": "True"}), status=200)
else:
return flask.Response(json.dumps({"uploaded": "False"}), status=200)

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ openslide-python
flask
Werkzeug
flask-cors
requests
requests

0 comments on commit 4e25bd8

Please sign in to comment.