def complete_transfer(tid): signature = request.form.get("signature", None) if signature is None: raise ValueError("Need value for signature.") if not security.hmac_compare(app.config["BASEJUMP_KEY"], tid, signature): raise ValueError("Invalid credentials.") with db_session() as s: transfer = s.query(Transfer).filter(Transfer.id == tid and Transfer.started == True).first() if transfer is None: raise ValueError("No such transfer.") filepath = filecache.get_file_path(transfer.file.key) if not os.path.exists(filepath): raise ValueError("File not found.") transfer.progress = 100 s.add(transfer) emails = [] d = datetime.datetime.now() for subscriber in transfer.subscribers: emails.append(subscriber.email) subscriber.last_notified = d s.add(subscriber) message = """Your file transfer of {filename} is complete.\ Please download it at {download_url} in the next week,\ otherwise it may be deleted to make room.""".format(filename=transfer.file.file_name(), download_url=url_for("download_file", key=transfer.file.key, _external=True)) subject = "HPSS Transfer Complete" mailer.send_email(subject, message, emails) s.commit()
def queued_jobs(timestamp=None, signed_stamp=None): if None in (timestamp, signed_stamp): raise ValueError("No credentials provided.") if not security.hmac_compare(app.config["BASEJUMP_KEY"], timestamp, signed_stamp): raise ValueError("Invalid credentials.") with db_session() as s: transfers = s.query(Transfer).filter(Transfer.started == False) details = [{"id": t.id, "key": t.file.key, "path": t.file.path} for t in transfers.all()] return jsonify(details)
def update_transfer(tid): progress, signature = request.form.get("progress", None), request.form.get("signature", None) if None in (progress, signature): raise ValueError("Need value for progress and signature.") if not security.hmac_compare(app.config["BASEJUMP_KEY"], progress, signature): raise ValueError("Invalid credentials.") try: progress = int(progress) except: raise ValueError("Invalid progress value.") with db_session() as s: transfer = s.query(Transfer).filter(Transfer.id == tid and Transfer.started == True).first() if transfer is None: raise ValueError("No such transfer.") transfer.progress = progress s.add(transfer) s.commit()
def start_transfer(tid): if "signature" not in request.form: raise ValueError("No credentials provided.") signature = request.form["signature"] if not security.hmac_compare(app.config["BASEJUMP_KEY"], "/transfers/%s/start" % (tid), signature): raise ValueError("Invalid credentials.") with db_session() as s: transfer = s.query(Transfer).filter(Transfer.id == tid).first() if transfer is None: raise ValueError("No such transfer.") f = transfer.file if not filecache.make_space_for(f.size): response = jsonify({"result": "failure"}) # "Entity Too Large" error response.status_code = 413 response.headers["Retry-After"] = "24" return response transfer.started = True s.add(transfer) s.commit() return jsonify({"result": "success", "filepath": filecache.get_file_path(f.key)})