Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add asset package #48

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions asset/asset.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
type Asset implements Node {
id: ID!
project: Project!
projectId: ID!
createdAt: DateTime!
createdBy: Operator!
createdByType: OperatorType!
createdById: ID!
items: [AssetItem!]
size: FileSize!
previewType: PreviewType
uuid: String!
thread: Thread
threadId: ID!
url: String!
fileName: String!
archiveExtractionStatus: ArchiveExtractionStatus
}
type AssetItem {
itemId: ID!
modelId: ID!
}

type AssetFile {
name: String!
size: FileSize!
contentType: String
path: String!
filePaths: [String!]
}

enum PreviewType {
IMAGE
IMAGE_SVG
GEO
GEO_3D_TILES
GEO_MVT
MODEL_3D
CSV
UNKNOWN
}

enum ArchiveExtractionStatus {
SKIPPED
PENDING
IN_PROGRESS
DONE
FAILED
}

input CreateAssetInput {
projectId: ID!
file: Upload
url: String
token: String
skipDecompression: Boolean
}

# If `cursor` is specified, both `filename` and `contentLength` will be ignored.
input CreateAssetUploadInput {
projectId: ID!

# The name of the file to upload.
filename: String
# The size of the file to upload.
contentLength: Int

# Required if uploading in multiple parts.
cursor: String
}

input UpdateAssetInput {
id: ID!
previewType: PreviewType
}

input DeleteAssetInput {
assetId: ID!
}

input DecompressAssetInput {
assetId: ID!
}

type CreateAssetPayload {
asset: Asset!
}

type UpdateAssetPayload {
asset: Asset!
}

type DeleteAssetPayload {
assetId: ID!
}

type DecompressAssetPayload {
asset: Asset!
}

type CreateAssetUploadPayload {
# A token identifying the sequence of uploads.
# If an empty string is returned, it means that issuing URLs is not supported, and the `file` in CreateAsset must be used.
# If splitting the upload is necessary, it is guaranteed that the same value will be returned.
token: String!
# The URL to which the PUT request should be made.
# An empty string return means that the upload process has been completed.
url: String!
# The MIME type for the PUT request.
# If unspecified or an empty string, the Content-Type should not be sent.
contentType: String
# The size of the upload.
contentLength: Int!
# A cursor to obtain the URL for the next PUT request.
next: String
}

type AssetConnection {
edges: [AssetEdge!]!
nodes: [Asset]!
pageInfo: PageInfo!
totalCount: Int!
}

type AssetEdge {
cursor: Cursor!
node: Asset
}

enum AssetSortType {
DATE
SIZE
NAME
}

input AssetSort {
sortBy: AssetSortType!
direction: SortDirection
}

extend type Query {
assetFile(assetId: ID!): AssetFile!
assets(projectId: ID!, keyword: String, sort: AssetSort, pagination: Pagination): AssetConnection!
}

extend type Mutation {
createAsset(input: CreateAssetInput!): CreateAssetPayload
updateAsset(input: UpdateAssetInput!): UpdateAssetPayload
deleteAsset(input: DeleteAssetInput!): DeleteAssetPayload
decompressAsset(input: DecompressAssetInput!): DecompressAssetPayload
createAssetUpload(input: CreateAssetUploadInput!): CreateAssetUploadPayload
}
112 changes: 112 additions & 0 deletions asset/assetdomain/asset/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package asset

import (
"time"

"github.com/reearth/reearthx/account/accountdomain"
"github.com/reearth/reearthx/util"
)

type Asset struct {
id ID
project ProjectID
createdAt time.Time
user *accountdomain.UserID
integration *IntegrationID
fileName string
size uint64
previewType *PreviewType
uuid string
thread ThreadID
archiveExtractionStatus *ArchiveExtractionStatus
flatFiles bool
}

type URLResolver = func(*Asset) string

func (a *Asset) ID() ID {
return a.id
}

func (a *Asset) Project() ProjectID {
return a.project
}

func (a *Asset) CreatedAt() time.Time {
if a == nil {
return time.Time{}
}

return a.createdAt
}

func (a *Asset) User() *accountdomain.UserID {
return a.user
}

func (a *Asset) Integration() *IntegrationID {
return a.integration
}

func (a *Asset) FileName() string {
return a.fileName
}

func (a *Asset) Size() uint64 {
return a.size
}

func (a *Asset) PreviewType() *PreviewType {
if a.previewType == nil {
return nil
}
return a.previewType
}

func (a *Asset) UUID() string {
return a.uuid
}

func (a *Asset) ArchiveExtractionStatus() *ArchiveExtractionStatus {
if a.archiveExtractionStatus == nil {
return nil
}
return a.archiveExtractionStatus
}

func (a *Asset) UpdatePreviewType(p *PreviewType) {
a.previewType = util.CloneRef(p)
}

func (a *Asset) UpdateArchiveExtractionStatus(s *ArchiveExtractionStatus) {
a.archiveExtractionStatus = util.CloneRef(s)
}

func (a *Asset) Clone() *Asset {
if a == nil {
return nil
}

return &Asset{
id: a.id.Clone(),
project: a.project.Clone(),
createdAt: a.createdAt,
user: a.user.CloneRef(),
integration: a.integration.CloneRef(),
fileName: a.fileName,
size: a.size,
previewType: a.previewType,
uuid: a.uuid,
thread: a.thread.Clone(),
archiveExtractionStatus: a.archiveExtractionStatus,
flatFiles: a.flatFiles,
}
}

func (a *Asset) Thread() ThreadID {
return a.thread
}

func (a *Asset) FlatFiles() bool {
return a.flatFiles
}
Loading
Loading