json response + imported old drag and drop uploader
This commit is contained in:
parent
350338baa4
commit
8caae56b39
|
@ -15,15 +15,18 @@ var Config struct {
|
||||||
bind string
|
bind string
|
||||||
filesDir string
|
filesDir string
|
||||||
siteName string
|
siteName string
|
||||||
|
siteURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
|
flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
|
||||||
"host to bind to (default: 127.0.0.1:8080)")
|
"host to bind to (default: 127.0.0.1:8080)")
|
||||||
flag.StringVar(&Config.filesDir, "d", "files/",
|
flag.StringVar(&Config.filesDir, "filespath", "files/",
|
||||||
"path to files directory (default: files/)")
|
"path to files directory (default: files/)")
|
||||||
flag.StringVar(&Config.siteName, "n", "linx",
|
flag.StringVar(&Config.siteName, "sitename", "linx",
|
||||||
"name of the site")
|
"name of the site")
|
||||||
|
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
|
||||||
|
"site base url (including trailing slash)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Disable template caching -- keep until out of pre-alpha
|
// Disable template caching -- keep until out of pre-alpha
|
||||||
|
|
|
@ -352,7 +352,7 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
.qq-upload-file {}
|
.qq-upload-file {}
|
||||||
.qq-upload-spinner {display:inline-block; background: url("/images/loading.gif"); width:15px; height:15px; vertical-align:text-bottom;}
|
.qq-upload-spinner {display:inline-block; width:15px; height:15px; vertical-align:text-bottom;}
|
||||||
.qq-upload-size,.qq-upload-cancel {font-size:11px;}
|
.qq-upload-size,.qq-upload-cancel {font-size:11px;}
|
||||||
|
|
||||||
.qq-upload-failed-text {display:none;}
|
.qq-upload-failed-text {display:none;}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,6 @@
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
|
||||||
<form action="/upload" method="POST" enctype="multipart/form-data">
|
<form action="/upload" method="POST" enctype="multipart/form-data">
|
||||||
|
|
||||||
<div id="file-uploader" style="min-width: 400px;">
|
<div id="file-uploader" style="min-width: 400px;">
|
||||||
<br />
|
<br />
|
||||||
<input type="file" name="file" id="file_upload" name="file"><br/ ><br/ >
|
<input type="file" name="file" id="file_upload" name="file"><br/ ><br/ >
|
||||||
|
@ -42,4 +41,18 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function downloadJSAtOnload() {
|
||||||
|
var element = document.createElement("script");
|
||||||
|
element.src = "/static/js/cat.js";
|
||||||
|
document.body.appendChild(element);
|
||||||
|
}
|
||||||
|
if (window.addEventListener)
|
||||||
|
window.addEventListener("load", downloadJSAtOnload, false);
|
||||||
|
else if (window.attachEvent)
|
||||||
|
window.attachEvent("onload", downloadJSAtOnload);
|
||||||
|
else window.onload = downloadJSAtOnload;
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
21
upload.go
21
upload.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -30,15 +31,21 @@ type Upload struct {
|
||||||
func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
upReq := UploadRequest{}
|
upReq := UploadRequest{}
|
||||||
|
|
||||||
|
if r.Header.Get("Content-Type") == "application/octet-stream" {
|
||||||
|
defer r.Body.Close()
|
||||||
|
upReq.src = r.Body
|
||||||
|
upReq.filename = r.URL.Query().Get("qqfile")
|
||||||
|
|
||||||
|
} else {
|
||||||
file, headers, err := r.FormFile("file")
|
file, headers, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
upReq.src = file
|
upReq.src = file
|
||||||
upReq.filename = headers.Filename
|
upReq.filename = headers.Filename
|
||||||
|
}
|
||||||
|
|
||||||
upload, err := processUpload(upReq)
|
upload, err := processUpload(upReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,9 +53,21 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
|
||||||
|
js, _ := json.Marshal(map[string]string{
|
||||||
|
"filename": upload.Filename,
|
||||||
|
"url": Config.siteURL + upload.Filename,
|
||||||
|
})
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
w.Write(js)
|
||||||
|
|
||||||
|
} else {
|
||||||
http.Redirect(w, r, "/"+upload.Filename, 301)
|
http.Redirect(w, r, "/"+upload.Filename, 301)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
upReq := UploadRequest{}
|
upReq := UploadRequest{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue