Skip to content

Commit

Permalink
add constant.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol committed Jul 1, 2024
1 parent b8905fc commit b98b9da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions core/util/breadcrumbs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"log/slog"

Check failure on line 4 in core/util/breadcrumbs.go

View workflow job for this annotation

GitHub Actions / build

"log/slog" imported and not used
"regexp"
"strings"
)
Expand Down
5 changes: 5 additions & 0 deletions web/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package web

const (
UPLOAD_DIR = "./upload"
)
13 changes: 6 additions & 7 deletions web/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/tttol/mos3/core/logging"
)


func IndexHandler(w http.ResponseWriter, r *http.Request) {
slog.Info("IndexHandler is called.")
logging.LogRequest(r)
Expand Down Expand Up @@ -63,7 +62,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
}
defer file.Close()

dst, err := os.Create(filepath.Join(uploadDir, header.Filename))
dst, err := os.Create(filepath.Join(UPLOAD_DIR, header.Filename))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -85,7 +84,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
}

filename := r.FormValue("filename")
err := os.Remove(filepath.Join(uploadDir, filename))
err := os.Remove(filepath.Join(UPLOAD_DIR, filename))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -102,7 +101,7 @@ func RenameHandler(w http.ResponseWriter, r *http.Request) {

oldFilename := r.FormValue("oldFilename")
newFilename := r.FormValue("newFilename")
err := os.Rename(filepath.Join(uploadDir, oldFilename), filepath.Join(uploadDir, newFilename))
err := os.Rename(filepath.Join(UPLOAD_DIR, oldFilename), filepath.Join(UPLOAD_DIR, newFilename))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -118,7 +117,7 @@ func MkdirHandler(w http.ResponseWriter, r *http.Request) {
}

dirname := r.FormValue("dirname")
err := os.Mkdir(filepath.Join(uploadDir, dirname), os.ModePerm)
err := os.Mkdir(filepath.Join(UPLOAD_DIR, dirname), os.ModePerm)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -134,7 +133,7 @@ func RmdirHandler(w http.ResponseWriter, r *http.Request) {
}

dirname := r.FormValue("dirname")
err := os.Remove(filepath.Join(uploadDir, dirname))
err := os.Remove(filepath.Join(UPLOAD_DIR, dirname))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -151,7 +150,7 @@ func RenamedirHandler(w http.ResponseWriter, r *http.Request) {

oldDirname := r.FormValue("oldDirname")
newDirname := r.FormValue("newDirname")
err := os.Rename(filepath.Join(uploadDir, oldDirname), filepath.Join(uploadDir, newDirname))
err := os.Rename(filepath.Join(UPLOAD_DIR, oldDirname), filepath.Join(UPLOAD_DIR, newDirname))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
4 changes: 0 additions & 4 deletions web/s3_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"github.com/tttol/mos3/core/util"
)

const (
UPLOAD_DIR = "./upload"
)

func S3Handler(w http.ResponseWriter, r *http.Request) {
slog.Info("S3Handler is called.")
path := r.URL.Path[len("/s3/"):]
Expand Down

0 comments on commit b98b9da

Please sign in to comment.