api_topic.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from .tool.func import *
  2. def api_topic(topic_num = 1, tool = 'normal', num = ''):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. topic_num = str(topic_num)
  6. if acl_check('', 'topic_view', topic_num) != 1:
  7. if tool == 'normal':
  8. if num != '':
  9. curs.execute(db_change(
  10. "select id, data, date, ip, block, top from topic where code = ? and id + 0 = ? + 0 order by id + 0 asc"
  11. ), [
  12. topic_num,
  13. num
  14. ])
  15. else:
  16. curs.execute(db_change(
  17. "select id, data, date, ip, block, top from topic where code = ? order by id + 0 asc"
  18. ), [
  19. topic_num
  20. ])
  21. else:
  22. curs.execute(db_change(
  23. "select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"
  24. ), [
  25. topic_num
  26. ])
  27. data = curs.fetchall()
  28. if data:
  29. data_a = {}
  30. admin = admin_check(3)
  31. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  32. data_f = curs.fetchall()
  33. data_f = data_f[0][0] if data_f else ''
  34. data_a['data_main'] = {
  35. "ip_first" : ip_pas(data_f, 1),
  36. "admin" : str(admin)
  37. }
  38. ip_a = ip_pas([i[3] for i in data])
  39. ip_a_2 = ip_pas([i[3] for i in data], 1)
  40. for i in data:
  41. data_v = i[1] if i[4] != 'O' or admin == 1 else ''
  42. data_a[i[0]] = {
  43. "data" : data_v,
  44. "date" : i[2],
  45. "ip" : ip_a_2[i[3]],
  46. "blind" : i[4],
  47. "ip_pas" : ip_a[i[3]],
  48. "data_pas" : render_set(
  49. doc_data = data_v,
  50. data_type = 'api_view',
  51. data_in = 'topic_' + topic_num + '_' + i[0],
  52. doc_acl = 0
  53. )
  54. }
  55. return flask.jsonify(data_a)
  56. else:
  57. return flask.jsonify({})
  58. else:
  59. return flask.jsonify({})