models

package
v0.0.0-...-7139136 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries = 10
)

Consts ...

View Source
const (
	OriginalFilename = "prim"
)

Consts ...

Variables

View Source
var ErrInvalidMetaMainItem = errors.New(`invalid meta main item`)

ErrInvalidMetaMainItem error

Functions

func IsOriginal

func IsOriginal(name string) bool

IsOriginal file name

func SourceFilename

func SourceFilename(name, ext string) string

SourceFilename prepare ” -> @ = oroginal filename

Types

type Action

type Action struct {
	Name        string         `json:"name,omitempty"`
	MustExecute bool           `json:"mustexecute,omitempty"`
	Values      map[string]any `json:"values,omitempty"`
}

Action which must be applied to source

func NewAction

func NewAction(name string, values ...any) *Action

NewAction with parameters

func (*Action) Copy

func (a *Action) Copy() *Action

Copy current action object

func (*Action) Equal

func (a *Action) Equal(act *Action) bool

Equal action to

func (*Action) Value

func (a *Action) Value(name string, def any) any

Value parameter as any type

func (*Action) ValueBool

func (a *Action) ValueBool(name string, def bool) bool

ValueBool parameter as bool type

func (*Action) ValueFloat64

func (a *Action) ValueFloat64(name string, def float64) float64

ValueFloat64 parameter as float type

func (*Action) ValueInt32

func (a *Action) ValueInt32(name string, def int32) int32

ValueInt32 parameter as int type

func (*Action) ValueInt64

func (a *Action) ValueInt64(name string, def int64) int64

ValueInt64 parameter as int type

func (*Action) ValueString

func (a *Action) ValueString(name string, def string) string

ValueString parameter as string type

func (*Action) ValueStringSlice

func (a *Action) ValueStringSlice(name string) []string

ValueStringSlice parameter as string slice type

type Event

type Event struct {
	Type   EventType `json:"type"`
	Error  string    `json:"error,omitempty"`
	Object *Object   `json:"object,omitempty"`
}

Event produced by storage

func (*Event) ErrorObj

func (e *Event) ErrorObj() error

ErrorObj value

func (*Event) IsError

func (e *Event) IsError() bool

IsError object

type EventType

type EventType string

EventType value

const (
	RefreshEventType   EventType = "refresh"
	UpdateEventType    EventType = "update"
	ProcessedEventType EventType = "processed"
	DeleteEventType    EventType = "delete"
)

Event type list...

func (EventType) String

func (t EventType) String() string

type ItemMeta

