Allow the User Files directory to be configured as a URL.

master
Pacman Ghost 3 years ago
parent b5f72c2b57
commit 36fcc4f9a5
  1. 11
      vasl_templates/server_settings.py
  2. 2
      vasl_templates/webapp/files.py

@ -29,7 +29,7 @@ SERVER_SETTINGS = {
"webdriver-path": { "type": "file", "name": "webdriver", "allow_on_path": True, "fspec": _EXE_FSPEC },
"chapter-h-notes-dir": { "type": "dir", "name": "Chapter H notes directory" },
"chapter-h-image-scaling": { "type": "int", "name": "Chapter H image scaling" },
"user-files-dir": { "type": "dir", "name": "user files directory" },
"user-files-dir": { "type": "dir", "name": "user files directory", "allow_urls": True },
}
# ---------------------------------------------------------------------
@ -133,8 +133,9 @@ class ServerSettingsDialog( QDialog ):
ctrl = self._get_control( key )
func = getattr( self, "_unload_"+vals["type"] )
args, kwargs = [ vals["name"] ], {}
if "allow_on_path" in vals:
kwargs[ "allow_on_path" ] = vals["allow_on_path"]
for k in ("allow_on_path","allow_urls"):
if k in vals:
kwargs[ k ] = vals[ k ]
val = func( ctrl, *args, **kwargs )
if val is None:
# nb: something failed validation, an error message has already been shown
@ -189,9 +190,11 @@ class ServerSettingsDialog( QDialog ):
self._update_ui()
@staticmethod
def _unload_dir( ctrl, name ):
def _unload_dir( ctrl, name, allow_urls=False ):
"""Unload and validate a directory path."""
dname = ctrl.text().strip()
if allow_urls and dname.startswith( ("http://","https://") ):
return dname
if dname and not os.path.isdir( dname ):
MainWindow.showErrorMsg( "Can't find the {}:\n {}".format( name, dname ) )
ctrl.setFocus()

@ -63,7 +63,7 @@ def get_user_file( path ):
dname = app.config.get( "USER_FILES_DIR" )
if not dname:
abort( 404 )
if not os.path.isdir( dname ):
if not os.path.isdir( dname ) and not dname.startswith( ("http://","https://") ):
logging.error( "Missing user files directory: %s", dname )
resp = FileServer( dname ).serve_file( path )
if not resp:

Loading…
Cancel
Save