def download(id): item = shared_files.get(id) if not item: abort(404) if item.is_expired(): item.delete() resp = jsonify(message="The requested item has expired") resp.status_code = 410 return resp if item.expires == 0: item.delete() remove_record("share", item.id) path = item.path item.fetch_count += 1 if os.path.isdir(path): apath = compress(path, format="zip") with open(apath, "r") as f: data = f.read() resp = Response(data, mimetype="application/octet-stream") resp.headers["Content-Length"] = os.path.getsize(apath) resp.headers["Content-Disposition"] = "attachment; filename=%s" % os.path.basename(apath) return resp else: with open(path, "r") as f: data = f.read() resp = Response(data, mimetype="application/octet-stream") resp.headers["Content-Length"] = str(len(data.encode('utf-8'))) resp.headers["Content-Disposition"] = "attachment; filename=%s" % os.path.basename(path) return resp
def download(id): item = shared_files.get(id) if not item: abort(404) if item.is_expired: item.delete() return jsonify(errors={"msg": "The requested item has expired"}), 410 if item.expires == 0: item.delete() remove_record("share", item.id) path = item.path item.fetch_count += 1 if os.path.isdir(path): apath = compress(path, format="zip") with open(apath, "r") as f: data = f.read() resp = Response(data, mimetype="application/octet-stream") resp.headers["Content-Length"] = os.path.getsize(apath) resp.headers[ "Content-Disposition"] = "attachment; filename={0}".format( os.path.basename(apath)) return resp else: with open(path, "r") as f: data = f.read() resp = Response(data, mimetype="application/octet-stream") resp.headers["Content-Length"] = str(len(data)) resp.headers[ "Content-Disposition"] = "attachment; filename={0}".format( os.path.basename(path)) return resp
def remove_share(id): """Disable a fileshare link.""" try: share = shared_files.get(id) share.delete() logger.success('ctl:links:delete', 'Deleted share {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def update_share(id, expires): """Update a fileshare link's expiration.""" try: share = shared_files.get(id) share.update_expiry(expires) logger.success('ctl:links:update', 'Updated share {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def get(self, id): shares = shared_files.get(id) if id and not shares: abort(404) if type(shares) == list: return jsonify(shares=[x.as_dict() for x in shares]) else: return jsonify(share=shares.as_dict())
def get(self, id): shares = shared_files.get(id) if id and not shares: abort(404) if isinstance(shares, shared_files.SharedFile): return jsonify(share=shares.serialized) else: return jsonify(shares=[x.serialized for x in shares])
def put(self, id): share = shared_files.get(id) if id and not share: abort(404) data = request.get_json()["share"] if data["expires"]: share.update_expiry(data["expires_at"]) else: share.update_expiry(False) return jsonify(share=share.as_dict())
def put(self, id): share = shared_files.get(id) if id and not share: abort(404) data = request.get_json()["share"] if data["expires"]: share.update_expiry(data["expires_at"]) else: share.update_expiry(False) return jsonify(share=share.serialized)
def list_shares(): """List all fileshare links.""" try: data = shared_files.get() for x in data: smsg = click.style(x.path, fg="white", bold=True) click.echo(smsg + " ({0})".format(x.id)) s = "Never" if not x.expires else x.expires_at.strftime("%c") click.echo(click.style(" * Expires: ", fg="yellow") + s) except Exception as e: raise CLIException(str(e))
def delete(self, id): item = shared_files.get(id) if not item: abort(404) item.delete() return Response(status=204)