Skip to content

Commit

Permalink
fix: Dereference resource data based on mediatype [DEV-4778] (#350)
Browse files Browse the repository at this point in the history
* fix: Derference resource data based on mediatype

* fix tests

* Update package-lock.json

* make swagger

* Ignore uniresolver link fails

* Update mlc_config.json

---------

Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
  • Loading branch information
DaevMithran and ankurdotb authored Feb 28, 2025
1 parent 0fc1631 commit 89bfaf9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/linters/mlc_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
},
{
"pattern": "^https://twitter.com/"
},
{
"pattern": "^https://dev.uniresolver.io"
}
],
"retryOn429": true
Expand Down
16 changes: 15 additions & 1 deletion docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@
}
}
},
"types.ResolutionResourceMetadata": {
"type": "object",
"properties": {
"linkedResourceMetadata": {
"type": "array",
"items": {
"$ref": "#/definitions/types.DereferencedResource"
}
},
"metadata": {
"$ref": "#/definitions/types.DereferencedResource"
}
}
},
"types.ResourceDereferencing": {
"type": "object",
"properties": {
Expand All @@ -939,7 +953,7 @@
"example": "https://w3id.org/did-resolution/v1"
},
"contentMetadata": {
"$ref": "#/definitions/types.DereferencedResource"
"$ref": "#/definitions/types.ResolutionResourceMetadata"
},
"contentStream": {},
"dereferencingMetadata": {
Expand Down
11 changes: 10 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,22 @@ definitions:
example: "2021-09-01T12:00:00Z"
type: string
type: object
types.ResolutionResourceMetadata:
properties:
linkedResourceMetadata:
items:
$ref: '#/definitions/types.DereferencedResource'
type: array
metadata:
$ref: '#/definitions/types.DereferencedResource'
type: object
types.ResourceDereferencing:
properties:
'@context':
example: https://w3id.org/did-resolution/v1
type: string
contentMetadata:
$ref: '#/definitions/types.DereferencedResource'
$ref: '#/definitions/types.ResolutionResourceMetadata'
contentStream: {}
dereferencingMetadata:
$ref: '#/definitions/types.DereferencingMetadata'
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/resource_dereference_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (rds ResourceService) DereferenceResourceDataWithMetadata(did string, resou
var result types.ContentStreamI
result = types.NewDereferencedResourceData(resource.Resource.Data)
metadata := types.NewDereferencedResource(did, resource.Metadata)
if dereferenceMetadata.ContentType == types.JSON || dereferenceMetadata.ContentType == types.TEXT {
if metadata.MediaType == string(types.JSON) || metadata.MediaType == string(types.TEXT) {
if res, err := types.NewResourceData(resource.Resource.Data); err == nil {
result = res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"method": "cheqd"
}
},
"contentStream": "eyAKICAgICJjb250ZW50IjogInRlc3QgZGF0YSIKfQ==",
"contentStream": {
"content": "test data"
},
"contentMetadata": {
"resourceURI": "did:cheqd:testnet:c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0/resources/9ba3922e-d5f5-4f53-b265-fc0d4e988c77",
"resourceCollectionId": "c1685ca0-1f5b-439c-8eb8-5c0e85ab7cd0",
Expand Down

0 comments on commit 89bfaf9

Please sign in to comment.