controller

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeOrFail

func DecodeOrFail(rd io.Reader, ctrl model.Controller, val interface{}) error

DecodeOrFail tries to decode val to ctrl and if it fails, it writes and returns an error.

func EventFsMkdir

func EventFsMkdir(path string) sse.Event

func EventFsMove

func EventFsMove(old, new string) sse.Event

func EventFsRemove

func EventFsRemove(path string) sse.Event

func EventOperationAll

func EventOperationAll(o map[string]*Operation) sse.Event

func EventOperationDone

func EventOperationDone(id string) sse.Event

func EventOperationError

func EventOperationError(id string, dst string, err model.OperationError) sse.Event

Methods that are only sent for the owner

func EventOperationLog

func EventOperationLog(id string, message string) sse.Event

func EventOperationNew

func EventOperationNew(o *Operation) sse.Event

func EventOperationProgress

func EventOperationProgress(id string, index int, size int64) sse.Event

Public methods that all subscribers get access to

func EventOperationStatus

func EventOperationStatus(id string, status uint8) sse.Event

func EventOperationUpdate

func EventOperationUpdate(o *Operation) sse.Event

func StatOrFail

func StatOrFail(ctrl model.Controller, fs afero.Fs, path string) (*model.FileInfo, error)

StatOrFail tries to stat a file in fs by it's path and if it fails, it writes and returns an error.

Types

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

Channel is a data structure that can collect an infinite amount of subscribers with the intent of sending events to each subscriber via its functions.

An empty Channel is ready to use.

func (*Channel) Announce

func (c *Channel) Announce(s sse.Event)

Announce sends an event to all subscribers.

func (*Channel) GetSubscriber

func (c *Channel) GetSubscriber(id string) chan sse.Event

GetSubscriber returns a subscriber with that id or nil

func (*Channel) SetSubscriber

func (c *Channel) SetSubscriber(id string) chan sse.Event

SetSubscriber creates a subscriber and assign that particular id to it.

func (*Channel) Subscribe

func (c *Channel) Subscribe() (string, chan sse.Event)

Subscribe returns an id and a channel that sends when Announce gets called.

func (*Channel) Unsubscribe

func (c *Channel) Unsubscribe(id string)

Unsubscribe removes the writer from the list of subscribers, thereby removing any effect Announce has.

type FsController

type FsController struct {
	// contains filtered or unexported fields
}

func NewFsController

func NewFsController(ch *Channel, f afero.Fs) (*FsController, error)

func (*FsController) MkdirAll

func (f *FsController) MkdirAll(rd io.Reader, ctrl model.Controller) error

@Title Creates a new directory @Description Creates a new directory and its subdirectories if needed @Param mkdirAllData body FsGenericData true "The directory's path" @Success 200 object FsGenericData "FsGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/mkdir [post]

func (*FsController) Move

func (f *FsController) Move(rd io.Reader, ctrl model.Controller) error

@Title Move a file or directory @Description Moves a file or directory into a new one, or renames the file @Param moveData body FsGenericData true "The source and destination in the form of MoveData" @Success 200 object FsGenericData "FsGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/move [post]

func (*FsController) ReadDir

func (f *FsController) ReadDir(rd io.Reader, ctrl model.Controller) (*ReadDirValue, error)

@Title Reads a directory @Description Reads all the files in a directory and returns them. @Param readDirData body FsGenericData true "The path of the file" @Success 200 object ReadDirValue "ReadDirValue JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/readdir [post]

func (*FsController) RemoveAll

func (f *FsController) RemoveAll(rd io.Reader, ctrl model.Controller) error

@Title Removes the file or directory and its sub-directories @Description Removes the file or directory and its sub-directories @Param removeAllData body FsGenericData true "The directory's path" @Success 200 object FsGenericData "FsGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/remove [post]

func (*FsController) Size

func (f *FsController) Size(rd io.Reader, ctrl model.Controller) (int64, error)

