mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 03:15:19 +08:00
Compare commits
2 Commits
9d09ee133d
...
in-browser
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
749fc07cb2 | ||
|
|
18173878c4 |
@@ -132,7 +132,8 @@ func InitialSettings() []model.SettingItem {
|
||||
"Google":"https://docs.google.com/gview?url=$e_url&embedded=true"
|
||||
},
|
||||
"pdf": {
|
||||
"PDF.js":"https://res.oplist.org/pdf.js/web/viewer.html?file=$e_url"
|
||||
"PDF.js":"https://res.oplist.org/pdf.js/web/viewer.html?file=$e_url",
|
||||
"Browser":"$url?inline_preview=true"
|
||||
},
|
||||
"epub": {
|
||||
"EPUB.js":"https://res.oplist.org/epub.js/viewer.html?url=$e_url"
|
||||
|
||||
@@ -18,14 +18,18 @@ import (
|
||||
)
|
||||
|
||||
func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
|
||||
|
||||
// check if query param "inline_preview" is true
|
||||
inlinePreview := r.URL.Query().Get("inline_preview") == "true"
|
||||
|
||||
if link.MFile != nil {
|
||||
attachHeader(w, file, link)
|
||||
attachHeader(w, file, link, inlinePreview)
|
||||
http.ServeContent(w, r, file.GetName(), file.ModTime(), link.MFile)
|
||||
return nil
|
||||
}
|
||||
|
||||
if link.Concurrency > 0 || link.PartSize > 0 {
|
||||
attachHeader(w, file, link)
|
||||
attachHeader(w, file, link, inlinePreview)
|
||||
size := link.ContentLength
|
||||
if size <= 0 {
|
||||
size = file.GetSize()
|
||||
@@ -40,7 +44,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
|
||||
}
|
||||
|
||||
if link.RangeReader != nil {
|
||||
attachHeader(w, file, link)
|
||||
attachHeader(w, file, link, inlinePreview)
|
||||
size := link.ContentLength
|
||||
if size <= 0 {
|
||||
size = file.GetSize()
|
||||
@@ -70,9 +74,11 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
|
||||
})
|
||||
return err
|
||||
}
|
||||
func attachHeader(w http.ResponseWriter, file model.Obj, link *model.Link) {
|
||||
func attachHeader(w http.ResponseWriter, file model.Obj, link *model.Link, inlinePreview bool) {
|
||||
fileName := file.GetName()
|
||||
w.Header().Set("Content-Disposition", utils.GenerateContentDisposition(fileName))
|
||||
if !inlinePreview {
|
||||
w.Header().Set("Content-Disposition", utils.GenerateContentDisposition(fileName))
|
||||
}
|
||||
w.Header().Set("Content-Type", utils.GetMimeType(fileName))
|
||||
size := link.ContentLength
|
||||
if size <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user