Compare commits
3 Commits
f0254a6370
...
0a74ecf651
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a74ecf651 | |||
| 361123baca | |||
| 05e438eb23 |
8
Makefile
8
Makefile
@@ -2,7 +2,7 @@ BINARY = s3share
|
|||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: clean build
|
all: clean deps build
|
||||||
|
|
||||||
.PHONY:build
|
.PHONY:build
|
||||||
build: $(BUILD_DIR)/$(BINARY) $(BUILD_DIR)/public
|
build: $(BUILD_DIR)/$(BINARY) $(BUILD_DIR)/public
|
||||||
@@ -13,6 +13,12 @@ $(BUILD_DIR)/$(BINARY):
|
|||||||
$(BUILD_DIR)/public:
|
$(BUILD_DIR)/public:
|
||||||
npm run build && cp -r public/ $(BUILD_DIR)/public
|
npm run build && cp -r public/ $(BUILD_DIR)/public
|
||||||
|
|
||||||
|
.PHONY: deps
|
||||||
|
deps: node_modules
|
||||||
|
|
||||||
|
node_modules:
|
||||||
|
npm install
|
||||||
|
|
||||||
.PHONY:clean
|
.PHONY:clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR) && rm -rf public/build/
|
rm -rf $(BUILD_DIR) && rm -rf public/build/
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ type createShare struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type deleteShare struct {
|
|
||||||
Slug string `json:"slug"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func StartWebserver(addr string, client client.Client, username, password string) error {
|
func StartWebserver(addr string, client client.Client, username, password string) error {
|
||||||
if username == "" || password == "" {
|
if username == "" || password == "" {
|
||||||
return errors.New("API username and password must be set")
|
return errors.New("API username and password must be set")
|
||||||
@@ -74,6 +70,31 @@ func StartWebserver(addr string, client client.Client, username, password string
|
|||||||
json.NewEncoder(w).Encode(shares)
|
json.NewEncoder(w).Encode(shares)
|
||||||
}).Methods("GET")
|
}).Methods("GET")
|
||||||
|
|
||||||
|
r.HandleFunc("/api/share/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !checkAuth(w, r, username, password) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
slug := vars["slug"]
|
||||||
|
|
||||||
|
share, err := client.GetShare(r.Context(), slug)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err.Error())
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if share == nil {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(share)
|
||||||
|
}).Methods("GET")
|
||||||
|
|
||||||
r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if !checkAuth(w, r, username, password) {
|
if !checkAuth(w, r, username, password) {
|
||||||
return
|
return
|
||||||
@@ -100,20 +121,14 @@ func StartWebserver(addr string, client client.Client, username, password string
|
|||||||
json.NewEncoder(w).Encode(share)
|
json.NewEncoder(w).Encode(share)
|
||||||
}).Methods("POST")
|
}).Methods("POST")
|
||||||
|
|
||||||
r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/api/share/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if !checkAuth(w, r, username, password) {
|
if !checkAuth(w, r, username, password) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var shareParams deleteShare
|
vars := mux.Vars(r)
|
||||||
err := json.NewDecoder(r.Body).Decode(&shareParams)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err.Error())
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = client.DeleteShare(r.Context(), shareParams.Slug)
|
err := client.DeleteShare(r.Context(), vars["slug"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err.Error())
|
logrus.Error(err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|||||||
Reference in New Issue
Block a user