@Title Calculate the size of a directory @Description Reads all the files in a directory and adds them together then returns the sum. @Param sizeData body FsGenericData true "The path of the file" @Success 200 object FsGenericData "FsGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/size [post]

func (*FsController) Verify

func (f *FsController) Verify(rd io.Reader, ctrl model.Controller) (err error)

@Title Verify two files @Description Check if two files contain the same content or not. This function uses the xxhash algorithm and if there's a file with the extension "xxh64", it uses that instead of reading the file and computing the hash. @Param moveData body MoveData true "The two files in the structure of MoveData" @Success 200 object VerifyValue "MoveData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource file system routes @Route /api/v0/fs/verify [post]

type FsGenericData

type FsGenericData struct {
	Name string `json:"name" example:"/home/tim/file.txt" description:"A path to a file or a directory"`
}

FsGenericData represents the model for most fs operations

type MkdirAllData

type MkdirAllData FsGenericData

type MkdirAllValue

type MkdirAllValue FsGenericData

type MoveData

type MoveData struct {
	Src string `json:"src" example:"/home/tim/src-file.txt" description:"The source file you want to rename or move"`
	Dst string `json:"dst" example:"/home/tim/dst-file.txt" description:"The destination you want to move the src file to"`
}

type MoveValue

type MoveValue MoveData

type Operation

type Operation struct {
	*model.PublicOperation
	ID string
	// contains filtered or unexported fields
}

func (*Operation) MarshalJSON

func (o *Operation) MarshalJSON() ([]byte, error)

type OperationController

type OperationController struct {
	// contains filtered or unexported fields
}

func NewOperationController

func NewOperationController(ch *Channel, fs afero.Fs) (*OperationController, error)

func (*OperationController) AddOperation

func (oc *OperationController) AddOperation(op *model.Operation, dst, owner string) (string, error)

func (*OperationController) ConvertPathsToFilesOrFail

func (oc *OperationController) ConvertPathsToFilesOrFail(ctrl model.Controller, srcs []string) (model.Collection, error)

func (*OperationController) GetOperation

func (oc *OperationController) GetOperation(id string) (*Operation, error)

GetOperation returns operation by its id or an error

func (*OperationController) GetOperationOrFail

func (oc *OperationController) GetOperationOrFail(ctrl model.Controller, id string) (*Operation, error)

GetOperationOrFail returns an operation, or if it doesn't exist it writes nil and error. Errors are also written to ctrl.

func (*OperationController) NewOperation

func (oc *OperationController) NewOperation(rd io.Reader, ctrl model.Controller) (*OperationNewValue, error)

NewOperation creates a new operation from the reader's parameters and adds it to the controller's map of operations.

@Title Create a new operation @Description Create a new operation from scratch. Do note: New operations by default have the Default status. @Param val body OperationNewData true "The operation ID alongside the list of files to copy, the destination and the ID given by the SSE route." @Success 200 object OperationGenericData "OperationGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/new [post]

func (*OperationController) Operations

func (oc *OperationController) Operations() map[string]*Operation

func (*OperationController) Proceed

func (oc *OperationController) Proceed(rd io.Reader, ctrl model.Controller) error

DEPRECATED @Title Proceed with the operation @Description DEPRECATED This route should only be used once an operation has occurred an error. Basically, it tells the operation "we've solved whatever caused the error, continue copying the files.". This route should not be confused with a paused state as an error and a paused are completely different states. @Param val body OperationGenericData true "The operation ID" @Success 200 object OperationGenericData "OperationGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/proceed [post]

func (*OperationController) SetIndex

func (oc *OperationController) SetIndex(rd io.Reader, ctrl model.Controller) error

@Title Sets the index for the operation @Description Sets the number of the operation file that should be copied. Do note, any calls to this route will cause the current file to be skipped even amidst writing it. @Param val body OperationSetIndexData true "The operation ID and new index" @Success 200 object OperationSetIndexData "OperationSetIndexData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/set-index [post]

