You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
905 B

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. import os
  6. from werkzeug.exceptions import NotFound
  7. from werkzeug.wsgi import SharedDataMiddleware
  8. from frappe.utils import get_site_name, get_site_path, get_site_base_path, get_path, cstr
  9. class StaticDataMiddleware(SharedDataMiddleware):
  10. def __call__(self, environ, start_response):
  11. self.environ = environ
  12. return super(StaticDataMiddleware, self).__call__(environ, start_response)
  13. def get_directory_loader(self, directory):
  14. def loader(path):
  15. site = get_site_name(frappe.app._site or self.environ.get('HTTP_HOST'))
  16. path = os.path.join(directory, site, 'public', 'files', cstr(path))
  17. if os.path.isfile(path):
  18. return os.path.basename(path), self._opener(path)
  19. else:
  20. raise NotFound
  21. # return None, None
  22. return loader