worlds

package
v0.0.0-...-4436486 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
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 QueryForWorlds

func QueryForWorlds(q *gorm.DB) *gorm.DB

QueryForWorlds returns a gorm query configured to query Worlds with preloaded License and Tags.

Types

type CloneWorld

type CloneWorld struct {
	// The name of the World
	// required: false
	Name string `json:"name" validate:"omitempty,noforwardslash,min=3" 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" 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"`
}

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

type Service struct{}

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, *ign.ErrMsg)

CloneWorld clones a world. creator argument is the active user requesting the operation.

func (*Service) ComputeAllCounters

func (ws *Service) ComputeAllCounters(tx *gorm.DB) *ign.ErrMsg

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, *ign.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, int, *ign.ErrMsg)

CreateWorldLike creates a WorldLike. Returns the created worldLike, the current count of likes, or an ign.errMsg.

func (*Service) CreateWorldReport

func (ws *Service) CreateWorldReport(tx *gorm.DB, owner, worldName, reason string) (*WorldReport, *ign.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) (*World, *string, int, *ign.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, *ign.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, *ign.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 *ign.PaginationRequest,
	tx *gorm.DB, owner, name, version string,
	user *users.User) (*ModelIncludes, *ign.PaginationResult, *ign.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) GetWorld

func (ws *Service) GetWorld(tx *gorm.DB, owner, name string,
	user *users.User) (*World, *ign.ErrMsg)

GetWorld returns a world by its name and owner's name.

func (*Service) GetWorldProto

func (ws *Service) GetWorldProto(ctx context.Context, tx *gorm.DB, owner,
	name string, user *users.User) (*fuel.World, *ign.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(tx *gorm.DB, owner, name string, user *users.User) *ign.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, int, *ign.ErrMsg)

RemoveWorldLike removes a worldLike. Returns the removed worldLike, the current count of likes, or an ign.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) (*World, *ign.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 *ign.PaginationRequest, tx *gorm.DB, owner *string,
	order, search string, likedBy *users.User, user *users.User) (*fuel.Worlds, *ign.PaginationResult, *ign.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.

func (*Service) WorldToProto

func (ws *Service) WorldToProto(world *World) *fuel.World

WorldToProto creates a new 'fuel.World' from the given world. NOTE: returned "thumbnail urls" are pointing to the "tip" version.

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"`
}

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"`

	// 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

func GetWorldByName(tx *gorm.DB, name string, owner string) (*World, error)

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) (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) (World, error)

NewWorldAndUUID creates a World struct with a new UUID.

func (*World) GetID

func (w *World) GetID() uint

GetID returns the ID

func (*World) GetLocation

func (w *World) GetLocation() *string

GetLocation returns the world's location on disk

func (*World) GetName

func (w *World) GetName() *string

GetName returns the world's name

func (*World) GetOwner

func (w *World) GetOwner() *string

GetOwner returns the world's owner

func (*World) GetUUID

func (w *World) GetUUID() *string

GetUUID returns the world's UUID

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 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.

type Worlds

type Worlds []World

Worlds is an array of World

Jump to

Keyboard shortcuts

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