mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-11 11:40:23 +08:00
front: finish docx & back: init
This commit is contained in:
26
backend/file/provider.go
Normal file
26
backend/file/provider.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
"github.com/fumiama/paper-manager/backend/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Handler serves contents in global.FileFolder
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
if !utils.IsMethod("GET", w, r) {
|
||||
return
|
||||
}
|
||||
i := strings.LastIndex(r.URL.Path, "/")
|
||||
fn := r.URL.Path[i+1:]
|
||||
if fn == "" {
|
||||
http.Error(w, "400 Bad Request: empty path", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
name := global.FileFolder + fn
|
||||
logrus.Infoln("[file.Handler]\t serve", name)
|
||||
http.ServeFile(w, r, name)
|
||||
}
|
||||
Reference in New Issue
Block a user