main_view_file.py 1.1 KB

12345678910111213141516171819202122232425
  1. from .tool.func import *
  2. async def main_view_file(data = ''):
  3. with get_db_connect() as conn:
  4. if data == 'robots.txt':
  5. curs = conn.cursor()
  6. curs.execute(db_change("select data from other where name = 'robot_default'"))
  7. db_data = curs.fetchall()
  8. if db_data and db_data[0][0] != '':
  9. return flask.Response(get_default_robots_txt(conn), mimetype = 'text/plain')
  10. else:
  11. curs.execute(db_change("select data from other where name = 'robot'"))
  12. db_data = curs.fetchall()
  13. if db_data:
  14. return flask.Response(db_data[0][0], mimetype = 'text/plain')
  15. else:
  16. return flask.Response(get_default_robots_txt(conn), mimetype = 'text/plain')
  17. elif os.path.exists(data):
  18. if re.search(r'\.txt$', data, flags = re.I):
  19. return flask.send_from_directory('./', data, mimetype = 'text/plain')
  20. else:
  21. return flask.send_from_directory('./', data, mimetype = 'text/xml')
  22. else:
  23. return ''