UiRequestPlugin.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import re
  2. from Plugin import PluginManager
  3. @PluginManager.registerTo("UiRequest")
  4. class UiRequestPlugin(object):
  5. def __init__(self, *args, **kwargs):
  6. from Site import SiteManager
  7. self.site_manager = SiteManager.site_manager
  8. super(UiRequestPlugin, self).__init__(*args, **kwargs)
  9. # Media request
  10. def actionSiteMedia(self, path, **kwargs):
  11. match = re.match("/media/(?P<address>[A-Za-z0-9-]+\.[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)", path)
  12. if match: # Its a valid domain, resolve first
  13. domain = match.group("address")
  14. address = self.site_manager.resolveDomain(domain)
  15. if address:
  16. path = "/media/" + address + match.group("inner_path")
  17. return super(UiRequestPlugin, self).actionSiteMedia(path, **kwargs) # Get the wrapper frame output
  18. @PluginManager.registerTo("ConfigPlugin")
  19. class ConfigPlugin(object):
  20. def createArguments(self):
  21. group = self.parser.add_argument_group("Zeroname plugin")
  22. group.add_argument('--bit_resolver', help='ZeroNet site to resolve .bit domains', default="1Name2NXVi1RDPDgf5617UoW7xA6YrhM9F", metavar="address")
  23. return super(ConfigPlugin, self).createArguments()