|
|
@ -1,7 +1,7 @@
|
|
|
|
package domain
|
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
// "io"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -16,10 +16,13 @@ func NewBogFileService(user_agent_repo UserAgentRepository, file_data_repo FileD
|
|
|
|
return BogFileService {user_agent_repo, file_data_repo}
|
|
|
|
return BogFileService {user_agent_repo, file_data_repo}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b BogFileService) CreateOrOpenInFile(ref FileReference) (BogInFile ,error) {
|
|
|
|
func (b BogFileService) SaveFile(ref FileReference, src io.Reader, size int64) error {
|
|
|
|
|
|
|
|
|
|
|
|
user_agent, err := b.user_agent_repo.GetByName(ref.UserAgent)
|
|
|
|
user_agent, err := b.user_agent_repo.GetByName(ref.UserAgent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !user_agent.FileQuota.Allows(size) {
|
|
|
|
|
|
|
|
return ErrExceedQuota
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err == ErrNotExists {
|
|
|
|
if err == ErrNotExists {
|
|
|
|
// TODO make this into a factory method?
|
|
|
|
// TODO make this into a factory method?
|
|
|
|
new_ua := UserAgent {
|
|
|
|
new_ua := UserAgent {
|
|
|
@ -35,14 +38,16 @@ func (b BogFileService) CreateOrOpenInFile(ref FileReference) (BogInFile ,error)
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f, err := b.file_data_repo.Create(ref.Path, strconv.FormatInt(user_agent.ID, 10))
|
|
|
|
f, err := b.file_data_repo.Create(ref.Path, strconv.FormatInt(user_agent.ID, 10))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return f, err
|
|
|
|
io.Copy(f, src)
|
|
|
|
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b BogFileService) OpenOutFile(ref FileReference) (BogOutFile, error) {
|
|
|
|
func (b BogFileService) OpenOutFile(ref FileReference) (BogOutFile, error) {
|
|
|
|