mirror of
https://github.com/ZizzyDizzyMC/linx-server.git
synced 2026-01-23 02:14:33 +00:00
use abstracted storage for flexibility
I moved the storage functionality into the StorageBackend interface, which is currently only implemented by LocalfsBackend.
This commit is contained in:
parent
47670af185
commit
fcd18eceec
10 changed files with 154 additions and 77 deletions
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/zenazn/goji/web"
|
||||
)
|
||||
|
|
@ -13,11 +12,9 @@ func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||
requestKey := r.Header.Get("Linx-Delete-Key")
|
||||
|
||||
filename := c.URLParams["name"]
|
||||
filePath := path.Join(Config.filesDir, filename)
|
||||
metaPath := path.Join(Config.metaDir, filename)
|
||||
|
||||
// Ensure requested file actually exists
|
||||
if _, readErr := os.Stat(filePath); os.IsNotExist(readErr) {
|
||||
if _, readErr := fileBackend.Exists(filename); os.IsNotExist(readErr) {
|
||||
notFoundHandler(c, w, r) // 404 - file doesn't exist
|
||||
return
|
||||
}
|
||||
|
|
@ -30,8 +27,8 @@ func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if metadata.DeleteKey == requestKey {
|
||||
fileDelErr := os.Remove(filePath)
|
||||
metaDelErr := os.Remove(metaPath)
|
||||
fileDelErr := fileBackend.Delete(filename)
|
||||
metaDelErr := metaBackend.Delete(filename)
|
||||
|
||||
if (fileDelErr != nil) || (metaDelErr != nil) {
|
||||
oopsHandler(c, w, r, RespPLAIN, "Could not delete")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue