mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 18:36:44 +00:00
Merge pull request #7 from terorie/master
Exclusive /api/task/upload operation
This commit is contained in:
commit
fb6a1821ae
22
app.py
22
app.py
@ -14,6 +14,9 @@ from flask_caching import Cache
|
|||||||
from tasks import TaskManager, Task, TaskResult
|
from tasks import TaskManager, Task, TaskResult
|
||||||
from search.search import ElasticSearchEngine, InvalidQueryException
|
from search.search import ElasticSearchEngine, InvalidQueryException
|
||||||
from callbacks import PostCrawlCallbackFactory
|
from callbacks import PostCrawlCallbackFactory
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
|
uploadLock = Lock()
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = config.FLASK_SECRET
|
app.secret_key = config.FLASK_SECRET
|
||||||
@ -635,14 +638,17 @@ def api_upload():
|
|||||||
|
|
||||||
filename = "./tmp/" + str(website_id) + ".json"
|
filename = "./tmp/" + str(website_id) + ".json"
|
||||||
|
|
||||||
if os.path.exists(filename):
|
# Read the file into memory cuz if the request fails
|
||||||
logger.debug("Appending chunk to existing file...")
|
# no file is corrupted.
|
||||||
with open(filename, "ab") as f:
|
buf = file.stream.readall()
|
||||||
f.write(file.stream.read())
|
|
||||||
else:
|
# Write to file (create if not exists) when
|
||||||
logger.debug("Saving temp file " + filename + " ...")
|
# everything read successfully.
|
||||||
file.save(filename)
|
with uploadLock:
|
||||||
logger.debug("Done saving temp file")
|
with open(filename, "a+b") as f:
|
||||||
|
f.write(buf)
|
||||||
|
|
||||||
|
logger.debug("Written chunk to file")
|
||||||
return "ok"
|
return "ok"
|
||||||
else:
|
else:
|
||||||
return abort(403)
|
return abort(403)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user