mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 03:09:33 -06:00
add a store to postprocessing
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -10,47 +10,41 @@ import (
|
||||
|
||||
// Postprocessing handles postprocessing of a file
|
||||
type Postprocessing struct {
|
||||
id string
|
||||
url string
|
||||
u *user.User
|
||||
m map[events.Postprocessingstep]interface{}
|
||||
filename string
|
||||
filesize uint64
|
||||
resourceID *provider.ResourceId
|
||||
steps []events.Postprocessingstep
|
||||
delay time.Duration
|
||||
ID string
|
||||
URL string
|
||||
User *user.User
|
||||
Filename string
|
||||
Filesize uint64
|
||||
ResourceID *provider.ResourceId
|
||||
Steps []events.Postprocessingstep
|
||||
PPDelay time.Duration
|
||||
}
|
||||
|
||||
// New returns a new postprocessing instance
|
||||
func New(uploadID string, uploadURL string, user *user.User, filename string, filesize uint64, resourceID *provider.ResourceId, steps []events.Postprocessingstep, delay time.Duration) *Postprocessing {
|
||||
return &Postprocessing{
|
||||
id: uploadID,
|
||||
url: uploadURL,
|
||||
u: user,
|
||||
m: make(map[events.Postprocessingstep]interface{}),
|
||||
filename: filename,
|
||||
filesize: filesize,
|
||||
resourceID: resourceID,
|
||||
steps: steps,
|
||||
delay: delay,
|
||||
ID: uploadID,
|
||||
URL: uploadURL,
|
||||
User: user,
|
||||
Filename: filename,
|
||||
Filesize: filesize,
|
||||
ResourceID: resourceID,
|
||||
Steps: steps,
|
||||
PPDelay: delay,
|
||||
}
|
||||
}
|
||||
|
||||
// Init is the first step of the postprocessing
|
||||
func (pp *Postprocessing) Init(ev events.BytesReceived) interface{} {
|
||||
pp.m["init"] = ev
|
||||
|
||||
if len(pp.steps) == 0 {
|
||||
if len(pp.Steps) == 0 {
|
||||
return pp.finished(events.PPOutcomeContinue)
|
||||
}
|
||||
|
||||
return pp.nextStep(pp.steps[0])
|
||||
return pp.nextStep(pp.Steps[0])
|
||||
}
|
||||
|
||||
// NextStep returns the next postprocessing step
|
||||
func (pp *Postprocessing) NextStep(ev events.PostprocessingStepFinished) interface{} {
|
||||
pp.m[ev.FinishedStep] = ev
|
||||
|
||||
switch ev.Outcome {
|
||||
case events.PPOutcomeContinue:
|
||||
return pp.next(ev.FinishedStep)
|
||||
@@ -62,16 +56,15 @@ func (pp *Postprocessing) NextStep(ev events.PostprocessingStepFinished) interfa
|
||||
|
||||
// Delay will sleep the configured time then continue
|
||||
func (pp *Postprocessing) Delay(ev events.StartPostprocessingStep) interface{} {
|
||||
pp.m[events.PPStepDelay] = ev
|
||||
time.Sleep(pp.delay)
|
||||
time.Sleep(pp.PPDelay)
|
||||
return pp.next(events.PPStepDelay)
|
||||
}
|
||||
|
||||
func (pp *Postprocessing) next(current events.Postprocessingstep) interface{} {
|
||||
l := len(pp.steps)
|
||||
for i, s := range pp.steps {
|
||||
l := len(pp.Steps)
|
||||
for i, s := range pp.Steps {
|
||||
if s == current && i+1 < l {
|
||||
return pp.nextStep(pp.steps[i+1])
|
||||
return pp.nextStep(pp.Steps[i+1])
|
||||
}
|
||||
}
|
||||
return pp.finished(events.PPOutcomeContinue)
|
||||
@@ -79,22 +72,21 @@ func (pp *Postprocessing) next(current events.Postprocessingstep) interface{} {
|
||||
|
||||
func (pp *Postprocessing) nextStep(next events.Postprocessingstep) events.StartPostprocessingStep {
|
||||
return events.StartPostprocessingStep{
|
||||
UploadID: pp.id,
|
||||
URL: pp.url,
|
||||
ExecutingUser: pp.u,
|
||||
Filename: pp.filename,
|
||||
Filesize: pp.filesize,
|
||||
ResourceID: pp.resourceID,
|
||||
UploadID: pp.ID,
|
||||
URL: pp.URL,
|
||||
ExecutingUser: pp.User,
|
||||
Filename: pp.Filename,
|
||||
Filesize: pp.Filesize,
|
||||
ResourceID: pp.ResourceID,
|
||||
StepToStart: next,
|
||||
}
|
||||
}
|
||||
|
||||
func (pp *Postprocessing) finished(outcome events.PostprocessingOutcome) events.PostprocessingFinished {
|
||||
return events.PostprocessingFinished{
|
||||
UploadID: pp.id,
|
||||
Result: pp.m,
|
||||
ExecutingUser: pp.u,
|
||||
Filename: pp.filename,
|
||||
UploadID: pp.ID,
|
||||
ExecutingUser: pp.User,
|
||||
Filename: pp.Filename,
|
||||
Outcome: outcome,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user