api_topic_sub.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from .tool.func import *
  2. def api_topic_sub_2(conn, topic_num):
  3. curs = conn.cursor()
  4. topic_num = str(topic_num)
  5. get_acl = acl_check('', 'render')
  6. if flask.request.args.get('num', None):
  7. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"), [
  8. topic_num,
  9. flask.request.args.get('num', '')
  10. ])
  11. elif flask.request.args.get('top', None):
  12. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"), [topic_num])
  13. else:
  14. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"), [topic_num])
  15. data = curs.fetchall()
  16. if data:
  17. data_a = {}
  18. admin = admin_check(3)
  19. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  20. data_f = curs.fetchall()
  21. data_f = data_f[0][0] if data_f else ''
  22. data_a['data_main'] = {
  23. "ip_first" : ip_pas(data_f, 1),
  24. "admin" : str(admin)
  25. }
  26. ip_a = ip_pas([i[3] for i in data])
  27. ip_a_2 = ip_pas([i[3] for i in data], 1)
  28. for i in data:
  29. data_v = i[1] if i[4] != 'O' or admin == 1 else ''
  30. data_r = render_set(data = data_v, num = 2, include = 'topic_' + i[0], acl = get_acl)
  31. data_r_html = data_r[0]
  32. data_r_js = data_r[1]
  33. data_r_html = re.sub(
  34. r'<topic_a>((?:(?!<\/topic_a>).)+)<\/topic_a>',
  35. '<a href="\g<1>">\g<1></a>',
  36. data_r_html
  37. )
  38. data_r_html = re.sub(
  39. r'&lt;topic_call&gt;@((?:(?!&lt;\/topic_call&gt;).)+)&lt;\/topic_call&gt;',
  40. '<a href="/w/user:\g<1>">@\g<1></a>',
  41. data_r_html
  42. )
  43. data_a[i[0]] = {
  44. "data" : data_v,
  45. "date" : i[2],
  46. "ip" : ip_a_2[i[3]],
  47. "blind" : i[4],
  48. "ip_pas" : ip_a[i[3]],
  49. "data_pas" : [data_r_html, data_r_js]
  50. }
  51. return flask.jsonify(data_a)
  52. else:
  53. return flask.jsonify({})