refactor: update app instance structure to include both mailserver and logger
This commit is contained in:
@ -1,21 +1,15 @@
|
||||
package downloadHandler
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/view/client/download"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
||||
func init() {
|
||||
log = logger.Logger()
|
||||
}
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
files, err := db.DB.GetFiles(userSession.UserID.String())
|
||||
@ -38,7 +32,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
err = component.Render(r.Context(), w)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Error(err.Error())
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,20 @@
|
||||
package downloadFileHandler
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
||||
func init() {
|
||||
log = logger.Logger()
|
||||
}
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
fileID := r.PathValue("id")
|
||||
file, err := db.DB.GetFile(fileID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Error(err.Error())
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -31,7 +25,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
saveFolder := filepath.Join(basePath, file.OwnerID.String(), file.ID.String())
|
||||
|
||||
if filepath.Dir(saveFolder) != filepath.Join(basePath, file.OwnerID.String()) {
|
||||
log.Error("invalid path")
|
||||
app.Server.Logger.Error("invalid path")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -39,7 +33,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
openFile, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Error(err.Error())
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
defer openFile.Close()
|
||||
@ -47,7 +41,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
stat, err := openFile.Stat()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Error(err.Error())
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user