file-transfer/main.go
2025-02-07 00:24:26 +01:00

42 lines
818 B
Go

package main
import (
"log"
"net/http"
"os"
"regexp"
"github.com/rs/cors"
)
type LocalFile struct {
path string
passwordHash []byte
passwordSalt []byte
}
const storePath string = "/var/cache/file-transfer"
var localFiles = map[string]*LocalFile{}
var base64SpecialCharRegEx, base64SpecialCharErr = regexp.Compile(`[+/]`)
func main() {
if base64SpecialCharErr != nil {
log.Fatalf("Error while compiling regex: %s", base64SpecialCharErr)
}
os.RemoveAll(storePath)
os.MkdirAll(storePath, 0700)
router := http.NewServeMux()
router.HandleFunc("POST /", uploadFile)
router.HandleFunc("GET /", downloadFile)
router.HandleFunc("DELETE /", deleteFile)
router.HandleFunc("GET /info", fileInfo)
handler := cors.AllowAll().Handler(router)
log.Fatal(http.ListenAndServe(":4545", handler))
}