A vibe coded tangled fork which supports pijul.
at sl/tap-appview 54 lines 1.4 kB view raw
1package models 2 3import ( 4 "fmt" 5 "time" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 "github.com/go-git/go-git/v5/plumbing" 9 "github.com/ipfs/go-cid" 10 "tangled.org/core/api/tangled" 11) 12 13type Artifact struct { 14 Id uint64 15 Did string 16 Rkey string 17 18 RepoAt syntax.ATURI 19 Tag plumbing.Hash 20 CreatedAt time.Time 21 22 BlobCid cid.Cid 23 Name string 24 Size uint64 25 MimeType string 26} 27 28func (a *Artifact) AtUri() syntax.ATURI { 29 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", a.Did, tangled.RepoArtifactNSID, a.Rkey)) 30} 31 32func ArtifactFromRecord(did syntax.DID, rkey syntax.RecordKey, record tangled.RepoArtifact) (Artifact, error) { 33 // validate atproto record 34 repoAt, err := syntax.ParseATURI(record.Repo) 35 if err != nil { 36 return Artifact{}, fmt.Errorf("invalid record %T: %w", record, fmt.Errorf("repo should be valid at-uri: %w", err)) 37 } 38 created, err := time.Parse(time.RFC3339, record.CreatedAt) 39 if err != nil { 40 return Artifact{}, fmt.Errorf("invalid record %T: %w", record, fmt.Errorf("invalid time format '%s'", record.CreatedAt)) 41 } 42 43 return Artifact{ 44 Did: did.String(), 45 Rkey: rkey.String(), 46 RepoAt: repoAt, 47 Tag: plumbing.Hash(record.Tag), 48 CreatedAt: created, 49 BlobCid: cid.Cid(record.Artifact.Ref), 50 Name: record.Name, 51 Size: uint64(record.Artifact.Size), 52 MimeType: record.Artifact.MimeType, 53 }, nil 54}