feat: proxy download image
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
package model
|
||||
|
||||
type Catalog struct {
|
||||
Repos []string `json:"repositories"`
|
||||
type Repo struct {
|
||||
Name string
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
type Catalog struct {
|
||||
Repositories []string `json:"repositories"`
|
||||
Repos []*PackageManifest `json:"repos"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
@ -2,15 +2,55 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/samber/lo"
|
||||
"io"
|
||||
"nf-repo/internal/model/types"
|
||||
)
|
||||
|
||||
type Manifest struct {
|
||||
type RepoSimpleManifestLayer struct {
|
||||
MediaType string `json:"mediaType"`
|
||||
Size int `json:"size"`
|
||||
Digest string `json:"digest"`
|
||||
}
|
||||
|
||||
type RepoSimpleManifestBlob struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
MediaType string `json:"mediaType"`
|
||||
Config struct {
|
||||
MediaType string `json:"mediaType"`
|
||||
Size int `json:"size"`
|
||||
Digest string `json:"digest"`
|
||||
} `json:"config"`
|
||||
Layers []RepoSimpleManifestLayer `json:"layers"`
|
||||
}
|
||||
|
||||
func (b *RepoSimpleManifestBlob) CountSize() int {
|
||||
return b.Config.Size + lo.Sum(lo.Map(b.Layers, func(item RepoSimpleManifestLayer, _ int) int {
|
||||
return item.Size
|
||||
}))
|
||||
}
|
||||
|
||||
func ManifestCountSize(m *v1.Manifest) int {
|
||||
return int(m.Config.Size) + lo.Sum(lo.Map(m.Layers, func(item v1.Descriptor, _ int) int {
|
||||
return int(item.Size)
|
||||
}))
|
||||
}
|
||||
|
||||
type RepoSimpleManifest struct {
|
||||
Blob []byte `json:"blob"`
|
||||
ContentType string `json:"content_type"`
|
||||
}
|
||||
|
||||
type Manifest struct {
|
||||
SchemaVersion int64 `json:"schemaVersion"`
|
||||
MediaType types.MediaType `json:"mediaType,omitempty"`
|
||||
Config Descriptor `json:"config"`
|
||||
Layers []Descriptor `json:"layers"`
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
Subject *Descriptor `json:"subject,omitempty"`
|
||||
}
|
||||
|
||||
type Descriptor struct {
|
||||
MediaType types.MediaType `json:"mediaType"`
|
||||
Size int64 `json:"size"`
|
||||
@ -37,3 +77,34 @@ func ParseIndexManifest(r io.Reader) (*IndexManifest, error) {
|
||||
}
|
||||
return &im, nil
|
||||
}
|
||||
|
||||
type PackageManifest struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
|
||||
|
||||
DigestId uint64 `json:"digest_id" gorm:"column:digest_id"`
|
||||
Digest string `json:"digest" gorm:"-"`
|
||||
Size int `json:"size" gorm:"-"`
|
||||
Repo string `json:"repo" gorm:"uniqueIndex:repo_tag_idx;column:repo"`
|
||||
Tag string `json:"tag" gorm:"uniqueIndex:repo_tag_idx;column:tag"`
|
||||
}
|
||||
|
||||
type PackageDigest struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
|
||||
|
||||
Digest string `json:"digest" gorm:"uniqueIndex;column:digest"`
|
||||
Size int `json:"size" gorm:"column:size;default:0"`
|
||||
ContentType string `json:"content_type" gorm:"column:content_type"`
|
||||
Content []byte `json:"content" gorm:"column:content;type:bytes"`
|
||||
}
|
||||
|
||||
func ParseManifest(r io.Reader) (*Manifest, error) {
|
||||
m := Manifest{}
|
||||
if err := json.NewDecoder(r).Decode(&m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
type Tag struct {
|
||||
Name string `json:"name"`
|
||||
Tags []string `json:"tags"`
|
||||
Name string `json:"name"`
|
||||
Tags []string `json:"tags"`
|
||||
RepoTags []*PackageManifest `json:"repo_tags"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user