api_topic_sub.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if flask.request.args.get('num', None):
  6. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"), [
  7. topic_num,
  8. flask.request.args.get('num', '')
  9. ])
  10. elif flask.request.args.get('top', None):
  11. 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])
  12. else:
  13. curs.execute(db_change("select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"), [topic_num])
  14. data = curs.fetchall()
  15. if data:
  16. data_a = {}
  17. admin = admin_check(3)
  18. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  19. data_f = curs.fetchall()
  20. data_f = data_f[0][0] if data_f else ''
  21. data_a['data_main'] = {
  22. "ip_first" : ip_pas(data_f, 1),
  23. "admin" : str(admin)
  24. }
  25. ip_a = ip_pas([i[3] for i in data])
  26. ip_a_2 = ip_pas([i[3] for i in data], 1)
  27. for i in data:
  28. data_v = i[1] if i[4] != 'O' or admin == 1 else ''
  29. data_a[i[0]] = {
  30. "data" : data_v,
  31. "date" : i[2],
  32. "ip" : ip_a_2[i[3]],
  33. "blind" : i[4],
  34. "ip_pas" : ip_a[i[3]],
  35. "data_pas" : render_set(
  36. doc_data = data_v,
  37. data_type = 'api_view',
  38. data_in = 'topic_' + topic_num + '_' + i[0],
  39. doc_acl = 0
  40. )
  41. }
  42. return flask.jsonify(data_a)
  43. else:
  44. return flask.jsonify({})