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