Merge branch 'master' of https://github.com/filebrowser/filebrowser
commit
b09cadfc8e
35
CHANGELOG.md
35
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.
|
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)
|
## [2.16.0](https://github.com/filebrowser/filebrowser/compare/v2.15.0...v2.16.0) (2021-07-26)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@ func stat(opts FileOptions) (*FileInfo, error) {
|
||||||
// set correct file size in case of symlink
|
// set correct file size in case of symlink
|
||||||
if file != nil && file.IsSymlink {
|
if file != nil && file.IsSymlink {
|
||||||
file.Size = info.Size()
|
file.Size = info.Size()
|
||||||
|
file.IsDir = info.IsDir()
|
||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,34 @@ main .spinner .bounce2 {
|
||||||
height: 100%;
|
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 {
|
#previewer .pdf {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
|
@ -73,7 +73,8 @@
|
||||||
"size": "Size",
|
"size": "Size",
|
||||||
"sortByLastModified": "Sort by last modified",
|
"sortByLastModified": "Sort by last modified",
|
||||||
"sortByName": "Sort by name",
|
"sortByName": "Sort by name",
|
||||||
"sortBySize": "Sort by size"
|
"sortBySize": "Sort by size",
|
||||||
|
"noPreview": "Preview is not available for this file."
|
||||||
},
|
},
|
||||||
"help": {
|
"help": {
|
||||||
"click": "select file or directory",
|
"click": "select file or directory",
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
:href="link + '?inline=true'"
|
:href="inlineLink"
|
||||||
class="button button--flat"
|
class="button button--flat"
|
||||||
v-if="!req.isDir"
|
v-if="!req.isDir"
|
||||||
>
|
>
|
||||||
|
@ -239,6 +239,11 @@ export default {
|
||||||
const path = this.$route.path.split("/").splice(2).join("/");
|
const path = this.$route.path.split("/").splice(2).join("/");
|
||||||
return `${baseURL}/api/public/dl/${path}${queryArg}`;
|
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 () {
|
fullLink: function () {
|
||||||
return window.location.origin + this.link;
|
return window.location.origin + this.link;
|
||||||
},
|
},
|
||||||
|
|
|
@ -89,12 +89,31 @@
|
||||||
class="pdf"
|
class="pdf"
|
||||||
:data="raw"
|
:data="raw"
|
||||||
></object>
|
></object>
|
||||||
<a v-else-if="req.type == 'blob'" :href="downloadUrl">
|
<div v-else-if="req.type == 'blob'" class="info">
|
||||||
<h2 class="message">
|
<div class="title">
|
||||||
{{ $t("buttons.download") }}
|
<i class="material-icons">feedback</i>
|
||||||
<i class="material-icons">file_download</i>
|
{{ $t("files.noPreview") }}
|
||||||
</h2>
|
</div>
|
||||||
</a>
|
<div>
|
||||||
|
<a target="_blank" :href="downloadUrl" class="button button--flat">
|
||||||
|
<div>
|
||||||
|
<i class="material-icons">file_download</i
|
||||||
|
>{{ $t("buttons.download") }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
target="_blank"
|
||||||
|
:href="downloadUrl + '&inline=true'"
|
||||||
|
class="button button--flat"
|
||||||
|
v-if="!req.isDir"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<i class="material-icons">open_in_new</i
|
||||||
|
>{{ $t("buttons.openFile") }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,21 @@ func previewHandler(imgSvc ImgService, fileCache FileCache, enableThumbnails, re
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleImagePreview(w http.ResponseWriter, r *http.Request, imgSvc ImgService, fileCache FileCache,
|
func handleImagePreview(
|
||||||
file *files.FileInfo, previewSize PreviewSize, enableThumbnails, resizePreview bool) (int, error) {
|
w http.ResponseWriter,
|
||||||
format, err := imgSvc.FormatFromExtension(file.Extension)
|
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
|
// Unsupported extensions directly return the raw data
|
||||||
if err == img.ErrUnsupportedFormat || format == img.FormatGif {
|
if err == img.ErrUnsupportedFormat || format == img.FormatGif {
|
||||||
return rawFileHandler(w, r, file)
|
return rawFileHandler(w, r, file)
|
||||||
|
@ -80,33 +91,26 @@ func handleImagePreview(w http.ResponseWriter, r *http.Request, imgSvc ImgServic
|
||||||
return errToStatus(err), err
|
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)
|
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 {
|
if err != nil {
|
||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
}
|
}
|
||||||
if ok {
|
if !ok {
|
||||||
_, _ = w.Write(cachedFile)
|
resizedImage, err = createPreview(imgSvc, fileCache, file, previewSize)
|
||||||
return 0, nil
|
if err != nil {
|
||||||
|
return errToStatus(err), err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resizedImage, err := createPreview(imgSvc, fileCache, file, previewSize, enableThumbnails, resizePreview)
|
w.Header().Set("Cache-Control", "private")
|
||||||
if err != nil {
|
http.ServeContent(w, r, file.Name, file.ModTime, bytes.NewReader(resizedImage))
|
||||||
return errToStatus(err), err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _ = w.Write(resizedImage.Bytes())
|
|
||||||
|
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createPreview(imgSvc ImgService, fileCache FileCache,
|
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)
|
fd, err := file.Fs.Open(file.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -120,11 +124,11 @@ func createPreview(imgSvc ImgService, fileCache FileCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case previewSize == PreviewSizeBig && resizePreview:
|
case previewSize == PreviewSizeBig:
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 1080
|
height = 1080
|
||||||
options = append(options, img.WithMode(img.ResizeModeFit), img.WithQuality(img.QualityMedium))
|
options = append(options, img.WithMode(img.ResizeModeFit), img.WithQuality(img.QualityMedium))
|
||||||
case previewSize == PreviewSizeThumb && enableThumbnails:
|
case previewSize == PreviewSizeThumb:
|
||||||
width = 128
|
width = 128
|
||||||
height = 128
|
height = 128
|
||||||
options = append(options, img.WithMode(img.ResizeModeFill), img.WithQuality(img.QualityLow), img.WithFormat(img.FormatJpeg))
|
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 {
|
func previewCacheKey(fPath string, fTime int64, previewSize PreviewSize) string {
|
||||||
|
|
|
@ -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) {
|
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)
|
fd, err := file.Fs.Open(file.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
@ -213,6 +208,7 @@ func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo
|
||||||
|
|
||||||
setContentDisposition(w, r, file)
|
setContentDisposition(w, r, file)
|
||||||
|
|
||||||
|
w.Header().Set("Cache-Control", "private")
|
||||||
http.ServeContent(w, r, file.Name, file.ModTime, fd)
|
http.ServeContent(w, r, file.Name, file.ModTime, fd)
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data["Json"] = string(b)
|
data["Json"] = strings.ReplaceAll(string(b), `'`, `\'`)
|
||||||
|
|
||||||
fileContents, err := fs.ReadFile(fSys, file)
|
fileContents, err := fs.ReadFile(fSys, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package http
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -67,11 +66,3 @@ func stripPrefix(prefix string, h http.Handler) http.Handler {
|
||||||
h.ServeHTTP(w, r2)
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue