|
|
|
@ -18,7 +18,6 @@ type SwampFileService struct {
|
|
|
|
|
eventBus util.EventBus
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewSwampFileService(
|
|
|
|
|
ns_svc namespace.NamespaceService,
|
|
|
|
|
swamp_file_repo swampfile.Repository,
|
|
|
|
@ -29,12 +28,10 @@ func NewSwampFileService(
|
|
|
|
|
return &s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s SwampFileService) NamespaceStats() []namespace.Namespace {
|
|
|
|
|
return s.ns_svc.All()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, size int64) error {
|
|
|
|
|
ns := s.ns_svc.GetOrCreateNs(ref.UserAgent)
|
|
|
|
|
|
|
|
|
@ -57,7 +54,8 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
|
|
|
|
|
s.eventBus.Handle(*util.NewEvent("FileUsed", struct {
|
|
|
|
|
Name string
|
|
|
|
|
Size int64}{
|
|
|
|
|
Size int64
|
|
|
|
|
}{
|
|
|
|
|
ns.Name,
|
|
|
|
|
f.Size(),
|
|
|
|
|
}))
|
|
|
|
@ -65,7 +63,6 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
// TODO: rewrite this into an interruptable loop that emits downloaded events
|
|
|
|
|
written, err := io.CopyN(f, src, size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if written < size {
|
|
|
|
|
s.swamp_file_repo.Delete(r.Path, strconv.FormatInt(ns.ID, 10)) //
|
|
|
|
|
return swampfile.ErrContentSizeExaggerated
|
|
|
|
@ -83,7 +80,8 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
f.Close()
|
|
|
|
|
s.eventBus.Handle(*util.NewEvent("FileRecieved", struct {
|
|
|
|
|
Name string
|
|
|
|
|
Size int64}{
|
|
|
|
|
Size int64
|
|
|
|
|
}{
|
|
|
|
|
ns.Name,
|
|
|
|
|
written,
|
|
|
|
|
}))
|
|
|
|
@ -125,7 +123,8 @@ func (s SwampFileService) CleanUpExpiredFiles() error {
|
|
|
|
|
for _, df := range dfs {
|
|
|
|
|
s.eventBus.Handle(*util.NewEvent("FileDeleted", struct {
|
|
|
|
|
Name string
|
|
|
|
|
Size int64}{
|
|
|
|
|
Size int64
|
|
|
|
|
}{
|
|
|
|
|
ns.Name,
|
|
|
|
|
df.Size,
|
|
|
|
|
}))
|
|
|
|
|