50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
#! /usr/bin/python3
|
|
import flask
|
|
from redis import Redis
|
|
from flask import Flask, redirect, url_for, request
|
|
import json
|
|
import hashlib
|
|
import time
|
|
|
|
r = Redis()
|
|
app = Flask(__name__)
|
|
m = hashlib.sha256()
|
|
@app.route('/dashboard/<name>')
|
|
def dashboard(name):
|
|
return 'welcome %s' % name
|
|
|
|
@app.route('/image',methods = ['POST', 'GET'])
|
|
def image():
|
|
try:
|
|
data = dict()
|
|
|
|
# Clean the request
|
|
if "text" in request.form:
|
|
data["text"] = request.form["text"][:256]
|
|
else :
|
|
data["text"] = ""
|
|
|
|
if "image_data" in request.form:
|
|
data["image_data"] = request.form["image_data"]
|
|
else:
|
|
raise Exception("image_data is mandatory")
|
|
|
|
m.update( bytes(time.asctime(), 'utf-8'))
|
|
hash_name = m.hexdigest()[:16]
|
|
data["hash_name"] = hash_name
|
|
|
|
# Save to queue
|
|
r.rpush("image-convert",json.dumps(data))
|
|
return( json.dumps({
|
|
"message":"ok",
|
|
"hash_name":hash_name
|
|
}) )
|
|
|
|
except Exception as e:
|
|
print("woah",e)
|
|
return( json.dumps( {"errors":[ str(e)]}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug = True)
|