api_topic_sub.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_a[i[0]] = {
  31. "data" : data_v,
  32. "date" : i[2],
  33. "ip" : ip_a_2[i[3]],
  34. "blind" : i[4],
  35. "ip_pas" : ip_a[i[3]],
  36. "data_pas" : render_set(data = data_v, num = 2, include = 'topic_' + i[0], acl = get_acl)
  37. }
  38. return flask.jsonify(data_a)
  39. else:
  40. return flask.jsonify({})