func (*OperationController) SetRateLimit

func (oc *OperationController) SetRateLimit(rd io.Reader, ctrl model.Controller) error

@Title Set the operation's rate limit @Description This route allows the client to limit how fast an operation can run. @Param val body OperationRateLimitData true "The operation ID alongside the rate limit" @Success 200 object OperationGenericData "OperationRateLimitdata JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/set-rate-limit [post]

func (*OperationController) SetSources

func (oc *OperationController) SetSources(rd io.Reader, ctrl model.Controller) error

@Title Set the operation's sources @Description This route allows the client to add new files to copy or remove old ones that haven't started copying. Do note: This doesn't add but instead *sets* the source array. @Param val body OperationSetSourcesData true "The operation ID alongside the list of new files" @Success 200 object OperationGenericData "OperationGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/set-sources [post]

func (*OperationController) Status

func (oc *OperationController) Status(rd io.Reader, ctrl model.Controller) error

@Title Update the Operation's status @Description This route allows the client to Start, Pause, Resume or Exit an operation. @Param val body OperationStatusData true "The operation ID alongside the new status value" @Success 200 object OperationGenericData "OperationGenericData JSON" @Failure 400 object model.ControllerError "model.ControllerError JSON" @Resource operation routes @Route /api/v0/op/proceed [post]

type OperationGenericData

type OperationGenericData struct {
	ID string `json:"id" example:"51afb" description:"The ID of the operation"`
}

type OperationGenericValue

type OperationGenericValue OperationGenericData

type OperationNewData

type OperationNewData struct {
	WriterID string   `json:"writer_id"`
	Src      []string `json:"src"`
	Dst      string   `json:"dst"`
}

type OperationNewValue

type OperationNewValue OperationGenericValue

type OperationRateLimitData

type OperationRateLimitData struct {
	ID    string  `json:"id" example:"51afb" description:"The ID of the operation"`
	Speed float64 `json:"speed" example:"2.5" description:"bytes/second"`
}

type OperationSetIndexData

type OperationSetIndexData struct {
	ID    string `json:"id" example:"51afb" description:"The ID of the operation"`
	Index int    `json:"index" example:"1" description:"The index you want to set"`
}

type OperationSetIndexValue

type OperationSetIndexValue OperationSetIndexData

type OperationSetSourcesData

type OperationSetSourcesData struct {
	ID   string   `json:"id" example:"51afb" description:"The ID of the operation"`
	Srcs []string `json:"srcs" example:"[\"/home/tim/src-file.txt\", \"/home/tim/src-dir/\"]" description:"The array of file paths"`
}

type OperationSetSourcesValue

type OperationSetSourcesValue OperationSetSourcesData

type OperationStatusData

type OperationStatusData struct {
	ID     string `json:"id" example:"51afb" description:"The ID of the operation"`
	Status uint8  `` /* 301-byte string literal not displayed */

}

type OperationStatusValue

type OperationStatusValue OperationGenericValue

type ProgressBroadcaster

type ProgressBroadcaster struct {
	// contains filtered or unexported fields
}

func (*ProgressBroadcaster) Set

func (p *ProgressBroadcaster) Set(index int, size int64)

type ReadDirData

type ReadDirData FsGenericData

type ReadDirValue

type ReadDirValue struct {
	Files []model.OsFileInfo `` /* 214-byte string literal not displayed */
}

type RemoveAllData

type RemoveAllData FsGenericData

type RemoveAllValue

type RemoveAllValue FsGenericData

type SizeData

type SizeData FsGenericData

type SizeValue

type SizeValue struct {
	Size int64 `json:"size" example:"1024" description:"Size in bytes"`
}

type VerifyValue

type VerifyValue struct {
	Same bool `` /* 184-byte string literal not displayed */
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL