Esempio n. 1
0
def check_template_name():
    try:
        data = json.loads(
            urllib.parse.unquote(request.query_string.decode("utf-8")))
        name = data.get('name')
        guilds = data.get('guilds')  # TODO security concern
        connector = postgres_connector.PostgresConnector()
        connector.verify_name_uniqueness(name, guilds)
        return Response("Name available", status=200)
    except ValueError:
        abort(400)
Esempio n. 2
0
def delete():
    try:
        name = request.args.get("name")
        guild = request.args.get("guild")
        print(name, guild)
        if guild in [x['id'] for x in get_common_guilds_with_manage_perms()]:
            connector = postgres_connector.PostgresConnector()
            connector.delete_meme_template(name, guild)
            return Response(status=200)
        else:
            abort(403)
    except ValueError as e:
        return Response(str(e), status=400)
Esempio n. 3
0
def template():
    try:
        name = request.args.get("name")
        guild = request.args.get("guild")
        if guild in [x['id'] for x in get_common_guilds_with_manage_perms()]:
            connector = postgres_connector.PostgresConnector()
            template = connector.get_meme_template(name, guild)
            base64string = base64.b64encode(template['image']).decode('UTF-8')
            return jsonify(image=base64string, metadata=template['metadata'])
        else:
            abort(403)
    except ValueError as e:
        return Response(str(e), status=400)
Esempio n. 4
0
def preview_get():
    try:
        name = request.args.get("name")
        guild = request.args.get("guild")
        if guild in [x['id'] for x in get_common_guilds_with_manage_perms()]:
            connector = postgres_connector.PostgresConnector()
            template = connector.get_meme_template(name, guild)
            preview = MemeGenerator(bytes(template['image']),
                                    template['metadata'], []).generate()
            base64string = base64.b64encode(preview.read())
            return Response(base64string, status=200)
        else:
            abort(403)
    except ValueError as e:
        return Response(str(e), status=400)
Esempio n. 5
0
def guild_templates():
    guild = request.args.get('id')
    if guild in [x['id'] for x in get_common_guilds_with_manage_perms()]:
        templates = postgres_connector.PostgresConnector().list_guild_memes(
            guild)
        return jsonify(templates)
Esempio n. 6
0
def guilds_create():
    guilds = get_common_guilds_with_create_perms()
    guilds_templates = postgres_connector.PostgresConnector(
    ).get_guilds_templates(guilds)
    return jsonify(guilds_templates)