From 0bac81816cfdea3f0d1dc6da188bfd109168965f Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Tue, 22 Jul 2025 18:59:20 +0200 Subject: [PATCH] WebClient: add an id field to files list to simplify UI logic Signed-off-by: Nicola Murino --- internal/httpd/webclient.go | 10 ++++++---- templates/webclient/files.html | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/internal/httpd/webclient.go b/internal/httpd/webclient.go index 6d0c17fc..eadd95eb 100644 --- a/internal/httpd/webclient.go +++ b/internal/httpd/webclient.go @@ -1009,7 +1009,7 @@ func (s *httpdServer) handleShareGetDirContents(w http.ResponseWriter, r *http.R } defer lister.Close() - dataGetter := func(limit, _ int) ([]byte, int, error) { + dataGetter := func(limit, offset int) ([]byte, int, error) { contents, err := lister.Next(limit) if errors.Is(err, io.EOF) { err = nil @@ -1018,11 +1018,12 @@ func (s *httpdServer) handleShareGetDirContents(w http.ResponseWriter, r *http.R return nil, 0, err } results := make([]map[string]any, 0, len(contents)) - for _, info := range contents { + for idx, info := range contents { if !info.Mode().IsDir() && !info.Mode().IsRegular() { continue } res := make(map[string]any) + res["id"] = offset + idx + 1 if info.IsDir() { res["type"] = "1" res["size"] = "" @@ -1217,7 +1218,7 @@ func (s *httpdServer) handleClientGetDirContents(w http.ResponseWriter, r *http. defer lister.Close() dirTree := r.URL.Query().Get("dirtree") == "1" - dataGetter := func(limit, _ int) ([]byte, int, error) { + dataGetter := func(limit, offset int) ([]byte, int, error) { contents, err := lister.Next(limit) if errors.Is(err, io.EOF) { err = nil @@ -1226,8 +1227,9 @@ func (s *httpdServer) handleClientGetDirContents(w http.ResponseWriter, r *http. return nil, 0, err } results := make([]map[string]any, 0, len(contents)) - for _, info := range contents { + for idx, info := range contents { res := make(map[string]any) + res["id"] = offset + idx + 1 res["url"] = getFileObjectURL(name, info.Name(), webClientFilesPath) if info.IsDir() { res["type"] = "1" diff --git a/templates/webclient/files.html b/templates/webclient/files.html index 9d12cb2e..cb4d3c34 100644 --- a/templates/webclient/files.html +++ b/templates/webclient/files.html @@ -244,7 +244,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). `; //{{- if not .ShareUploadBaseURL}} - const supportedEditExtensions = ["csv", "bat", "dyalog", "apl", "asc", "pgp", "sig", "asn", "asn1", "b", "bf", + const supportedEditExtensions = ["csv", "bat", "dyalog", "apl", "asc", "sig", "asn", "asn1", "b", "bf", "c", "h", "ino", "cpp", "c++", "cc", "cxx", "hpp", "h++", "hh", "hxx", "cob", "cpy", "cbl", "cs", "clj", "cljc", "cljx", "cljs", "gss", "cmake", "cmake.in", "coffee", "cl", "lisp", "el", "cyp", "cypher", "pyx", "pxd", "pxi", "cr", "css", "cql", "d", "dart", "diff", "patch", "dtd", "dylan", "dyl", "intr", @@ -504,6 +504,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). switch (error.response.status) { case 200: errorMessage = "general.expired_session"; + break; case 403: errorMessage = "fs.create_dir.err_403"; break; @@ -677,6 +678,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). }, { data: "edit_url", + defaultContent: '', className: 'text-end', render: function (data, type, row) { if (type === 'display') { @@ -692,16 +694,19 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). case "webp": case "bmp": case "svg": - let desc = escapeHTML(filename).replace(/"/g, '"'); + let desc = escapeHTML(filename); + let descHtml = `${desc}`; + let descId = `desc-${row.id}`; previewDiv = ``; + + +
${descHtml}
+ `; break; case "mp4": case "mov": @@ -1965,6 +1970,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). switch (error.response.status) { case 200: errorMessage = "general.expired_session"; + break; case 403: errorMessage = "fs.create_dir.err_403"; break;