Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
File: files.py Progetto: ns408/core
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))
Esempio n. 4
0
File: files.py Progetto: ns408/core
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))
Esempio n. 5
0
 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())
Esempio n. 6
0
 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])
Esempio n. 7
0
 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())
Esempio n. 8
0
 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)
Esempio n. 9
0
File: files.py Progetto: ns408/core
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))
Esempio n. 10
0
 def delete(self, id):
     item = shared_files.get(id)
     if not item:
         abort(404)
     item.delete()
     return Response(status=204)
Esempio n. 11
0
 def delete(self, id):
     item = shared_files.get(id)
     if not item:
         abort(404)
     item.delete()
     return Response(status=204)