File downloading
This commit is contained in:
parent
86cedf9531
commit
eaf5e2fb95
12
main.go
12
main.go
@ -20,9 +20,9 @@ import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
const VERSION = "v0.1.4";
|
||||
const VERSION = "v0.1.5";
|
||||
const LISTEN_HOST = "0.0.0.0";
|
||||
const DB_SCHEMA = 5
|
||||
const DB_SCHEMA = 6
|
||||
|
||||
var (
|
||||
flagPort int
|
||||
@ -495,6 +495,10 @@ func nodeDownload(w http.ResponseWriter, r *http.Request) {// {{{
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", files[0].MIME)
|
||||
w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, files[0].Filename))
|
||||
w.Header().Add("Content-Length", strconv.Itoa(int(finfo.Size())))
|
||||
|
||||
read := 1
|
||||
var buf []byte
|
||||
for read > 0 {
|
||||
@ -505,10 +509,6 @@ func nodeDownload(w http.ResponseWriter, r *http.Request) {// {{{
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", files[0].MIME)
|
||||
w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, files[0].Filename))
|
||||
w.Header().Add("Content-Length", strconv.Itoa(int(finfo.Size())))
|
||||
|
||||
}// }}}
|
||||
func nodeFiles(w http.ResponseWriter, r *http.Request) {// {{{
|
||||
var err error
|
||||
|
5
sql/0006.sql
Normal file
5
sql/0006.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE public.file DROP CONSTRAINT file_node_fk;
|
||||
ALTER TABLE public.file ADD CONSTRAINT file_node_fk FOREIGN KEY (node_id) REFERENCES public.node(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE public.file DROP CONSTRAINT file_fk;
|
||||
ALTER TABLE public.file ADD CONSTRAINT file_user_fk FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -326,14 +326,15 @@ class Node {
|
||||
}),
|
||||
})
|
||||
.then(response=>{
|
||||
console.log(...response.headers);
|
||||
let match = response.headers.get('content-disposition').match(/filename="([^"]*)"/)
|
||||
fname = match[1]
|
||||
return response.blob()
|
||||
})
|
||||
.then(blob=>{
|
||||
let url = window.URL.createObjectURL(blob)
|
||||
let a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = "filename.xlsx";
|
||||
a.download = fname;
|
||||
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
|
||||
a.click();
|
||||
a.remove(); //afterwards we remove the element again
|
||||
|
Loading…
Reference in New Issue
Block a user