diff --git a/CHANGELOG.md b/CHANGELOG.md index 050c1d16..8e2e03ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,41 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.17.2](https://github.com/filebrowser/filebrowser/compare/v2.17.1...v2.17.2) (2021-08-27) + + +### Bug Fixes + +* bug with inlineLink not creating url properly ([#1515](https://github.com/filebrowser/filebrowser/issues/1515)) ([43a4609](https://github.com/filebrowser/filebrowser/commit/43a460993c3f0d158b876db4b20caa7963e9f361)) + +### [2.17.1](https://github.com/filebrowser/filebrowser/compare/v2.17.0...v2.17.1) (2021-08-23) + + +### Bug Fixes + +* internal server error if --disable-preview-resize flag is set (closes [#1510](https://github.com/filebrowser/filebrowser/issues/1510)) ([4c3099a](https://github.com/filebrowser/filebrowser/commit/4c3099a086c206dcb3bc70ee8c8da02eee61c30b)) + +## [2.17.0](https://github.com/filebrowser/filebrowser/compare/v2.16.1...v2.17.0) (2021-08-21) + + +### Features + +* open file option on preview ([76add9e](https://github.com/filebrowser/filebrowser/commit/76add9e5274b0373c6b983e3b20e387a14ea6c9e)) + + +### Bug Fixes + +* 401 error in share view open file button ([#1495](https://github.com/filebrowser/filebrowser/issues/1495)) ([25c8788](https://github.com/filebrowser/filebrowser/commit/25c87883908babde073390a2e2320a8e5880a87c)) +* escape quote on index template ([23d646c](https://github.com/filebrowser/filebrowser/commit/23d646c456876d06cf48e71c1e57b69de99511f0)), closes [#1501](https://github.com/filebrowser/filebrowser/issues/1501) +* file caching directive ([c63cc5a](https://github.com/filebrowser/filebrowser/commit/c63cc5a2d25909cc4e2f2e7235f276ec66c32bf2)) + +### [2.16.1](https://github.com/filebrowser/filebrowser/compare/v2.16.0...v2.16.1) (2021-08-04) + + +### Bug Fixes + +* check symlink target type (closes [#1488](https://github.com/filebrowser/filebrowser/issues/1488)) ([76b466f](https://github.com/filebrowser/filebrowser/commit/76b466f6492e74cf13e66a33e7e5f597ac92b240)) + ## [2.16.0](https://github.com/filebrowser/filebrowser/compare/v2.15.0...v2.16.0) (2021-07-26) diff --git a/files/file.go b/files/file.go index feecd81d..1cb53d90 100644 --- a/files/file.go +++ b/files/file.go @@ -127,6 +127,7 @@ func stat(opts FileOptions) (*FileInfo, error) { // set correct file size in case of symlink if file != nil && file.IsSymlink { file.Size = info.Size() + file.IsDir = info.IsDir() return file, nil } diff --git a/frontend/src/css/styles.css b/frontend/src/css/styles.css index 6e6d6ba2..5cff40fa 100644 --- a/frontend/src/css/styles.css +++ b/frontend/src/css/styles.css @@ -205,6 +205,34 @@ main .spinner .bounce2 { height: 100%; } +#previewer .preview .info { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 1.5em; + color: #fff; +} +#previewer .preview .info .title { + margin-bottom: 1em; +} +#previewer .preview .info .title i { + display: block; + margin-bottom: .1em; + font-size: 4em; +} +#previewer .preview .info .button { + display: inline-block; +} +#previewer .preview .info .button:hover { + background-color: rgba(255, 255, 255, 0.2) +} +#previewer .preview .info .button i { + display: block; + margin-bottom: 4px; + font-size: 1.3em; +} + #previewer .pdf { width: 100%; height: 100%; diff --git a/frontend/src/i18n/en_GB.json b/frontend/src/i18n/en_GB.json index 3925faec..3c9f3a7c 100644 --- a/frontend/src/i18n/en_GB.json +++ b/frontend/src/i18n/en_GB.json @@ -73,7 +73,8 @@ "size": "Size", "sortByLastModified": "Sort by last modified", "sortByName": "Sort by name", - "sortBySize": "Sort by size" + "sortBySize": "Sort by size", + "noPreview": "Preview is not available for this file." }, "help": { "click": "select file or directory", diff --git a/frontend/src/views/Share.vue b/frontend/src/views/Share.vue index bad206ca..c1b79e65 100644 --- a/frontend/src/views/Share.vue +++ b/frontend/src/views/Share.vue @@ -93,7 +93,7 @@ @@ -239,6 +239,11 @@ export default { const path = this.$route.path.split("/").splice(2).join("/"); return `${baseURL}/api/public/dl/${path}${queryArg}`; }, + inlineLink: function () { + let url = new URL(this.fullLink); + url.searchParams.set("inline", "true"); + return url.href; + }, fullLink: function () { return window.location.origin + this.link; }, diff --git a/frontend/src/views/files/Preview.vue b/frontend/src/views/files/Preview.vue index 3fb23a5b..013e526f 100644 --- a/frontend/src/views/files/Preview.vue +++ b/frontend/src/views/files/Preview.vue @@ -89,12 +89,31 @@ class="pdf" :data="raw" > - -

- {{ $t("buttons.download") }} - file_download -

-
+
+
+ feedback + {{ $t("files.noPreview") }} +
+
+ +
+ file_download{{ $t("buttons.download") }} +
+
+ +
+ open_in_new{{ $t("buttons.openFile") }} +
+
+
+
diff --git a/http/preview.go b/http/preview.go index 051498ba..48d4ded0 100644 --- a/http/preview.go +++ b/http/preview.go @@ -68,10 +68,21 @@ func previewHandler(imgSvc ImgService, fileCache FileCache, enableThumbnails, re }) } -func handleImagePreview(w http.ResponseWriter, r *http.Request, imgSvc ImgService, fileCache FileCache, - file *files.FileInfo, previewSize PreviewSize, enableThumbnails, resizePreview bool) (int, error) { - format, err := imgSvc.FormatFromExtension(file.Extension) +func handleImagePreview( + w http.ResponseWriter, + r *http.Request, + imgSvc ImgService, + fileCache FileCache, + file *files.FileInfo, + previewSize PreviewSize, + enableThumbnails, resizePreview bool, +) (int, error) { + if (previewSize == PreviewSizeBig && !resizePreview) || + (previewSize == PreviewSizeThumb && !enableThumbnails) { + return rawFileHandler(w, r, file) + } + format, err := imgSvc.FormatFromExtension(file.Extension) // Unsupported extensions directly return the raw data if err == img.ErrUnsupportedFormat || format == img.FormatGif { return rawFileHandler(w, r, file) @@ -80,33 +91,26 @@ func handleImagePreview(w http.ResponseWriter, r *http.Request, imgSvc ImgServic return errToStatus(err), err } - isFresh := checkEtag(w, r, file.ModTime.Unix(), file.Size) - if isFresh { - return http.StatusNotModified, nil - } - cacheKey := previewCacheKey(file.Path, file.ModTime.Unix(), previewSize) - cachedFile, ok, err := fileCache.Load(r.Context(), cacheKey) + resizedImage, ok, err := fileCache.Load(r.Context(), cacheKey) if err != nil { return errToStatus(err), err } - if ok { - _, _ = w.Write(cachedFile) - return 0, nil + if !ok { + resizedImage, err = createPreview(imgSvc, fileCache, file, previewSize) + if err != nil { + return errToStatus(err), err + } } - resizedImage, err := createPreview(imgSvc, fileCache, file, previewSize, enableThumbnails, resizePreview) - if err != nil { - return errToStatus(err), err - } - - _, _ = w.Write(resizedImage.Bytes()) + w.Header().Set("Cache-Control", "private") + http.ServeContent(w, r, file.Name, file.ModTime, bytes.NewReader(resizedImage)) return 0, nil } func createPreview(imgSvc ImgService, fileCache FileCache, - file *files.FileInfo, previewSize PreviewSize, enableThumbnails, resizePreview bool) (*bytes.Buffer, error) { + file *files.FileInfo, previewSize PreviewSize) ([]byte, error) { fd, err := file.Fs.Open(file.Path) if err != nil { return nil, err @@ -120,11 +124,11 @@ func createPreview(imgSvc ImgService, fileCache FileCache, ) switch { - case previewSize == PreviewSizeBig && resizePreview: + case previewSize == PreviewSizeBig: width = 1080 height = 1080 options = append(options, img.WithMode(img.ResizeModeFit), img.WithQuality(img.QualityMedium)) - case previewSize == PreviewSizeThumb && enableThumbnails: + case previewSize == PreviewSizeThumb: width = 128 height = 128 options = append(options, img.WithMode(img.ResizeModeFill), img.WithQuality(img.QualityLow), img.WithFormat(img.FormatJpeg)) @@ -144,7 +148,7 @@ func createPreview(imgSvc ImgService, fileCache FileCache, } }() - return buf, nil + return buf.Bytes(), nil } func previewCacheKey(fPath string, fTime int64, previewSize PreviewSize) string { diff --git a/http/raw.go b/http/raw.go index a24d474a..5004365a 100644 --- a/http/raw.go +++ b/http/raw.go @@ -200,11 +200,6 @@ func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files. } func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo) (int, error) { - isFresh := checkEtag(w, r, file.ModTime.Unix(), file.Size) - if isFresh { - return http.StatusNotModified, nil - } - fd, err := file.Fs.Open(file.Path) if err != nil { return http.StatusInternalServerError, err @@ -213,6 +208,7 @@ func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo setContentDisposition(w, r, file) + w.Header().Set("Cache-Control", "private") http.ServeContent(w, r, file.Name, file.ModTime, fd) return 0, nil } diff --git a/http/static.go b/http/static.go index 88313ae5..2b0b0af8 100644 --- a/http/static.go +++ b/http/static.go @@ -80,7 +80,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys return http.StatusInternalServerError, err } - data["Json"] = string(b) + data["Json"] = strings.ReplaceAll(string(b), `'`, `\'`) fileContents, err := fs.ReadFile(fSys, file) if err != nil { diff --git a/http/utils.go b/http/utils.go index 48ae2f40..c1c3fa65 100644 --- a/http/utils.go +++ b/http/utils.go @@ -3,7 +3,6 @@ package http import ( "encoding/json" "errors" - "fmt" "net/http" "net/url" "os" @@ -67,11 +66,3 @@ func stripPrefix(prefix string, h http.Handler) http.Handler { h.ServeHTTP(w, r2) }) } - -func checkEtag(w http.ResponseWriter, r *http.Request, fTime, fSize int64) bool { - etag := fmt.Sprintf("%x%x", fTime, fSize) - w.Header().Set("Cache-Control", "private") - w.Header().Set("Etag", etag) - - return r.Header.Get("If-None-Match") == etag -}