Exemplo n.º 1
0
def push():
    data = request.json
    to_email = data.get('email')
    file_ids = data.get('fileIds')
    if to_email is None or file_ids is None:
        return json.dumps({
            'code': -1,
            'msg': 'Email and File ids are required.'
        })
    # send emails
    files = [read_file(file_id) for file_id in file_ids]
    try:
        job = send_mail.queue(to_email, current_app.config['MG_EMAIL_FROM'],
                              current_app.config['MG_EMAIL_SUBJECT'],
                              current_app.config['MG_EMAIL_TEXT'], files,
                              current_app.config['MG_DOMAIN_NAME'],
                              current_app.config['MG_API_KEY'])
        for file_id in file_ids:
            remove_file(file_id)
        return json.dumps({'code': 0, 'data': job.id})
    except requests.exceptions.RequestException as e:
        print(str(e))
        return json.dumps({
            'code': -1,
            'msg': 'Failed to send emails. Please try again.'
        })
Exemplo n.º 2
0
def handle_files():
    if request.method == 'POST':
        file = request.files['file']
        # validate file type
        if file is None:
            return json.jumps({'code': -2, 'msg': 'Missing uploaded file.'})
        try:
            file_id = create_file(file)
            return json.dumps({'code': 0, 'data': file_id})
        except ValueError as e:
            return json.dumps({'code': -1, 'msg': str(e)})
    else:
        file_id = request.data.decode('utf-8')
        if file_id is None or file_id == '':
            return json.dumps({'code': -1, 'msg': 'Missing file id.'})
        remove_file(file_id)
        return json.dumps({'code': 0, 'data': file_id})
Exemplo n.º 3
0
def handle_files():
    if request.method == "POST":
        file = request.files["file"]
        # validate file type
        if file is None:
            return json.dumps({"code": -2, "msg": "Missing uploaded file."})
        try:
            file_id = create_file(file)
            return json.dumps({"code": 0, "data": file_id})
        except ValueError as e:
            print(str(e))
            return json.dumps({"code": -1, "msg": str(e)})
    else:
        file_id = request.data.decode("utf-8")
        if file_id is None or file_id == "":
            return json.dumps({"code": -1, "msg": "Missing file id."})
        remove_file(file_id)
        return json.dumps({"code": 0, "data": file_id})
Exemplo n.º 4
0
def push():
    data = request.json
    to_email = data.get('email')
    file_ids = data.get('fileIds')
    if to_email is None or file_ids is None:
        return json.dumps({
            'code': -1,
            'msg': 'Email and File ids are required.'
        })
    # send emails
    files = [read_file(file_id) for file_id in file_ids]
    try:
        send_mail(to_email, files)
        for file_id in file_ids:
            remove_file(file_id)
        return json.dumps({'code': 0, 'data': file_ids})
    except requests.exceptions.RequestException as e:
        print(str(e))
        return json.dumps({
            'code': -1,
            'msg': 'Failed to send emails. Please try again.'
        })