This commit is contained in:
3
main.go
3
main.go
@@ -183,7 +183,7 @@ func main() {
|
|||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
content, err := folder.Storage.Get(fileName)
|
content, err := folder.Storage.Get(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", esimateMimeType(fileName))
|
w.Header().Set("Content-Type", esimateMimeType(fileName))
|
||||||
@@ -196,6 +196,7 @@ func main() {
|
|||||||
authKey := r.Header.Get("Authorization")
|
authKey := r.Header.Get("Authorization")
|
||||||
if authKey != apiKey {
|
if authKey != apiKey {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
log.Printf("auth value %s is not correct, current: %s", authKey, apiKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err := io.ReadAll(r.Body)
|
data, err := io.ReadAll(r.Body)
|
||||||
|
|||||||
@@ -40,15 +40,7 @@ func (ds *DiskStorage) Put(key string, data []byte) error {
|
|||||||
if err := ds.ensureDir(); err != nil {
|
if err := ds.ensureDir(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
f, err := os.Open(path.Join(ds.dir, key))
|
return os.WriteFile(path.Join(ds.dir, key), data, 0644)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = f.Write(data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return f.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DiskStorage) Delete(key string) error {
|
func (ds *DiskStorage) Delete(key string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user