-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
0884bf1
619b700
6873e1a
7d7ca2d
d56c2b6
b133380
ffffe17
ac69bfe
bdffd15
6ee07c6
7f83c44
7f1d1ee
4e3c73b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env | ||
.env.* | ||
.idea |
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 | ||
} |
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) | ||
} | ||
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add nil receiver check to update methods The update methods should check for nil receiver to prevent panics. Add nil checks: func (a *Asset) UpdatePreviewType(p *PreviewType) {
+ if a == nil {
+ return
+ }
a.previewType = util.CloneRef(p)
}
func (a *Asset) UpdateArchiveExtractionStatus(s *ArchiveExtractionStatus) {
+ if a == nil {
+ return
+ }
a.archiveExtractionStatus = util.CloneRef(s)
} Also applies to: 81-83 |
||
|
||
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, | ||
} | ||
} | ||
Comment on lines
+85
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incomplete deep copy in Clone method The Clone method doesn't properly deep copy pointer fields previewType and archiveExtractionStatus. Fix the Clone method: 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,
+ previewType: util.CloneRef(a.previewType),
uuid: a.uuid,
thread: a.thread.Clone(),
- archiveExtractionStatus: a.archiveExtractionStatus,
+ archiveExtractionStatus: util.CloneRef(a.archiveExtractionStatus),
flatFiles: a.flatFiles,
}
}
|
||
|
||
func (a *Asset) Thread() ThreadID { | ||
return a.thread | ||
} | ||
|
||
func (a *Asset) FlatFiles() bool { | ||
return a.flatFiles | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add nil checks to all getter methods
Some getter methods lack nil checks while others have them. This inconsistency could lead to panics.
Add nil checks to the following methods:
Also applies to: 51-53, 55-57