upload

package
v2.40.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = tusd.NewError("ERR_ALREADY_EXISTS", "file already exists", http.StatusConflict)
)

Functions

This section is empty.

Types

type OcisSession

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

OcisSession extends tus upload lifecycle with postprocessing steps.

func (*OcisSession) Chunk

func (s *OcisSession) Chunk() string

Chunk returns the chunk name when a legacy chunked upload was started

func (*OcisSession) Cleanup

func (session *OcisSession) Cleanup(revertNodeMetadata, cleanBin, cleanInfo bool)

cleanup cleans up after the upload is finished

func (*OcisSession) ConcatUploads

func (session *OcisSession) ConcatUploads(_ context.Context, uploads []tusd.Upload) (err error)

ConcatUploads concatenates multiple uploads

func (*OcisSession) Context

func (s *OcisSession) Context(ctx context.Context) context.Context

Context returns a context with the user, logger and lockid used when initiating the upload session

func (*OcisSession) DeclareLength

func (session *OcisSession) DeclareLength(ctx context.Context, length int64) error

DeclareLength updates the upload length information

func (*OcisSession) Dir

func (s *OcisSession) Dir() string

Dir returns the directory to which the upload is made TODO get rid of Dir(), whoever consumes the reference should be able to deal with a relative reference. Dir is only used to:

  • fill the Path property when emitting the UploadReady event after postprocessing finished. I wonder why the UploadReady contains a finished flag ... maybe multiple distinct events would make more sense.
  • build the reference that is passed to the FileUploaded event in the UploadFinishedFunc callback passed to the Upload call used for simple datatx put requests

AFAICT only search and audit services consume the path.

  • search needs to index from the root anyway. And it only needs the most recent path to put it in the index. So it should already be able to deal with an id based reference.
  • audit on the other hand needs to log events with the path at the state of the event ... so it does need the full path.

I think we can safely determine the path later, right before emitting the event. And maybe make it configurable, because only audit needs it, anyway.

func (*OcisSession) Executant

func (s *OcisSession) Executant() userpb.UserId

Executant returns the id of the user that initiated the upload session

func (*OcisSession) Expires

func (s *OcisSession) Expires() time.Time

Expires returns the time the upload session expires

func (*OcisSession) Filename

func (s *OcisSession) Filename() string

Filename returns the name of the node which is not the same as the name af the file being uploaded for legacy chunked uploads

func (*OcisSession) Finalize

func (session *OcisSession) Finalize(ctx context.Context) (err error)

Finalize finalizes the upload (eg moves the file to the internal destination)

func (*OcisSession) FinishUpload

func (session *OcisSession) FinishUpload(ctx context.Context) error

FinishUpload finishes an upload and moves the file to the internal destination implements tusd.DataStore interface returns tusd errors

func (*OcisSession) FinishUploadDecomposed

func (session *OcisSession) FinishUploadDecomposed(ctx context.Context) error

FinishUploadDecomposed finishes an upload and moves the file to the internal destination retures errtypes errors

func (*OcisSession) GetInfo

func (session *OcisSession) GetInfo(_ context.Context) (tusd.FileInfo, error)

GetInfo returns the FileInfo

func (*OcisSession) GetReader

func (session *OcisSession) GetReader(ctx context.Context) (io.ReadCloser, error)

GetReader returns an io.Reader for the upload

func (*OcisSession) HeaderIfMatch

func (s *OcisSession) HeaderIfMatch() string

HeaderIfMatch returns the if-match header for the upload session

func (*OcisSession) HeaderIfNoneMatch

func (s *OcisSession) HeaderIfNoneMatch() string

HeaderIfNoneMatch returns the if-none-match header for the upload session

func (*OcisSession) HeaderIfUnmodifiedSince

func (s *OcisSession) HeaderIfUnmodifiedSince() string

HeaderIfUnmodifiedSince returns the if-unmodified-since header for the upload session

func (*OcisSession) ID

func (s *OcisSession) ID() string

ID returns the upload session id

func (*OcisSession) InitiatorID

func (s *OcisSession) InitiatorID() string

InitiatorID returns the id of the initiating client

func (*OcisSession) IsProcessing

func (s *OcisSession) IsProcessing() bool

IsProcessing returns true if all bytes have been received. The session then has entered postprocessing state.

func (*OcisSession) MTime

func (s *OcisSession) MTime() time.Time

MTime returns the mtime to use for the uploaded file

func (*OcisSession) Node

func (s *OcisSession) Node(ctx context.Context) (*node.Node, error)

Node returns the node for the session

func (*OcisSession) NodeExists

func (s *OcisSession) NodeExists() bool

NodeExists returns wether or not the node existed during InitiateUpload. FIXME If two requests try to write the same file they both will store a new random node id in the session and try to initialize a new node when finishing the upload. The second request will fail with an already exists error when trying to create the symlink for the node in the parent directory. A node should be created as part of InitiateUpload. When listing a directory we can decide if we want to skip the entry, or expose uploed progress information. But that is a bigger change and might involve client work.

func (*OcisSession) NodeID

func (s *OcisSession) NodeID() string

NodeID returns the node id

