working commit

This commit is contained in:
2026-02-04 12:32:54 +02:00
parent 24b9acd678
commit 219a4cb890
17 changed files with 736 additions and 43 deletions
+42 -2
View File
@@ -25,8 +25,10 @@ func NewStorage(basepath string) *Storage {
return res
}
const filesubdir = "files"
const tmpsubdir = "tmps"
const (
filesubdir = "files"
tmpsubdir = "tmps"
)
func (store *Storage) makeCollecionpath(collection string) string {
return filepath.Join(store.basepath, filesubdir, collection)
@@ -135,3 +137,41 @@ func (store *Storage) DeleteFile(collection, filename string) error {
}
return err
}
const (
upsubdir = "uploads"
)
func (store *Storage) makeUppath(upname string) string {
return filepath.Join(store.basepath, upsubdir, upname)
}
func (store *Storage) WriteUpload(digest string, source io.Reader) (int64, error) {
var err error
var recsize int64
uploadPath := store.makeUppath(digest)
uploadFile, err := os.OpenFile(uploadPath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return recsize, err
}
defer uploadFile.Close()
hasher := sha256.New() // TODO: upload cheking
streamWriter := io.MultiWriter(uploadFile, hasher)
recsize, err = io.Copy(streamWriter, source)
if err != nil {
return recsize, err
}
return recsize, err
}
func (st *Storage) RemoveUpload(digest string) error {
var err error
uploadPath := st.makeUppath(digest)
err = os.Remove(uploadPath)
if err != nil {
return err
}
return err
}