createIndexFile
Create a public or encrypted file under a data model.
Usage
await dataverseConnector.runOS({
method: SYSTEM_CALL.createIndexFile,
params: {
modelId,
fileName: "file.json",
fileContent: {
modelVersion: "0.0.1",
text: "hello",
images: [
"https://bafkreib76wz6wewtkfmp5rhm3ep6tf4xjixvzzyh64nbyge5yhjno24yl4.ipfs.w3s.link",
],
videos: [],
createdAt: new Date().toISOString();,
updatedAt: new Date().toISOString();,
encrypted,
},
},
});
Parameters
modelId
:string
- the id of the data modelfileContent
-object
- the content of the file, fields under this object are decided by the data model you are using. Here is an example - If your data model looks like this:
type post @createModel(accountRelation: LIST, description: "post") {
author: DID! @documentAccount
version: CommitID! @documentVersion
appVersion: String! @string(maxLength: 100)
text: String @string(maxLength: 300000000)
images: [String] @list(maxLength: 10000000) @string(maxLength: 2000000)
videos: [String] @list(maxLength: 10000000) @string(maxLength: 2000000)
options: String @string(maxLength: 300000000)
createdAt: DateTime!
updatedAt: DateTime!
}
and was configured in dataverse.config.ts
like this:
{
isPublicDomain: false, // default is false
schemaName: 'post.graphql',
encryptable: ['text', 'images', 'videos'], // strings within the schema and within the array represent fields that may be encrypted, while fields within the schema but not within the array represent fields that will definitely not be encrypted
}
your fileContent
shall be:
appVersion
-string
- the version of the app under which the file will be createdtext
-string
- the text contentimages
-string[]
- the images urlvideos
-string[]
- the videos urlcreatedAt
-string
- the created time of the file, generated bynew Date().toISOString()
updatedAt
-string
- the updated time of the file, generated bynew Date().toISOString()
encrypted
-object
- fields to be encrypted or not in<key, value>
format, example:{ text: false, images: false, videos: false, }
💡
The structure of fileContent
needs to precisely match the structure of the
data model, otherwise the file will not be created.
Returns
{
"pkh": "did:pkh:eip155:1:0xb4D93398f6F3FB5EE4436D1aE93b32d65693a799",
"appId": "a3f0ac63-ff7d-4085-aade-c04888b71088",
"modelId": "kjzl6hvfrbw6catek36h3pep09k9gymfnla9k6ojlgrmwjogvjqg8q3zpybl1yu",
"fileContent": {
"content": {
"text": "hello",
"images": [
"https://bafkreib76wz6wewtkfmp5rhm3ep6tf4xjixvzzyh64nbyge5yhjno24yl4.ipfs.w3s.link"
],
"videos": [],
"createdAt": "2023-11-02T08:04:53.380Z",
"encrypted": "{\"text\":false,\"images\":false,\"videos\":false}",
"updatedAt": "2023-11-02T08:04:53.380Z",
"modelVersion": "0.0.1"
},
"file": {
"fsVersion": "0.11",
"contentId": "kjzl6kcym7w8y8wx1zuujmssq4wj6o6paynupzmidz7izcsiqwgpnt1uyo9lg2a",
"contentType": {
"resource": "CERAMIC",
"resourceId": "kjzl6hvfrbw6catek36h3pep09k9gymfnla9k6ojlgrmwjogvjqg8q3zpybl1yu"
},
"fileName": "create a file",
"fileType": 0,
"createdAt": "2023-11-02T08:04:56.699Z",
"updatedAt": "2023-11-02T08:04:56.699Z",
"fileId": "kjzl6kcym7w8ya3kyamskljmo181t6z3vz6px0w90c76ea3m28g994t58341ijt"
}
}
}