Ejemplo n.º 1
0
def upload_image():
    """
    Upload an image to a list.
    The image should be base64 encoded.
    """
    list_id = request.form.get("list_id")
    base64_str = request.form.get("file")

    if not list_id:
        return error(Error.EMPTY_LIST_ID, 400)
    if not base64_str:
        return error(Error.EMPTY_IMAGE, 400)

    decoded = base64.b64decode(base64_str)
    filename = str(uuid.uuid4()) + ".png"
    image_path = app.config['IMAGE_PATH'] + filename
    with open(image_path, "wb") as f:
        f.write(decoded)

    card = Card.add_card(list_id, filename, True)

    image_path = app.config['IMAGE_PATH'] + filename
    thread = Thread(target=async_ocr, args=[app, image_path, card.id])
    thread.start()

    return ok({"created": True, "card": card.to_dict()})
Ejemplo n.º 2
0
def upload_image():
    """
    Upload an image to a list,
    return JSON.
    """
    list_id = request.form.get("list_id")
    base64_str = request.form.get("file")

    if not list_id:
        return error(Error.EMPTY_LIST_ID, 400)
    if not base64_str:
        return error(Error.EMPTY_IMAGE, 400)
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_LIST, 400)

    decoded = base64.decodestring(base64_str)
    filename = str(uuid.uuid4()) + ".png"
    image_path = app.config['IMAGE_PATH'] + filename
    with open(image_path, "wb") as f:
        f.write(decoded)

    card = Card.add_card(list_id, filename, True)

    image_path = app.config['IMAGE_PATH'] + filename
    thread = Thread(target=async_ocr, args=[app, image_path, card.id])
    thread.start()

    return ok({"created": True, "card": card.to_dict()})
Ejemplo n.º 3
0
def add_card():
    """
    Adds a card to a list.
    """
    content = request.form.get("content")
    list_id = request.form.get("list_id")

    if not content:
        return error(Error.EMPTY_CONTENT, 400)
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_BOARD, 400)

    card = Card.add_card(list_id, content)
    return ok({"created": True, "card": card.to_dict()})
Ejemplo n.º 4
0
def add_card():
    """
    Adds a card specified by card content and list id.
    Returns the created card id.
    """
    content = request.form.get("content")
    list_id = request.form.get("list_id")

    if not content:
        return error(Error.EMPTY_CONTENT, 400)
    elif not list_id:
        return error(Error.EMPTY_LIST_ID, 400)

    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_BOARD, 400)

    card = Card.add_card(list_id, content)
    return ok({"created": True, "card": card.to_dict()})