Compare commits
2 Commits
v1.0.0-rc1
...
v1.0.0-rc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d2e0ad8cd | ||
|
|
9bb92172b6 |
@@ -145,7 +145,7 @@ Create a new config file ```/etc/nginx/sites-available/uploads.myserver.tld```:
|
|||||||
|
|
||||||
Enable the new config:
|
Enable the new config:
|
||||||
|
|
||||||
ln -s /etc/ngin/sites-available/uploads.myserver.tld /etc/nginx/sites-enabled/
|
ln -s /etc/nginx/sites-available/uploads.myserver.tld /etc/nginx/sites-enabled/
|
||||||
|
|
||||||
Check Nginx config:
|
Check Nginx config:
|
||||||
|
|
||||||
|
|||||||
17
main.go
17
main.go
@@ -14,6 +14,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -70,14 +71,11 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
* Check if the request is valid
|
* Check if the request is valid
|
||||||
*/
|
*/
|
||||||
mac := hmac.New(sha256.New, []byte(conf.Secret))
|
mac := hmac.New(sha256.New, []byte(conf.Secret))
|
||||||
log.Println("Secret:", conf.Secret)
|
|
||||||
log.Println("fileStorePath:", fileStorePath)
|
log.Println("fileStorePath:", fileStorePath)
|
||||||
log.Println("ContentLength:", strconv.FormatInt(r.ContentLength, 10))
|
log.Println("ContentLength:", strconv.FormatInt(r.ContentLength, 10))
|
||||||
mac.Write([]byte(fileStorePath + " " + strconv.FormatInt(r.ContentLength, 10)))
|
mac.Write([]byte(fileStorePath + " " + strconv.FormatInt(r.ContentLength, 10)))
|
||||||
macString := hex.EncodeToString(mac.Sum(nil))
|
macString := hex.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
log.Println("MAC wanted:", macString)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether calculated (expected) MAC is the MAC that client send in "v" URL parameter
|
* Check whether calculated (expected) MAC is the MAC that client send in "v" URL parameter
|
||||||
*/
|
*/
|
||||||
@@ -113,9 +111,22 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "404 Not Found", 404)
|
http.Error(w, "404 Not Found", 404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find out the content type to sent correct header. There is a Go function for retrieving the
|
||||||
|
* MIME content type, but this does not work with encrypted files (=> OMEMO). Therefore we're just
|
||||||
|
* relying on file extensions.
|
||||||
|
*/
|
||||||
|
contentType := mime.TypeByExtension(filepath.Ext(fileStorePath))
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(fileinfo.Size(), 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(fileinfo.Size(), 10))
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
} else if r.Method == "GET" {
|
} else if r.Method == "GET" {
|
||||||
|
contentType := mime.TypeByExtension(filepath.Ext(fileStorePath))
|
||||||
|
if contentType == "" {
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
}
|
||||||
http.ServeFile(w, r, conf.Storedir+fileStorePath)
|
http.ServeFile(w, r, conf.Storedir+fileStorePath)
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
} else {
|
} else {
|
||||||
log.Println("Invalid method", r.Method, "for access to ", conf.UploadSubDir)
|
log.Println("Invalid method", r.Method, "for access to ", conf.UploadSubDir)
|
||||||
http.Error(w, "405 Method Not Allowed", 405)
|
http.Error(w, "405 Method Not Allowed", 405)
|
||||||
|
|||||||
Reference in New Issue
Block a user