diff --git a/internal/router/meshes.go b/internal/router/meshes.go index a1e9f13..e13f847 100644 --- a/internal/router/meshes.go +++ b/internal/router/meshes.go @@ -221,12 +221,16 @@ func glbWithLicense(glb []byte, lic catalog.License) ([]byte, error) { if extras == nil { extras = map[string]any{} } - l := map[string]any{"name": lic.Name} - if lic.URL != "" { - l["url"] = lic.URL + // The whole licence, as /v1/models gives it: its id, whether it allows + // commercial use and where it grants nothing are what a pipeline that + // sorts assets by licence reads, and the name alone is for people. + var l map[string]any + b, err := json.Marshal(lic) + if err != nil { + return nil, err } - if lic.Notice != "" { - l["notice"] = lic.Notice + if err := json.Unmarshal(b, &l); err != nil { + return nil, err } extras["license"] = l asset["extras"] = extras diff --git a/internal/router/meshes_test.go b/internal/router/meshes_test.go index e18dcc2..d1d2e61 100644 --- a/internal/router/meshes_test.go +++ b/internal/router/meshes_test.go @@ -401,3 +401,34 @@ func TestAModelAsleepUntilAskedIsListedAndSaidAsleep(t *testing.T) { t.Error("a model serving is not said loaded") } } + +func TestAMeshCarriesItsWholeLicence(t *testing.T) { + // The name alone was written: a pipeline that sorts assets by licence + // reads the id, whether commercial use is allowed and where it is not. + glb, err := objToGLB([]byte("v 0 0 0\nv 1 0 0\nv 1 1 0\nf 1 2 3\n")) + if err != nil { + t.Fatal(err) + } + yes := true + out, err := glbWithLicense(glb, catalog.License{ID: "stability-community", Name: "Stability AI Community License", + Commercial: &yes, RevenueCapUSD: 1000000, Attribution: "Powered by Stability AI", ExcludedRegions: []string{"XX"}}) + if err != nil { + t.Fatal(err) + } + n := binary.LittleEndian.Uint32(out[12:]) + var doc struct { + Asset struct { + Extras struct { + License map[string]any `json:"license"` + } `json:"extras"` + } `json:"asset"` + } + if err := json.Unmarshal(out[20:20+n], &doc); err != nil { + t.Fatal(err) + } + l := doc.Asset.Extras.License + if l["id"] != "stability-community" || l["commercial"] != true || l["revenue_cap_usd"] != 1000000.0 || + l["attribution"] != "Powered by Stability AI" || l["name"] == nil { + t.Errorf("licence %v", l) + } +}