Documentation ¶
Index ¶
- Constants
- func ElasticSearchRemoveWorld(ctx context.Context, world *World)
- func ElasticSearchUpdateAll(ctx context.Context, tx *gorm.DB)
- func ElasticSearchUpdateWorld(ctx context.Context, world World)
- func QueryForWorlds(q *gorm.DB) *gorm.DB
- type CloneWorld
- type CreateReport
- type CreateWorld
- type ModelInclude
- type ModelIncludes
- type Service
- func (ws *Service) CloneWorld(ctx context.Context, tx *gorm.DB, swOwner, swName string, cw CloneWorld, ...) (*World, *gz.ErrMsg)
- func (ws *Service) ComputeAllCounters(tx *gorm.DB) *gz.ErrMsg
- func (ws *Service) CreateWorld(ctx context.Context, tx *gorm.DB, cm CreateWorld, uuidStr, filesPath string, ...) (*World, *gz.ErrMsg)
- func (ws *Service) CreateWorldLike(tx *gorm.DB, owner, worldName string, user *users.User) (*WorldLike, *gz.ErrMsg)
- func (ws *Service) CreateWorldReport(tx *gorm.DB, owner, worldName, reason string) (*WorldReport, *gz.ErrMsg)
- func (ws *Service) DownloadZip(ctx context.Context, tx *gorm.DB, owner, worldName, version string, ...) (*World, *string, int, *gz.ErrMsg)
- func (ws *Service) FileTree(ctx context.Context, tx *gorm.DB, owner, worldName, version string, ...) (*fuel.FileTree, *gz.ErrMsg)
- func (ws *Service) GetFile(ctx context.Context, tx *gorm.DB, owner, name, path, version string, ...) (*[]byte, int, *gz.ErrMsg)
- func (ws *Service) GetModelReferences(ctx context.Context, p *gz.PaginationRequest, tx *gorm.DB, ...) (*ModelIncludes, *gz.PaginationResult, *gz.ErrMsg)
- func (ws *Service) GetWorld(tx *gorm.DB, owner, name string, user *users.User) (*World, *gz.ErrMsg)
- func (ws *Service) GetWorldProto(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) (*fuel.World, *gz.ErrMsg)
- func (ws *Service) RemoveWorld(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) *gz.ErrMsg
- func (ws *Service) RemoveWorldLike(tx *gorm.DB, owner, worldName string, user *users.User) (*WorldLike, *gz.ErrMsg)
- func (ws *Service) UpdateWorld(ctx context.Context, tx *gorm.DB, owner, worldName string, ...) (*World, *gz.ErrMsg)
- func (ws *Service) WorldList(p *gz.PaginationRequest, tx *gorm.DB, owner *string, order, search string, ...) (*fuel.Worlds, *gz.PaginationResult, *gz.ErrMsg)
- func (ws *Service) WorldToProto(world *World) *fuel.World
- type UpdateWorld
- type World
- type WorldDownload
- type WorldLike
- type WorldMetadata
- type WorldMetadatum
- type WorldReport
- type Worlds
Constants ¶
const ParseWorldContentsEnvVar = "IGN_FUEL_PARSE_WORLD_MODEL_INCLUDES"
ParseWorldContentsEnvVar holds the name of the boolean env var to check if parsing world file contents to look for model references is enabled or not.
Variables ¶
This section is empty.
Functions ¶
func ElasticSearchRemoveWorld ¶
ElasticSearchRemoveWorld removes a world from elastic search
func ElasticSearchUpdateAll ¶
ElasticSearchUpdateAll will update ElasticSearch with all the worlds in the SQL database.
func ElasticSearchUpdateWorld ¶
ElasticSearchUpdateWorld will update ElasticSearch with a single world.
Types ¶
type CloneWorld ¶
type CloneWorld struct { // The name of the World // required: false Name string `json:"name" validate:"omitempty,noforwardslash,min=3,nopercent" form:"name"` // Optional Owner of the world. Must be a user or an org. // If not set, the current user will be used as owner Owner string `json:"owner" form:"owner"` // Optional privacy/visibility setting. Private *bool `json:"private" validate:"omitempty" form:"private"` }
CloneWorld encapsulates data required to clone a world
type CreateReport ¶
type CreateReport struct {
Reason string `json:"reason" form:"reason"`
}
CreateReport encapsulates the data required to report a world
type CreateWorld ¶
type CreateWorld struct { // The name of the World // required: true Name string `json:"name" validate:"required,noforwardslash,min=3,nopercent" form:"name"` // Optional Owner of the world. Must be a user or an org. // If not set, the current user will be used as owner Owner string `json:"owner" form:"owner"` // License ID // required: true // minimum: 1 License int `json:"license" validate:"required,gte=1" form:"license"` // The associated permissions. 0 for public, 1 for private. // enum: 0, 1 Permission int `json:"permission" validate:"gte=0,lte=1" form:"permission"` // Optional description Description string `json:"description" form:"description"` // A comma separated list of tags Tags string `json:"tags" validate:"printascii" form:"tags"` // One or more files // required: true File string `json:"file" validate:"omitempty,gt=0" form:"-"` // Optional privacy/visibility setting. Private *bool `json:"private" validate:"omitempty" form:"private"` // Metadata associated to this world Metadata *WorldMetadata `json:"metadata" form:"metadata"` }
CreateWorld encapsulates data required to create a world
type ModelInclude ¶
type ModelInclude struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` // Owning world ID WorldID uint `json:"-"` WorldVersion *int `json:"world_version"` // The owner name of the model ModelOwner *string `json:"model_owner,omitempty"` // The name of the model ModelName *string `json:"model_name,omitempty"` // The version of the model ModelVersion *int `json:"model_version,omitempty"` // The Include type, eg. full_url, model://, etc IncludeType *string `json:"type,omitempty"` }
ModelInclude represents an external model "included" in a world Includes are usually in the form of "full urls" or prefixed with "model://"
type ModelIncludes ¶
type ModelIncludes []ModelInclude
ModelIncludes is a slice of ModelInclude swagger:model
type Service ¶
Service is the main struct exported by this Worlds Service.
func (*Service) CloneWorld ¶
func (ws *Service) CloneWorld(ctx context.Context, tx *gorm.DB, swOwner, swName string, cw CloneWorld, creator *users.User) (*World, *gz.ErrMsg)
CloneWorld clones a world. creator argument is the active user requesting the operation.
func (*Service) ComputeAllCounters ¶
ComputeAllCounters is an initialization function that iterates all worlds and updates their likes and downloads counter, based on the number of records in corresponding tables world_likes and world_downloads.
func (*Service) CreateWorld ¶
func (ws *Service) CreateWorld(ctx context.Context, tx *gorm.DB, cm CreateWorld, uuidStr, filesPath string, creator *users.User) (*World, *gz.ErrMsg)
CreateWorld creates a new world. creator argument is the active user requesting the operation.
func (*Service) CreateWorldLike ¶
func (ws *Service) CreateWorldLike(tx *gorm.DB, owner, worldName string, user *users.User) (*WorldLike, *gz.ErrMsg)
CreateWorldLike creates a WorldLike. Returns the created worldLike, or a gz.errMsg.
func (*Service) CreateWorldReport ¶
func (ws *Service) CreateWorldReport(tx *gorm.DB, owner, worldName, reason string) (*WorldReport, *gz.ErrMsg)
CreateWorldReport creates a WorldReport
func (*Service) DownloadZip ¶
func (ws *Service) DownloadZip(ctx context.Context, tx *gorm.DB, owner, worldName, version string, u *users.User, agent string, zipGetter res.GetZipResource) (*World, *string, int, *gz.ErrMsg)
DownloadZip returns the path to a zip file representing a world at the given version. This method increments the downloads counter of the world. Optional argument "user" represents the user (if any) requesting the operation. Returns the world, as well as a pointer to the zip's filepath and the resolved version.
func (*Service) FileTree ¶
func (ws *Service) FileTree(ctx context.Context, tx *gorm.DB, owner, worldName, version string, user *users.User) (*fuel.FileTree, *gz.ErrMsg)
FileTree gets the world's FileTree
func (*Service) GetFile ¶
func (ws *Service) GetFile(ctx context.Context, tx *gorm.DB, owner, name, path, version string, user *users.User) (*[]byte, int, *gz.ErrMsg)
GetFile returns the contents (bytes) of a world file. World version is considered. Returns the file's bytes and the resolved version of the world.
func (*Service) GetModelReferences ¶
func (ws *Service) GetModelReferences(ctx context.Context, p *gz.PaginationRequest, tx *gorm.DB, owner, name, version string, user *users.User) (*ModelIncludes, *gz.PaginationResult, *gz.ErrMsg)
GetModelReferences returns the list of external "model includes" of a world. Argument @version is the world version. Can be "tip" too. Argument @user is the requesting user.
func (*Service) GetWorldProto ¶
func (ws *Service) GetWorldProto(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) (*fuel.World, *gz.ErrMsg)
GetWorldProto returns a world proto struct, given a world name and owner. The user argument is the user requesting the operation.
func (*Service) RemoveWorld ¶
func (ws *Service) RemoveWorld(ctx context.Context, tx *gorm.DB, owner, name string, user *users.User) *gz.ErrMsg
RemoveWorld removes a world. The user argument is the requesting user. It is used to check if the user can perform the operation.
func (*Service) RemoveWorldLike ¶
func (ws *Service) RemoveWorldLike(tx *gorm.DB, owner, worldName string, user *users.User) (*WorldLike, *gz.ErrMsg)
RemoveWorldLike removes a worldLike. Returns the removed worldLike or a gz.errMsg.
func (*Service) UpdateWorld ¶
func (ws *Service) UpdateWorld(ctx context.Context, tx *gorm.DB, owner, worldName string, desc, tagstr, filesPath *string, private *bool, user *users.User, metadata *WorldMetadata) (*World, *gz.ErrMsg)
UpdateWorld updates a world. The user argument is the requesting user. It is used to check if the user can perform the operation. Fields that can be currently updated: desc, tags, and files. The filesPath argument points to a tmp folder from which to read the new files.
func (*Service) WorldList ¶
func (ws *Service) WorldList(p *gz.PaginationRequest, tx *gorm.DB, owner *string, order, search string, likedBy *users.User, user *users.User) (*fuel.Worlds, *gz.PaginationResult, *gz.ErrMsg)
WorldList returns a paginated list of worlds. If the likedBy argument is set, it will return the list of worlds liked by an user. TODO: find a way to MERGE this with the one from Worlds service.
type UpdateWorld ¶
type UpdateWorld struct { // Optional description Description *string `json:"description" form:"description"` // Optional list of tags (comma separated) Tags *string `json:"tags" form:"tags"` // One or more files File string `json:"file" validate:"omitempty,gt=0" form:"-"` // Optional privacy/visibility setting. Private *bool `json:"private" validate:"omitempty" form:"private"` // Metadata associated to this world Metadata *WorldMetadata `json:"metadata" form:"metadata"` }
UpdateWorld encapsulates data that can be updated in a world
func (UpdateWorld) IsEmpty ¶
func (uw UpdateWorld) IsEmpty() bool
IsEmpty returns true is the struct is empty.
type World ¶
type World struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // Added 2 milliseconds to DeletedAt field, and added it to the unique index // to help disambiguate when soft deleted rows are involved. DeletedAt *time.Time `gorm:"type:timestamp(2) NULL; unique_index:idx_world_owner" sql:"index"` // The name of the world Name *string `gorm:"unique_index:idx_world_owner" json:"name,omitempty"` // Unique identifier for the world UUID *string `json:"-"` // A description of the world (max 65,535 chars) // Interesting post about TEXT vs VARCHAR(30000) performance: // https://nicj.net/mysql-text-vs-varchar-performance/ Description *string `gorm:"type:text" json:"description,omitempty"` // Number of likes Likes int `json:"likes,omitempty"` // Bytes of the world, when downloaded as a zip Filesize int `json:"filesize,omitempty"` // Number of downloads Downloads int `json:"downloads,omitempty"` // Date and time the world was first uploaded UploadDate *time.Time `json:"upload_date,omitempty"` // Modification Date and time ModifyDate *time.Time `json:"modify_date,omitempty"` // Tags associated to this world Tags models.Tags `gorm:"many2many:world_tags;" json:"tags,omitempty"` // Metadata associated to this world Metadata WorldMetadata `json:"metadata,omitempty"` // Location of the world on disk Location *string `json:"-"` // The user who created this world Owner *string `gorm:"unique_index:idx_world_owner" json:"owner,omitempty"` // The username of the User that created this world (usually got from the JWT) Creator *string `json:"creator,omitempty"` // Permission - 0: public, 1: owner, (future: team, others) Permission int `json:"permission,omitempty"` // The license associated to this world License license.License `json:"license,omitempty"` LicenseID int `json:"lic_id,omitempty"` // Private - True to make this a private resource Private *bool `json:"private,omitempty"` }
World represents information about a simulation world.
swagger:model dbWorld
func GetWorldByName ¶
GetModelByName queries a World by name and owner.
func NewWorld ¶
func NewWorld(uuidStr, name, desc, location, owner, creator *string, lic license.License, permission int, tags models.Tags, private bool, metadata *WorldMetadata) (World, error)
NewWorld creates a new World struct
func NewWorldAndUUID ¶
func NewWorldAndUUID(name, desc, location, owner, creator *string, lic license.License, permission int, tags models.Tags, private bool, metadata *WorldMetadata) (World, error)
NewWorldAndUUID creates a World struct with a new UUID.
func (*World) GetLocation ¶
GetLocation returns the world's location on disk
func (*World) SetLocation ¶
SetLocation sets the location path
type WorldDownload ¶
type WorldDownload struct { gorm.Model // The ID of the user that made the download UserID *uint // The ID of the world that was downloaded WorldID *uint // User-Agent sent in the http request (optional) UserAgent string }
WorldDownload represents a single download of a world.
type WorldLike ¶
type WorldLike struct { // Override default GORM Model fields ID uint `gorm:"primary_key"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // The ID of the user that made the like UserID *uint `gorm:"unique_index:idx_user_world_like"` // The ID of the world that was liked WorldID *uint `gorm:"unique_index:idx_user_world_like"` }
WorldLike represents a like of a world.
type WorldMetadata ¶
type WorldMetadata []WorldMetadatum
WorldMetadata is an array of WorldMetadatum
swagger:model
type WorldMetadatum ¶
type WorldMetadatum struct { // Override default GORM Model fields ID uint `gorm:"primary_key" json:"-"` CreatedAt time.Time `gorm:"type:timestamp(3) NULL"` UpdatedAt time.Time // WorldID is the ID of the resource to which this metadata is attached. WorldID uint // Pull in the common resources Metadatum. commonres.Metadatum }
WorldMetadatum is here so that world and model metadata are stored in separate tables.
swagger:model
type WorldReport ¶
type WorldReport struct { generics.Report // WorldID represents the world that was reported WorldID *uint `json:"world,omitempty"` }
WorldReport contains information about a world's user report.