main_view_file.py 1.1 KB

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