Merge pull request #1339 from ramiresviana/fixes-7

Some fixes
This commit is contained in:
Oleg Lobanov 2021-03-19 17:32:41 +01:00 committed by GitHub
commit d2e6d23741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 7 deletions

View File

@ -148,12 +148,15 @@ func (i *FileInfo) detectType(modify, saveContent, readHeader bool) error {
// of files couldn't be opened: we'd have immediately
// a 500 even though it doesn't matter. So we just log it.
var buffer []byte
mimetype := mime.TypeByExtension(i.Extension)
if mimetype == "" && readHeader {
var buffer []byte
if readHeader {
buffer = i.readFirstBytes()
mimetype = http.DetectContentType(buffer)
if mimetype == "" {
mimetype = http.DetectContentType(buffer)
}
}
switch {

View File

@ -31,7 +31,7 @@
<a target="_blank" :href="link" class="button button--flat">{{ $t('buttons.download') }}</a>
</div>
<div class="share__box__element share__box__center">
<qrcode-vue :value="link" size="200" level="M"></qrcode-vue>
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
</div>
</div>
<div v-if="req.isDir && req.items.length > 0" class="share__box share__box__items">
@ -161,6 +161,9 @@ export default {
const path = this.$route.path.split('/').splice(2).join('/')
return `${baseURL}/api/public/dl/${path}${queryArg}`
},
fullLink: function () {
return window.location.origin + this.link
},
humanSize: function () {
if (this.req.isDir) {
return this.req.items.length

View File

@ -73,5 +73,5 @@ func handle(fn handleFunc, prefix string, store *storage.Storage, server *settin
}
})
return http.StripPrefix(prefix, handler)
return stripPrefix(prefix, handler)
}

View File

@ -56,11 +56,13 @@ func stripPrefix(prefix string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, prefix)
rp := strings.TrimPrefix(r.URL.RawPath, prefix)
r2 := new(http.Request)
*r2 = *r
r2.URL = new(url.URL)
*r2.URL = *r.URL
r2.URL.Path = p
r2.URL.RawPath = rp
h.ServeHTTP(w, r2)
})
}

View File

@ -22,7 +22,7 @@ type Rule struct {
// MatchHidden matches paths with a basename
// that begins with a dot.
func MatchHidden(path string) bool {
return strings.HasPrefix(filepath.Base(path), ".")
return path != "" && strings.HasPrefix(filepath.Base(path), ".")
}
// Matches matches a path against a rule.