type ItemMeta struct {
	TaskID []string `json:"task_id,omitempty"`

	Name    string `json:"name"`
	NameExt string `json:"name_ext,omitempty"`

	Type        ObjectType     `json:"type,omitempty"`
	ContentType string         `json:"content_type,omitempty"`
	HashID      string         `json:"hashid,omitempty"`
	Width       int            `json:"width,omitempty"`
	Height      int            `json:"height,omitempty"`
	Size        int64          `json:"size,omitempty"`
	Duration    int            `json:"duration,omitempty"`
	Bitrate     string         `json:"bitrate,omitempty"`
	Codec       string         `json:"codec,omitempty"`
	Ext         map[string]any `json:"ext,omitempty"`

	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

ItemMeta information about one object element

func (*ItemMeta) ExtJSON

func (m *ItemMeta) ExtJSON() string

ExtJSON variable

func (*ItemMeta) FromExtJSON

func (m *ItemMeta) FromExtJSON(data []byte) error

FromExtJSON data

func (*ItemMeta) Fullname

func (m *ItemMeta) Fullname() string

Fullname of the file

func (*ItemMeta) GetExt

func (m *ItemMeta) GetExt(name string) any

GetExt value from context

func (*ItemMeta) IsEmpty

func (m *ItemMeta) IsEmpty() bool

IsEmpty manifest object

func (*ItemMeta) IsTaskProcessed

func (m *ItemMeta) IsTaskProcessed(id string) bool

IsTaskProcessed checks if the task was applied to the Item

func (*ItemMeta) MarkAsComplete

func (m *ItemMeta) MarkAsComplete(id string)

MarkAsComplete task

func (*ItemMeta) MarkAsIncomplete

func (m *ItemMeta) MarkAsIncomplete(id string)

MarkAsIncomplete task

func (*ItemMeta) ObjectTypeExt

func (m *ItemMeta) ObjectTypeExt() string

ObjectTypeExt returns file extension

func (*ItemMeta) SetExt

func (m *ItemMeta) SetExt(name string, value any)

SetExt context value

func (*ItemMeta) UpdateName

func (m *ItemMeta) UpdateName(name string)

UpdateName information

type Manifest

type Manifest struct {
	Version      string               `json:"version,omitempty"`
	ContentTypes []string             `json:"content_types,omitempty"`
	Stages       []*ManifestTaskStage `json:"stages,omitempty"`
}

Manifest model object

func (*Manifest) GetStages

func (m *Manifest) GetStages() []*ManifestTaskStage

GetStages returns the list of stagest safely

func (*Manifest) GetVersion

func (m *Manifest) GetVersion() string

GetVersion returns the version of manifest safely

func (*Manifest) HasTask

func (m *Manifest) HasTask(id string) bool

HasTask for target object in the manifest

func (*Manifest) HasTaskByTarget

func (m *Manifest) HasTaskByTarget(name string) bool

HasTaskByTarget name returns status

func (*Manifest) IsEmpty

func (m *Manifest) IsEmpty() bool

IsEmpty manifest object

func (*Manifest) IsValidContentType

func (m *Manifest) IsValidContentType(contentType string) bool

IsValidContentType checks the content type

func (*Manifest) PrepareInfo

func (m *Manifest) PrepareInfo() *Manifest

PrepareInfo of the manifest

func (*Manifest) TargetCount

func (m *Manifest) TargetCount() int

TargetCount returns total count of targets

func (*Manifest) TaskByID

func (m *Manifest) TaskByID(id string) *ManifestTask

TaskByID returns the task with such ID

func (*Manifest) TaskByTarget

func (m *Manifest) TaskByTarget(name string) *ManifestTask

TaskByTarget name of result

func (*Manifest) TaskCount

func (m *Manifest) TaskCount() int

TaskCount returns total count of tasks

func (*Manifest) UnmarshalJSON

func (m *Manifest) UnmarshalJSON(data []byte) error

UnmarshalJSON is custom method of json.Unmarshaler implementation

type ManifestTask

type ManifestTask struct {
	ID       string     `json:"id,omitempty"`       // Unique ID
	Source   string     `json:"source,omitempty"`   // ” -> @ = original file
	Target   string     `json:"target,omitempty"`   // Name of file
	Type     ObjectType `json:"type,omitempty"`     // Target type
	Actions  []*Action  `json:"actions,omitempty"`  // Applied to source before save to target
	When     []string   `json:"when,omitempty"`     // Only if tasks are processed
	Required bool       `json:"required,omitempty"` // If not required then task can`t be skipped and processin will ends with error
}

ManifestTask file processing

func (*ManifestTask) IsLastAction

func (task *ManifestTask) IsLastAction(action *Action, tester actionTester) bool

IsLastAction of some connverter

type ManifestTaskStage

type ManifestTaskStage struct {
	Name  string          `json:"name,omitempty"`
	Tasks []*ManifestTask `json:"tasks,omitempty"`
}

ManifestTaskStage file processing

func (*ManifestTaskStage) HasTask

func (stage *ManifestTaskStage) HasTask(id string) bool

HasTask for target object in the manifest

func (*ManifestTaskStage) IsEmpty

func (stage *ManifestTaskStage) IsEmpty() bool

IsEmpty manifest object

func (*ManifestTaskStage) PrepareInfo

func (stage *ManifestTaskStage) PrepareInfo()

PrepareInfo of the manifest stage

func (*ManifestTaskStage) TaskByID

func (stage *ManifestTaskStage) TaskByID(id string) *ManifestTask

TaskByID returns the task with ID

func (*ManifestTaskStage) TaskByTarget

func (stage *ManifestTaskStage) TaskByTarget(name string) *ManifestTask

TaskByTarget name of result

type Meta

type Meta struct {
	Main            ItemMeta            `json:"main"`
	Tasks           []*MetaTaskInfo     `json:"tasks,omitempty"` // List of complete actions
	Items           []*ItemMeta         `json:"items,omitempty"`
	Tags            []string            `json:"tags,omitempty"`
	Params          map[string][]string `json:"params,omitempty"`
	ManifestVersion string              `json:"manifest_version,omitempty"`
	CreatedAt       time.Time           `json:"created_at,omitempty"`
	UpdatedAt       time.Time           `json:"updated_at,omitempty"`
}

Meta information of the file object

func (*Meta) CleanSubItems

func (m *Meta) CleanSubItems()

CleanSubItems information from the object

func (*Meta) Complete

func (m *Meta) Complete(itemMeta *ItemMeta, task *ManifestTask, err error)

Complete marks action as complete

func (*Meta) ErrorTaskCount

func (m *Meta) ErrorTaskCount() (errorCount int)

ErrorTaskCount returns count of tasks which returns the error

func (*Meta) ExcessItems

func (m *Meta) ExcessItems(manifest *Manifest) []*ItemMeta

ExcessItems returns the list of items which is not present in the Manifest

func (*Meta) IsComplete

func (m *Meta) IsComplete(manifest *Manifest, stages ...string) bool

IsComplete manifest processed

func (*Meta) IsCompleteTask

func (m *Meta) IsCompleteTask(task *ManifestTask) bool

IsCompleteTask returns complition status of the task

func (*Meta) IsConsistent

func (m *Meta) IsConsistent(manifest *Manifest) bool

IsConsistent meta-information and manifest state

func (*Meta) IsEmpty

func (m *Meta) IsEmpty() bool

IsEmpty manifest object

func (*Meta) IsProcessingComplete

func (m *Meta) IsProcessingComplete(manifest *Manifest, stages ...string) bool

IsProcessingComplete with any status

func (*Meta) IsProcessingCompleteTask

func (m *Meta) IsProcessingCompleteTask(task *ManifestTask, maxRetries ...int) bool

IsProcessingCompleteTask returns finished complition status of the task

func (*Meta) ItemByName

func (m *Meta) ItemByName(name string) *ItemMeta

ItemByName returns subfile information

func (*Meta) RemoveExcessTasks

func (m *Meta) RemoveExcessTasks(manifest *Manifest)

RemoveExcessTasks from the meta object

func (*Meta) RemoveItemByName

func (m *Meta) RemoveItemByName(name string) (bool, error)

RemoveItemByName meta information about item

func (*Meta) RemoveTaskByID

func (m *Meta) RemoveTaskByID(id string) bool

RemoveTaskByID meta information about task

func (*Meta) ResetCompletion

func (m *Meta) ResetCompletion()

ResetCompletion state

func (*Meta) SetItem

func (m *Meta) SetItem(item *ItemMeta)

SetItem meta information

type MetaTaskInfo

type MetaTaskInfo struct {
	ID             string       `json:"id"`
	Attempts       int          `json:"attempts,omitempty"`
	Status         ObjectStatus `json:"status,omitempty"`
	StatusMessage  string       `json:"status_message,omitempty"`
	TargetItemName string       `json:"target_item_name,omitempty"`
	UpdatedAt      time.Time    `json:"updated_at,omitempty"`
}

MetaTaskInfo contains information of one action item

type Object

type Object struct {
	ID     string `json:"id" gorm:"primary_key"` // Unical ID in storage
	Bucket string `json:"bucket"`
	Path   string `json:"path"`
	HashID string `json:"hashid" gorm:"index:hashid;column:hashid"`

	Status        ObjectStatus `json:"status"`
	StatusMessage string       `json:"status_message,omitempty"`

	ContentType string                          `json:"content_type"`
	Type        ObjectType                      `json:"type"`
	Tags        gosql.NullableJSONArray[string] `json:"tags,omitempty"`
	Meta        gosql.NullableJSON[Meta]        `json:"meta,omitempty"`
	Manifest    gosql.NullableJSON[Manifest]    `json:"manifest,omitempty"`
	Size        uint64                          `json:"size"` // Size in bytes

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Object structure which describes the paticular file attached to advertisement Image advertisement: Title=Image title, Description=My description

      ID,  Bucket,         path,             HashID,  size,  type, content_type,                          meta
File:  1, 'image', 'images/a/c', dhg321h3ndp43u2hfc, 64322, image,   image/jpeg, {"width": 300, "height": 250}
File:  2, 'image', 'images/a/c', xxg321h3xxx43u2hfc, 44322, video,  video/x-mp4, {"width": 300, "height": 250, "duration": 11132ms}

func (*Object) IncompleteTasks

func (o *Object) IncompleteTasks() (resp []*ManifestTask)

IncompleteTasks returns the list of incompleted tasks

func (*Object) ObjectID

func (o *Object) ObjectID() string

ObjectID returns the Identificator of the object

func (*Object) PathByName

func (o *Object) PathByName(name string) string

PathByName returns the full path to the item

func (*Object) TableName

func (o *Object) TableName() string

TableName of the object in the database

type ObjectStatus

type ObjectStatus string

ObjectStatus of the object operation

const (
	StatusUndefined  ObjectStatus = "undefined"
	StatusProcessing ObjectStatus = "processing"
	StatusOK         ObjectStatus = "ok" // If processing finished
	StatusError      ObjectStatus = "error"
	StatusNotFound   ObjectStatus = "not-found"
)

Status list

func StatusFromString

func StatusFromString(st string) ObjectStatus

StatusFromString converts string to status type

func (ObjectStatus) Improtant

func (s ObjectStatus) Improtant(status2 ObjectStatus) ObjectStatus

Improtant returns more significant status one of two

func (ObjectStatus) IsEmpty

func (s ObjectStatus) IsEmpty() bool

IsEmpty checks the status

func (ObjectStatus) IsError

func (s ObjectStatus) IsError() bool

IsError status complition

func (ObjectStatus) IsProcessed

func (s ObjectStatus) IsProcessed() bool

IsProcessed status complition

func (ObjectStatus) IsProcessing

func (s ObjectStatus) IsProcessing() bool

IsProcessing status complition

func (ObjectStatus) String

func (s ObjectStatus) String() string

type ObjectType

type ObjectType string

ObjectType of object

const (
	TypeUndefined    ObjectType = "undefined"
	TypeVideo        ObjectType = "video"
	TypeImage        ObjectType = "image"
	TypeAudio        ObjectType = "audio"
	TypeHTMLArchType ObjectType = "htmlarch"
	TypeOther        ObjectType = "other"
)

Object types...

func ObjectTypeByContentType

func ObjectTypeByContentType(contentType string) ObjectType

ObjectTypeByContentType value

func ObjectTypesByContentType

func ObjectTypesByContentType(contentTypes ...string) (list []ObjectType)

ObjectTypesByContentType value list

func (ObjectType) IsImage

func (t ObjectType) IsImage() bool

IsImage file type

func (ObjectType) IsUndefined

func (t ObjectType) IsUndefined() bool

IsUndefined type object

func (ObjectType) IsVideo

func (t ObjectType) IsVideo() bool

IsVideo file type

func (ObjectType) String

func (t ObjectType) String() string

Jump to

Keyboard shortcuts

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