func (*OcisSession) NodeParentID

func (s *OcisSession) NodeParentID() string

NodeParentID returns the nodes parent id

func (*OcisSession) Offset

func (s *OcisSession) Offset() int64

Offset returns the current upload offset

func (*OcisSession) Persist

func (s *OcisSession) Persist(ctx context.Context) error

Persist writes the upload session metadata to disk events can update the scan outcome and the finished event might read an empty file because of race conditions so we need to lock the file while writing and use atomic writes

func (*OcisSession) ProviderID

func (s *OcisSession) ProviderID() string

ProviderID returns the provider id

func (*OcisSession) Purge

func (s *OcisSession) Purge(ctx context.Context) error

Purge deletes the upload session metadata and written binary data

func (*OcisSession) Reference

func (s *OcisSession) Reference() provider.Reference

Reference returns a reference that can be used to access the uploaded resource

func (*OcisSession) ScanData

func (s *OcisSession) ScanData() (string, time.Time)

ScanData returns the virus scan data

func (*OcisSession) SetExecutant

func (s *OcisSession) SetExecutant(u *userpb.User)

SetExecutant is used to remember the user that initiated the upload session

func (*OcisSession) SetMetadata

func (s *OcisSession) SetMetadata(key, value string)

SetMetadata is used to fill the upload metadata that will be exposed to the end user

func (*OcisSession) SetScanData

func (s *OcisSession) SetScanData(result string, date time.Time)

SetScanData sets virus scan data to the upload session

func (*OcisSession) SetSize

func (s *OcisSession) SetSize(size int64)

SetSize will set the upload size of the underlying tus info.

func (*OcisSession) SetSizeIsDeferred

func (s *OcisSession) SetSizeIsDeferred(value bool)

SetSizeIsDeferred is uset to change the SizeIsDeferred property of the underlying tus info.

func (*OcisSession) SetStorageValue

func (s *OcisSession) SetStorageValue(key, value string)

SetStorageValue is used to set metadata only relevant for the upload session implementation

func (*OcisSession) Size

func (s *OcisSession) Size() int64

Size returns the upload size

func (*OcisSession) SizeDiff

func (s *OcisSession) SizeDiff() int64

SizeDiff returns the size diff that was calculated after postprocessing

func (*OcisSession) SpaceID

func (s *OcisSession) SpaceID() string

SpaceID returns the space id

func (*OcisSession) SpaceOwner

func (s *OcisSession) SpaceOwner() *userpb.UserId

SpaceOwner returns the id of the space owner

func (*OcisSession) Terminate

func (session *OcisSession) Terminate(_ context.Context) error

Terminate terminates the upload

func (*OcisSession) ToFileInfo

func (s *OcisSession) ToFileInfo() tusd.FileInfo

ToFileInfo returns tus compatible FileInfo so the tus handler can access the upload offset

func (*OcisSession) TouchBin

func (s *OcisSession) TouchBin() error

TouchBin creates a file to contain the binary data. It's size will be used to keep track of the tus upload offset.

func (*OcisSession) URL

func (session *OcisSession) URL(_ context.Context) (string, error)

URL returns a url to download an upload

func (*OcisSession) WriteChunk

func (session *OcisSession) WriteChunk(ctx context.Context, offset int64, src io.Reader) (int64, error)

WriteChunk writes the stream from the reader to the given offset of the upload

type OcisStore

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

OcisStore manages upload sessions

func NewSessionStore

func NewSessionStore(fs storage.FS, aspects aspects.Aspects, root string, async bool, tknopts options.TokenOptions, log *zerolog.Logger) *OcisStore

NewSessionStore returns a new OcisStore

func (OcisStore) Cleanup

func (store OcisStore) Cleanup(ctx context.Context, session Session, revertNodeMetadata, keepUpload, unmarkPostprocessing bool)

Cleanup cleans upload metadata, binary data and processing status as necessary

func (OcisStore) CreateNodeForUpload

func (store OcisStore) CreateNodeForUpload(ctx context.Context, session *OcisSession, initAttrs node.Attributes) (*node.Node, error)

CreateNodeForUpload will create the target node for the Upload TODO move this to the node package as NodeFromUpload? should we in InitiateUpload create the node first? and then the upload?

func (OcisStore) Get

func (store OcisStore) Get(ctx context.Context, id string) (*OcisSession, error)

Get returns the upload session for the given upload id

func (OcisStore) List

func (store OcisStore) List(ctx context.Context) ([]*OcisSession, error)

List lists all upload sessions

func (OcisStore) New

func (store OcisStore) New(ctx context.Context) *OcisSession

New returns a new upload session

type PermissionsChecker

type PermissionsChecker interface {
	AssemblePermissions(ctx context.Context, n *node.Node) (ap provider.ResourcePermissions, err error)
}

PermissionsChecker defines an interface for checking permissions on a Node

type Session

type Session interface {
	ID() string
	Node(ctx context.Context) (*node.Node, error)
	Context(ctx context.Context) context.Context
	Cleanup(revertNodeMetadata, cleanBin, cleanInfo bool)
}

Session is the interface used by the Cleanup call

Jump to

Keyboard shortcuts

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