api_w.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from .tool.func import *
  2. def api_w_2(conn, name):
  3. curs = conn.cursor()
  4. if flask.request.args.get('exist', None):
  5. curs.execute(db_change("select title from data where title = ?"), [name])
  6. if curs.fetchall():
  7. return flask.jsonify({ "exist" : "1" })
  8. else:
  9. if acl_check(name, 'render') != 1:
  10. if flask.request.method == 'POST':
  11. g_data = flask.request.form.get('data', '')
  12. g_data = render_set(title = name, data = g_data, num = 2)
  13. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  14. else:
  15. rev = flask.request.args.get('num', '')
  16. if rev != '':
  17. curs.execute(db_change("select data from history where title = ? and id = ?"), [name, rev])
  18. else:
  19. curs.execute(db_change("select data from data where title = ?"), [name])
  20. data = curs.fetchall()
  21. if data:
  22. json_data = data[0][0]
  23. include_data = flask.request.args.get('include', None)
  24. if include_data:
  25. get_all_change_1 = []
  26. find_replace_moment = re.findall(r'(@([^=@]+)=([^=@]+)@|@([^=@]+)@)', json_data)
  27. for i in find_replace_moment:
  28. if i[1] != '':
  29. get_all_change_1 += [['@' + i[1] + '@', i[2]]]
  30. json_data = json_data.replace(i[0], '@' + i[1] + '@', 1)
  31. else:
  32. json_data = json_data.replace(i[0], '@' + i[3] + '@', 1)
  33. get_all_change_2 = re.findall(r'(@(?:[^@]*)@),([^,]*),', flask.request.args.get('change', '')) + get_all_change_1
  34. for i in get_all_change_2:
  35. json_data = json_data.replace(
  36. i[0].replace('<amp>', '&'),
  37. i[1].replace('<amp>', '&').replace('<comma>', ','),
  38. 1
  39. )
  40. g_data = render_set(title = name, data = json_data, num = 2, include = include_data)
  41. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  42. return flask.jsonify({})