···8 "math"
9 "sort"
1011+ util "github.com/bluesky-social/indigo/lex/util"
12 cid "github.com/ipfs/go-cid"
13 cbg "github.com/whyrusleeping/cbor-gen"
14 xerrors "golang.org/x/xerrors"
···30993100 return nil
3101}
3102+func (t *RepoArtifact) MarshalCBOR(w io.Writer) error {
3103+ if t == nil {
3104+ _, err := w.Write(cbg.CborNull)
3105+ return err
3106+ }
3107+3108+ cw := cbg.NewCborWriter(w)
3109+ fieldCount := 6
3110+3111+ if t.Tag == nil {
3112+ fieldCount--
3113+ }
3114+3115+ if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil {
3116+ return err
3117+ }
3118+3119+ // t.Tag (util.LexBytes) (slice)
3120+ if t.Tag != nil {
3121+3122+ if len("tag") > 1000000 {
3123+ return xerrors.Errorf("Value in field \"tag\" was too long")
3124+ }
3125+3126+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tag"))); err != nil {
3127+ return err
3128+ }
3129+ if _, err := cw.WriteString(string("tag")); err != nil {
3130+ return err
3131+ }
3132+3133+ if len(t.Tag) > 2097152 {
3134+ return xerrors.Errorf("Byte array in field t.Tag was too long")
3135+ }
3136+3137+ if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Tag))); err != nil {
3138+ return err
3139+ }
3140+3141+ if _, err := cw.Write(t.Tag); err != nil {
3142+ return err
3143+ }
3144+3145+ }
3146+3147+ // t.Name (string) (string)
3148+ if len("name") > 1000000 {
3149+ return xerrors.Errorf("Value in field \"name\" was too long")
3150+ }
3151+3152+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil {
3153+ return err
3154+ }
3155+ if _, err := cw.WriteString(string("name")); err != nil {
3156+ return err
3157+ }
3158+3159+ if len(t.Name) > 1000000 {
3160+ return xerrors.Errorf("Value in field t.Name was too long")
3161+ }
3162+3163+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil {
3164+ return err
3165+ }
3166+ if _, err := cw.WriteString(string(t.Name)); err != nil {
3167+ return err
3168+ }
3169+3170+ // t.Repo (string) (string)
3171+ if len("repo") > 1000000 {
3172+ return xerrors.Errorf("Value in field \"repo\" was too long")
3173+ }
3174+3175+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repo"))); err != nil {
3176+ return err
3177+ }
3178+ if _, err := cw.WriteString(string("repo")); err != nil {
3179+ return err
3180+ }
3181+3182+ if len(t.Repo) > 1000000 {
3183+ return xerrors.Errorf("Value in field t.Repo was too long")
3184+ }
3185+3186+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repo))); err != nil {
3187+ return err
3188+ }
3189+ if _, err := cw.WriteString(string(t.Repo)); err != nil {
3190+ return err
3191+ }
3192+3193+ // t.LexiconTypeID (string) (string)
3194+ if len("$type") > 1000000 {
3195+ return xerrors.Errorf("Value in field \"$type\" was too long")
3196+ }
3197+3198+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil {
3199+ return err
3200+ }
3201+ if _, err := cw.WriteString(string("$type")); err != nil {
3202+ return err
3203+ }
3204+3205+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.repo.artifact"))); err != nil {
3206+ return err
3207+ }
3208+ if _, err := cw.WriteString(string("sh.tangled.repo.artifact")); err != nil {
3209+ return err
3210+ }
3211+3212+ // t.Artifact (util.LexBlob) (struct)
3213+ if len("artifact") > 1000000 {
3214+ return xerrors.Errorf("Value in field \"artifact\" was too long")
3215+ }
3216+3217+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("artifact"))); err != nil {
3218+ return err
3219+ }
3220+ if _, err := cw.WriteString(string("artifact")); err != nil {
3221+ return err
3222+ }
3223+3224+ if err := t.Artifact.MarshalCBOR(cw); err != nil {
3225+ return err
3226+ }
3227+3228+ // t.CreatedAt (string) (string)
3229+ if len("createdAt") > 1000000 {
3230+ return xerrors.Errorf("Value in field \"createdAt\" was too long")
3231+ }
3232+3233+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil {
3234+ return err
3235+ }
3236+ if _, err := cw.WriteString(string("createdAt")); err != nil {
3237+ return err
3238+ }
3239+3240+ if len(t.CreatedAt) > 1000000 {
3241+ return xerrors.Errorf("Value in field t.CreatedAt was too long")
3242+ }
3243+3244+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil {
3245+ return err
3246+ }
3247+ if _, err := cw.WriteString(string(t.CreatedAt)); err != nil {
3248+ return err
3249+ }
3250+ return nil
3251+}
3252+3253+func (t *RepoArtifact) UnmarshalCBOR(r io.Reader) (err error) {
3254+ *t = RepoArtifact{}
3255+3256+ cr := cbg.NewCborReader(r)
3257+3258+ maj, extra, err := cr.ReadHeader()
3259+ if err != nil {
3260+ return err
3261+ }
3262+ defer func() {
3263+ if err == io.EOF {
3264+ err = io.ErrUnexpectedEOF
3265+ }
3266+ }()
3267+3268+ if maj != cbg.MajMap {
3269+ return fmt.Errorf("cbor input should be of type map")
3270+ }
3271+3272+ if extra > cbg.MaxLength {
3273+ return fmt.Errorf("RepoArtifact: map struct too large (%d)", extra)
3274+ }
3275+3276+ n := extra
3277+3278+ nameBuf := make([]byte, 9)
3279+ for i := uint64(0); i < n; i++ {
3280+ nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
3281+ if err != nil {
3282+ return err
3283+ }
3284+3285+ if !ok {
3286+ // Field doesn't exist on this type, so ignore it
3287+ if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
3288+ return err
3289+ }
3290+ continue
3291+ }
3292+3293+ switch string(nameBuf[:nameLen]) {
3294+ // t.Tag (util.LexBytes) (slice)
3295+ case "tag":
3296+3297+ maj, extra, err = cr.ReadHeader()
3298+ if err != nil {
3299+ return err
3300+ }
3301+3302+ if extra > 2097152 {
3303+ return fmt.Errorf("t.Tag: byte array too large (%d)", extra)
3304+ }
3305+ if maj != cbg.MajByteString {
3306+ return fmt.Errorf("expected byte array")
3307+ }
3308+3309+ if extra > 0 {
3310+ t.Tag = make([]uint8, extra)
3311+ }
3312+3313+ if _, err := io.ReadFull(cr, t.Tag); err != nil {
3314+ return err
3315+ }
3316+3317+ // t.Name (string) (string)
3318+ case "name":
3319+3320+ {
3321+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
3322+ if err != nil {
3323+ return err
3324+ }
3325+3326+ t.Name = string(sval)
3327+ }
3328+ // t.Repo (string) (string)
3329+ case "repo":
3330+3331+ {
3332+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
3333+ if err != nil {
3334+ return err
3335+ }
3336+3337+ t.Repo = string(sval)
3338+ }
3339+ // t.LexiconTypeID (string) (string)
3340+ case "$type":
3341+3342+ {
3343+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
3344+ if err != nil {
3345+ return err
3346+ }
3347+3348+ t.LexiconTypeID = string(sval)
3349+ }
3350+ // t.Artifact (util.LexBlob) (struct)
3351+ case "artifact":
3352+3353+ {
3354+3355+ b, err := cr.ReadByte()
3356+ if err != nil {
3357+ return err
3358+ }
3359+ if b != cbg.CborNull[0] {
3360+ if err := cr.UnreadByte(); err != nil {
3361+ return err
3362+ }
3363+ t.Artifact = new(util.LexBlob)
3364+ if err := t.Artifact.UnmarshalCBOR(cr); err != nil {
3365+ return xerrors.Errorf("unmarshaling t.Artifact pointer: %w", err)
3366+ }
3367+ }
3368+3369+ }
3370+ // t.CreatedAt (string) (string)
3371+ case "createdAt":
3372+3373+ {
3374+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
3375+ if err != nil {
3376+ return err
3377+ }
3378+3379+ t.CreatedAt = string(sval)
3380+ }
3381+3382+ default:
3383+ // Field doesn't exist on this type, so ignore it
3384+ if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
3385+ return err
3386+ }
3387+ }
3388+ }
3389+3390+ return nil
3391+}
+31
api/tangled/repoartifact.go
···0000000000000000000000000000000
···1+// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
2+3+package tangled
4+5+// schema: sh.tangled.repo.artifact
6+7+import (
8+ "github.com/bluesky-social/indigo/lex/util"
9+)
10+11+const (
12+ RepoArtifactNSID = "sh.tangled.repo.artifact"
13+)
14+15+func init() {
16+ util.RegisterType("sh.tangled.repo.artifact", &RepoArtifact{})
17+} //
18+// RECORDTYPE: RepoArtifact
19+type RepoArtifact struct {
20+ LexiconTypeID string `json:"$type,const=sh.tangled.repo.artifact" cborgen:"$type,const=sh.tangled.repo.artifact"`
21+ // artifact: the artifact
22+ Artifact *util.LexBlob `json:"artifact" cborgen:"artifact"`
23+ // createdAt: time of creation of this artifact
24+ CreatedAt string `json:"createdAt" cborgen:"createdAt"`
25+ // name: name of the artifact
26+ Name string `json:"name" cborgen:"name"`
27+ // repo: repo that this artifact is being uploaded to
28+ Repo string `json:"repo" cborgen:"repo"`
29+ // tag: hash of the tag object that this artifact is attached to (only annotated tags are supported)
30+ Tag util.LexBytes `json:"tag,omitempty" cborgen:"tag,omitempty"`
31+}
···208 unique(did, email)
209 );
21000000000000000000000000211 create table if not exists migrations (
212 id integer primary key autoincrement,
213 name text unique
···208 unique(did, email)
209 );
210211+ create table if not exists artifacts (
212+ -- id
213+ id integer primary key autoincrement,
214+ did text not null,
215+ rkey text not null,
216+217+ -- meta
218+ repo_at text not null,
219+ tag binary(20) not null,
220+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
221+222+ -- data
223+ blob_cid text not null,
224+ name text not null,
225+ size integer not null default 0,
226+ mimetype string not null default "*/*",
227+228+ -- constraints
229+ unique(did, rkey), -- record must be unique
230+ unique(repo_at, tag, name), -- for a given tag object, each file must be unique
231+ foreign key (repo_at) references repos(at_uri) on delete cascade
232+ );
233+234 create table if not exists migrations (
235 id integer primary key autoincrement,
236 name text unique