added vfs.ListProviders() and using it in template fsconfig.html (added a new ListFSProviders template function for that)

This commit is contained in:
Manuel Reithuber
2021-06-19 14:06:56 +02:00
committed by Nicola Murino
parent 88b10da596
commit fd4c388b23
3 changed files with 34 additions and 24 deletions

View File

@@ -252,20 +252,23 @@ func loadAdminTemplates(templatesPath string) {
filepath.Join(templatesPath, templateAdminDir, templateSetup), filepath.Join(templatesPath, templateAdminDir, templateSetup),
} }
usersTmpl := utils.LoadTemplate(nil, usersPaths...) rootTpl := template.New("").Funcs(template.FuncMap{
userTmpl := utils.LoadTemplate(nil, userPaths...) "ListFSProviders": vfs.ListProviders,
adminsTmpl := utils.LoadTemplate(nil, adminsPaths...) })
adminTmpl := utils.LoadTemplate(nil, adminPaths...) usersTmpl := utils.LoadTemplate(rootTpl, usersPaths...)
connectionsTmpl := utils.LoadTemplate(nil, connectionsPaths...) userTmpl := utils.LoadTemplate(rootTpl, userPaths...)
messageTmpl := utils.LoadTemplate(nil, messagePath...) adminsTmpl := utils.LoadTemplate(rootTpl, adminsPaths...)
foldersTmpl := utils.LoadTemplate(nil, foldersPath...) adminTmpl := utils.LoadTemplate(rootTpl, adminPaths...)
folderTmpl := utils.LoadTemplate(nil, folderPath...) connectionsTmpl := utils.LoadTemplate(rootTpl, connectionsPaths...)
statusTmpl := utils.LoadTemplate(nil, statusPath...) messageTmpl := utils.LoadTemplate(rootTpl, messagePath...)
loginTmpl := utils.LoadTemplate(nil, loginPath...) foldersTmpl := utils.LoadTemplate(rootTpl, foldersPath...)
changePwdTmpl := utils.LoadTemplate(nil, changePwdPaths...) folderTmpl := utils.LoadTemplate(rootTpl, folderPath...)
maintenanceTmpl := utils.LoadTemplate(nil, maintenancePath...) statusTmpl := utils.LoadTemplate(rootTpl, statusPath...)
defenderTmpl := utils.LoadTemplate(nil, defenderPath...) loginTmpl := utils.LoadTemplate(rootTpl, loginPath...)
setupTmpl := utils.LoadTemplate(nil, setupPath...) changePwdTmpl := utils.LoadTemplate(rootTpl, changePwdPaths...)
maintenanceTmpl := utils.LoadTemplate(rootTpl, maintenancePath...)
defenderTmpl := utils.LoadTemplate(rootTpl, defenderPath...)
setupTmpl := utils.LoadTemplate(rootTpl, setupPath...)
adminTemplates[templateUsers] = usersTmpl adminTemplates[templateUsers] = usersTmpl
adminTemplates[templateUser] = userTmpl adminTemplates[templateUser] = userTmpl

View File

@@ -6,12 +6,9 @@
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-control" id="idFilesystem" name="fs_provider" <select class="form-control" id="idFilesystem" name="fs_provider"
onchange="onFilesystemChanged(this.value)"> onchange="onFilesystemChanged(this.value)">
<option value="0" {{if eq .Provider 0 }}selected{{end}}>Local</option> {{ range ListFSProviders }}
<option value="4" {{if eq .Provider 4 }}selected{{end}}>Local encrypted</option> <option value="{{.}}" {{if eq . $.Provider }}selected{{end}}>{{.ShortInfo}}</option>
<option value="1" {{if eq .Provider 1 }}selected{{end}}>AWS S3 (Compatible)</option> {{end}}
<option value="2" {{if eq .Provider 2 }}selected{{end}}>Google Cloud Storage</option>
<option value="3" {{if eq .Provider 3 }}selected{{end}}>Azure Blob Storage</option>
<option value="5" {{if eq .Provider 5 }}selected{{end}}>SFTP</option>
</select> </select>
</div> </div>
</div> </div>

View File

@@ -68,19 +68,29 @@ func (p FilesystemProvider) ShortInfo() string {
case LocalFilesystemProvider: case LocalFilesystemProvider:
return "Local" return "Local"
case S3FilesystemProvider: case S3FilesystemProvider:
return "S3" return "AWS S3 (Compatible)"
case GCSFilesystemProvider: case GCSFilesystemProvider:
return "GCS" return "Google Cloud Storage"
case AzureBlobFilesystemProvider: case AzureBlobFilesystemProvider:
return "AzBlob" return "Azure Blob Storage"
case CryptedFilesystemProvider: case CryptedFilesystemProvider:
return "Encrypted" return "Local encrypted"
case SFTPFilesystemProvider: case SFTPFilesystemProvider:
return "SFTP" return "SFTP"
} }
return "" return ""
} }
// ListProviders returns a list of available FilesystemProviders
func ListProviders() []FilesystemProvider {
// TODO this should ultimately be dynamic (i.e. each provider registers itself)
return []FilesystemProvider{
LocalFilesystemProvider, S3FilesystemProvider,
GCSFilesystemProvider, AzureBlobFilesystemProvider,
CryptedFilesystemProvider, SFTPFilesystemProvider,
}
}
// ValidatorHelper implements methods we need for Filesystem.ValidateConfig. // ValidatorHelper implements methods we need for Filesystem.ValidateConfig.
// It is implemented by vfs.Folder and dataprovider.User // It is implemented by vfs.Folder and dataprovider.User
type ValidatorHelper interface { type ValidatorHelper interface {