Added ability to share folder for view rendering
This commit is contained in:
parent
05bfae264a
commit
3c56c91c46
@ -34,3 +34,6 @@ export async function create(url, password = "", expires = "", unit = "hours") {
|
||||
export function getShareURL(share) {
|
||||
return createURL("share/" + share.hash, {}, false);
|
||||
}
|
||||
export function getViewURL(share) {
|
||||
return createURL("api/public/view/" + share.hash + "/index.html", {}, false);
|
||||
}
|
||||
|
||||
@ -32,6 +32,16 @@
|
||||
<i class="material-icons">content_paste</i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="small">
|
||||
<button
|
||||
class="action copy-clipboard"
|
||||
:data-clipboard-text="buildViewLink(link)"
|
||||
:aria-label="$t('buttons.copyToClipboard')"
|
||||
:title="$t('buttons.copyToClipboard')"
|
||||
>
|
||||
<i class="material-icons">content_paste_search</i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="small" v-if="hasDownloadLink()">
|
||||
<button
|
||||
class="action copy-clipboard"
|
||||
@ -225,6 +235,9 @@ export default {
|
||||
buildLink(share) {
|
||||
return api.getShareURL(share);
|
||||
},
|
||||
buildViewLink(share) {
|
||||
return api.getViewURL(share);
|
||||
},
|
||||
hasDownloadLink() {
|
||||
return (
|
||||
this.selected.length === 1 && !this.req.items[this.selected[0]].isDir
|
||||
|
||||
@ -88,6 +88,7 @@ func NewHandler(
|
||||
|
||||
public := api.PathPrefix("/public").Subrouter()
|
||||
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
||||
public.PathPrefix("/view").Handler(monkey(publicViewHandler, "/api/public/view/")).Methods("GET")
|
||||
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
||||
|
||||
return stripPrefix(server.BaseURL, r), nil
|
||||
|
||||
@ -115,6 +115,15 @@ var publicDlHandler = withHashFile(func(w http.ResponseWriter, r *http.Request,
|
||||
return rawDirHandler(w, r, d, file)
|
||||
})
|
||||
|
||||
var publicViewHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
file := d.raw.(*files.FileInfo)
|
||||
if !file.IsDir {
|
||||
return rawFileHandler(w, r, file, false)
|
||||
}
|
||||
|
||||
return rawDirHandler(w, r, d, file, false)
|
||||
})
|
||||
|
||||
func authenticateShareRequest(r *http.Request, l *share.Link) (int, error) {
|
||||
if l.PasswordHash == "" {
|
||||
return 0, nil
|
||||
|
||||
15
http/raw.go
15
http/raw.go
@ -158,7 +158,7 @@ func addFile(ar archiver.Writer, d *data, path, commonPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files.FileInfo) (int, error) {
|
||||
func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files.FileInfo, setContentDispositionOptional ...bool) (int, error) {
|
||||
filenames, err := parseQueryFiles(r, file, d.user)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@ -187,7 +187,10 @@ func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files.
|
||||
name = "_" + name
|
||||
}
|
||||
name += extension
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name))
|
||||
|
||||
if len(setContentDispositionOptional) == 0 || (len(setContentDispositionOptional) > 0 && setContentDispositionOptional[0]) {
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name))
|
||||
}
|
||||
|
||||
for _, fname := range filenames {
|
||||
err = addFile(ar, d, fname, commonDir)
|
||||
@ -199,14 +202,18 @@ func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files.
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo) (int, error) {
|
||||
func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo, setContentDispositionOptional ...bool) (int, error) {
|
||||
fd, err := file.Fs.Open(file.Path)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
setContentDisposition(w, r, file)
|
||||
// Check if setContentDispositionOptional is provided and false
|
||||
if len(setContentDispositionOptional) == 0 || (len(setContentDispositionOptional) > 0 && setContentDispositionOptional[0]) {
|
||||
setContentDisposition(w, r, file)
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Security-Policy", `script-src 'none';`)
|
||||
w.Header().Set("Cache-Control", "private")
|
||||
http.ServeContent(w, r, file.Name, file.ModTime, fd)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user