1
0

Moved http server to internal.

This commit is contained in:
Alexander Andreev 2023-04-24 00:49:53 +04:00
parent 762f8e12c2
commit d5aa919a37
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 8 additions and 10 deletions

View File

@ -2,9 +2,8 @@ package main
import (
"dwelling-upload/internal/configuration"
"dwelling-upload/internal/handlers"
"dwelling-upload/internal/http"
"dwelling-upload/pkg/logging"
"dwelling-upload/pkg/server"
"dwelling-upload/pkg/utils"
"dwelling-upload/pkg/watcher"
"flag"
@ -81,8 +80,8 @@ func main() {
watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
hand := handlers.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize)
srv := server.NewHttpServer()
hand := http.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize)
srv := http.NewHttpServer()
srv.SetNotFoundHandler(hand.NotFound)
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())

View File

@ -1,10 +1,9 @@
package handlers
package http
import (
"crypto/sha256"
"dwelling-upload/internal/configuration"
"dwelling-upload/pkg/logging"
"dwelling-upload/pkg/server"
"dwelling-upload/pkg/utils"
"dwelling-upload/web"
"encoding/base64"
@ -153,7 +152,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
}
func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
saltedHash := server.GetURLParam(r, "hash")
saltedHash := GetURLParam(r, "hash")
path := path.Join(h.conf.Uploads.Directory, saltedHash)
@ -163,7 +162,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
return
}
name := server.GetURLParam(r, "name")
name := GetURLParam(r, "name")
w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", name))
@ -185,7 +184,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
var saltedHash string
if r.Method == "DELETE" {
saltedHash = server.GetURLParam(r, "hash")
saltedHash = GetURLParam(r, "hash")
} else {
r.ParseForm()
saltedHash = r.FormValue("hash")

View File

@ -1,4 +1,4 @@
package server
package http
import (
"context"