getArtifactByKref method
- String krefUri
Gets an artifact by kref, returned as an Artifact model.
If the kref includes &a=<name>, that artifact is returned. Otherwise the
revision's default artifact is resolved, mirroring Python's
get_artifact_by_kref. Throws a KumihoError if no artifact name is
present and the revision has no default artifact.
final mesh = await client.getArtifactByKref(
'kref://film-2024/models/hero.model?r=1&a=mesh');
final dflt = await client.getArtifactByKref(
'kref://film-2024/models/hero.model?r=1'); // default artifact
Implementation
Future<models.Artifact> getArtifactByKref(String krefUri) async {
final kref = Kref(krefUri);
final artifactName = kref.artifactName;
if (artifactName != null) {
final revisionKref = kref.revisionKref;
if (revisionKref == null) {
throw KumihoError('Artifact kref must include revision: $krefUri');
}
final response = await getArtifact(revisionKref.uri, artifactName);
return models.Artifact(response, this);
}
// No &a= -> resolve the revision's default artifact.
final rev = await getRevision(krefUri);
final defaultName = rev.defaultArtifact;
if (defaultName.isEmpty) {
throw KumihoError(
'Invalid artifact kref: $krefUri '
'(missing &a=<name> and no default artifact set)',
);
}
final response = await getArtifact(rev.kref.uri, defaultName);
return models.Artifact(response, this);
}