示例#1
0
文件: rest.py 项目: Signez/dradis2
def list_studios():
    studio_serializer = JSONSerializer(Studio)
    query = Studio.query.limit(request.args.get('limit')).order_by(Studio.slug)

    squack()

    return jsonify(sanitize(studio_serializer.serialize(query)))
示例#2
0
def upload_media():
    kind = request.args.get('kind')
    username = '******'  # FIXME: Add account support
    uploaded_file = request.files['file']

    if uploaded_file:
        filename = utilities.secure_filename(uploaded_file.filename)
        filename = decorate_filename(filename, kind, username)
        new_path = os.path.join(app.config['MEDIA_ROOT'], 'uploads', filename)
        uploaded_file.save(new_path)

        if not allowed_file(
                uploaded_file.filename) or not allowed_file_type(new_path):
            os.remove(new_path)
            return jsonify(error_message("not_allowed"))

        squack()

        return jsonify({
            "status":
            "done",
            "result":
            new_path.replace(app.config['MEDIA_ROOT'], app.config['MEDIA_URL'])
        })
    else:
        return jsonify(error_message("not_received_file"))
示例#3
0
def list_studios():
    studio_serializer = JSONSerializer(Studio)
    query = Studio.query.limit(request.args.get('limit')).order_by(Studio.slug)

    squack()

    return jsonify(sanitize(studio_serializer.serialize(query)))
示例#4
0
文件: upload.py 项目: Signez/dradis2
def upload_media():
    kind = request.args.get("kind")
    username = "******"  # FIXME: Add account support
    uploaded_file = request.files["file"]

    if uploaded_file:
        filename = utilities.secure_filename(uploaded_file.filename)
        filename = decorate_filename(filename, kind, username)
        new_path = os.path.join(app.config["MEDIA_ROOT"], "uploads", filename)
        uploaded_file.save(new_path)

        if not allowed_file(uploaded_file.filename) or not allowed_file_type(new_path):
            os.remove(new_path)
            return jsonify(error_message("not_allowed"))

        squack()

        return jsonify(
            {"status": "done", "result": new_path.replace(app.config["MEDIA_ROOT"], app.config["MEDIA_URL"])}
        )
    else:
        return jsonify(error_message("not_received_file"))