api_topic.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. elif tool == 'length':
  22. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
  23. db_data = curs.fetchall()
  24. if db_data:
  25. return flask.jsonify({ 'length' : db_data[0][0] })
  26. else:
  27. return flask.jsonify({})
  28. else:
  29. curs.execute(db_change(
  30. "select id, data, date, ip, block, top from topic where code = ? and top = 'O' order by id + 0 asc"
  31. ), [
  32. topic_num
  33. ])
  34. data = curs.fetchall()
  35. if data:
  36. data_a = {}
  37. admin = admin_check(3)
  38. curs.execute(db_change("select ip from topic where code = ? order by id + 0 asc limit 1"), [topic_num])
  39. data_f = curs.fetchall()
  40. data_f = data_f[0][0] if data_f else ''
  41. data_a['data_main'] = {
  42. "ip_first" : ip_pas(data_f, 1),
  43. "admin" : str(admin)
  44. }
  45. ip_a = ip_pas([i[3] for i in data])
  46. ip_a_2 = ip_pas([i[3] for i in data], 1)
  47. for i in data:
  48. data_v = i[1] if i[4] != 'O' or admin == 1 else ''
  49. data_a[i[0]] = {
  50. "data" : data_v,
  51. "date" : i[2],
  52. "ip" : ip_a_2[i[3]],
  53. "blind" : i[4],
  54. "ip_pas" : ip_a[i[3]],
  55. "data_pas" : render_set(
  56. doc_data = data_v,
  57. data_type = 'api_view',
  58. data_in = 'topic_' + topic_num + '_' + i[0],
  59. doc_acl = 0
  60. )
  61. }
  62. return flask.jsonify(data_a)
  63. else:
  64. return flask.jsonify({})
  65. else:
  66. return flask.jsonify({})