From c153a395435ef46ca2d1e5eaedbf744782a7ea0f Mon Sep 17 00:00:00 2001 From: Graham Steffaniak <42989099+gtsteffaniak@users.noreply.github.com> Date: Sun, 23 Feb 2025 18:04:47 -0500 Subject: [PATCH] Beta/v0.5.4 (#397) Co-authored-by: Anoop Sundaresh <16442416+theryecatcher@users.noreply.github.com> --- .github/workflows/tag.yaml | 21 +++++++++++---- CHANGELOG.md | 8 ++++++ backend/http/middleware.go | 15 ++++++----- backend/storage/bolt/users.go | 18 +++++++------ frontend/src/components/prompts/NewDir.vue | 3 ++- frontend/src/utils/download.js | 19 +++++++------ frontend/src/utils/files.js | 31 +++++++++++++++++----- frontend/src/utils/files.test.js | 20 ++++++++++++++ frontend/src/views/Files.vue | 3 ++- frontend/src/views/files/ListingView.vue | 19 ++++++++----- frontend/src/views/files/Preview.vue | 27 +++++++------------ frontend/tests/file-actions.spec.ts | 22 ++++++++++++--- frontend/tests/preview.spec.ts | 1 - 13 files changed, 143 insertions(+), 64 deletions(-) create mode 100644 frontend/src/utils/files.test.js diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index 5b83bd82c..6eebc56a0 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -50,13 +50,24 @@ jobs: uses: docker/metadata-action@v5 with: images: gtstef/filebrowser - - name: Modify tags (strip 'v' and add 'beta' if needed) + - name: Modify tags (strip 'v' and add 'beta'/'stable' if needed) id: modify-json run: | - JSON="${{ steps.meta.outputs.tags }}" - # Remove 'v' from version tags - JSON=$(echo "$JSON" | sed 's/filebrowser:v/filebrowser:/g') - echo "cleaned_tag=$JSON" >> $GITHUB_OUTPUT + JSON='${{ steps.meta.outputs.json }}' # Assuming the JSON output is stored in steps.meta.outputs.json + + # Process the JSON array using jq + MODIFIED_JSON=$(echo "$JSON" | jq ' + .tags |= map(sub(":v"; ":")) | + if any(.tags[]; test("beta")) then .tags += ["gtstef/filebrowser:beta"] else . end | + if any(.tags[]; test("stable")) then .tags += ["gtstef/filebrowser:stable"] else . end + ') + + # Convert JSON to a comma-separated string for Docker tags + TAGS_CSV=$(echo "$MODIFIED_JSON" | jq -r '.tags | join(",")') + + echo "$TAGS_CSV" > modified_tags.txt # Save for debugging + echo "cleaned_tag=$TAGS_CSV" >> $GITHUB_OUTPUT + - name: Build and push uses: docker/build-push-action@v6 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index f73244a93..d858a309a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. For commit guidelines, please refer to [Standard Version](https://github.com/conventional-changelog/standard-version). +## v0.5.4-beta + + **BugFixes**: + - default scope share issue. @theryecatcher https://github.com/gtsteffaniak/filebrowser/pull/387 + - drag and drop on empty folders https://github.com/gtsteffaniak/filebrowser/issues/361 + - preview navigation issue https://github.com/gtsteffaniak/filebrowser/issues/372 + - auth proxy password length error https://github.com/gtsteffaniak/filebrowser/issues/375 + ## v0.5.3-beta **New Features** diff --git a/backend/http/middleware.go b/backend/http/middleware.go index 0291ec95a..db762f74f 100644 --- a/backend/http/middleware.go +++ b/backend/http/middleware.go @@ -40,7 +40,9 @@ func withHashFileHelper(fn handleFunc) handleFunc { return func(w http.ResponseWriter, r *http.Request, data *requestContext) (int, error) { path := r.URL.Query().Get("path") hash := r.URL.Query().Get("hash") + // Retrieve the user (using the public user by default) data.user = &users.PublicUser + data.user.Scope = "" // Get the file link by hash link, err := store.Share.GetByHash(hash) @@ -55,15 +57,16 @@ func withHashFileHelper(fn handleFunc) handleFunc { return status, fmt.Errorf("could not authenticate share request") } } - // Retrieve the user (using the public user by default) - user := &users.PublicUser + + // Set the scope to configured defaults + scope := settings.Config.UserDefaults.Scope // Get file information with options file, err := FileInfoFasterFunc(files.FileOptions{ - Path: filepath.Join(user.Scope, link.Path+"/"+path), - Modify: user.Perm.Modify, + Path: filepath.Join(scope, link.Path+"/"+path), + Modify: data.user.Perm.Modify, Expand: true, - Checker: user, // Call your checker function here + Checker: data.user, // Call your checker function here }) file.Token = link.Token if err != nil { @@ -190,7 +193,6 @@ func wrapHandler(fn handleFunc) http.HandlerFunc { // Call the actual handler function and get status code and error status, err := fn(w, r, data) - // Handle the error case if there is one if err != nil { // Create an error response in JSON format @@ -303,7 +305,6 @@ func setUserInResponseWriter(w http.ResponseWriter, user *users.User) { // LoggingMiddleware logs each request and its status code. func LoggingMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - start := time.Now() // Wrap the ResponseWriter to capture the status code. diff --git a/backend/storage/bolt/users.go b/backend/storage/bolt/users.go index 433238da6..03de61db1 100644 --- a/backend/storage/bolt/users.go +++ b/backend/storage/bolt/users.go @@ -86,15 +86,17 @@ func (st usersBackend) Update(user *users.User, fields ...string) error { } func (st usersBackend) Save(user *users.User) error { - if len(user.Password) < settings.Config.Auth.Methods.PasswordAuth.MinLength { - return fmt.Errorf("password must be at least %d characters long", settings.Config.Auth.Methods.PasswordAuth.MinLength) + if settings.Config.Auth.Methods.PasswordAuth.Enabled { + if len(user.Password) < settings.Config.Auth.Methods.PasswordAuth.MinLength { + return fmt.Errorf("password must be at least %d characters long", settings.Config.Auth.Methods.PasswordAuth.MinLength) + } + pass, err := users.HashPwd(user.Password) + if err != nil { + return err + } + user.Password = pass } - pass, err := users.HashPwd(user.Password) - if err != nil { - return err - } - user.Password = pass - err = st.db.Save(user) + err := st.db.Save(user) if err == storm.ErrAlreadyExists { return errors.ErrExist } diff --git a/frontend/src/components/prompts/NewDir.vue b/frontend/src/components/prompts/NewDir.vue index a7dd31e14..2c9534a0f 100644 --- a/frontend/src/components/prompts/NewDir.vue +++ b/frontend/src/components/prompts/NewDir.vue @@ -7,6 +7,7 @@
{{ $t("prompts.newDirMessage") }}
{ @@ -44,10 +46,11 @@ export default function download() { files.push(state.route.path); } try { + // Initiate download without new window filesApi.download(format, files); - notify.showSuccess("download started"); + notify.showSuccess("Download started"); } catch (e) { - notify.showError("error downloading", e); + notify.showError("Error downloading", e); } }, }); diff --git a/frontend/src/utils/files.js b/frontend/src/utils/files.js index f95a5c755..6c2d14965 100644 --- a/frontend/src/utils/files.js +++ b/frontend/src/utils/files.js @@ -1,7 +1,26 @@ -export function getFileExtension(filename) { - const firstDotIndex = filename.indexOf('.'); - if (firstDotIndex === -1) { - return filename; // No dot found, return the original filename - } - return filename.substring(firstDotIndex); +export function getFileExtension (filename) { + if (typeof filename !== 'string') { + return '' } + const firstDotIndex = filename.indexOf('.') + + // If no dot exists, return an empty string + if (firstDotIndex === -1) { + return '' + } + + // Default: Get everything after the first dot + const firstDotExtension = filename.substring(firstDotIndex) + + if (firstDotExtension === '.') { + return "" + } + // If it's 7 or fewer characters (including the dot), return it + if (firstDotExtension.length <= 7) { + return firstDotExtension + } + + // Otherwise, return everything after the last dot + const lastDotIndex = filename.lastIndexOf('.') + return filename.substring(lastDotIndex) +} diff --git a/frontend/src/utils/files.test.js b/frontend/src/utils/files.test.js new file mode 100644 index 000000000..368ba535a --- /dev/null +++ b/frontend/src/utils/files.test.js @@ -0,0 +1,20 @@ +import { describe, it, expect } from 'vitest'; +import { getFileExtension } from './files.js'; + +describe('testSort', () => { + + it('get extension from file', () => { + const tests = [ + {input: "hi.txt", expected:".txt"}, + {input: "hello world.exe", expected:".exe"}, + {input: "Amazon.com - Order.pdf", expected:".pdf"}, + {input: "file", expected:""}, + {input: "file.", expected:""}, + {input: "file.tar.gz", expected:".tar.gz"}, + ] + for (let i in tests) { + expect(getFileExtension(tests[i].input)).toEqual(tests[i].expected); + } + }); + +}); diff --git a/frontend/src/views/Files.vue b/frontend/src/views/Files.vue index b31be158e..baf276706 100644 --- a/frontend/src/views/Files.vue +++ b/frontend/src/views/Files.vue @@ -112,9 +112,10 @@ export default { try { // Fetch initial data let res = await filesApi.fetchFiles(getters.routePath()); + console.log("fetched", res.name); // If not a directory, fetch content if (res.type != "directory") { - const content = !getters.onlyOfficeEnabled() + const content = !getters.onlyOfficeEnabled(); res = await filesApi.fetchFiles(getters.routePath(), content); } data = res; diff --git a/frontend/src/views/files/ListingView.vue b/frontend/src/views/files/ListingView.vue index 1429b5ea5..4c17c98d3 100644 --- a/frontend/src/views/files/ListingView.vue +++ b/frontend/src/views/files/ListingView.vue @@ -11,7 +11,13 @@