From 911852d14ebd377210bb2fe0bad56468354306e6 Mon Sep 17 00:00:00 2001 From: what Date: Fri, 22 Nov 2024 16:47:29 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E5=AE=8C=E5=96=84=20PkgVersion=20GetF?= =?UTF-8?q?ile()=20GetSourceMap()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/pkg_version.go | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/base/pkg_version.go b/base/pkg_version.go index 5f439bf..5379457 100644 --- a/base/pkg_version.go +++ b/base/pkg_version.go @@ -1,6 +1,12 @@ package base +import ( + "git.fsdpf.net/go/contracts" + "github.com/samber/do" +) + type PkgVersion struct { + Id int64 `db:"id"` Name string `db:"pkg"` Bundle string `db:"bundle"` Hash string `db:"hash"` @@ -13,8 +19,41 @@ type PkgVersion struct { CreatedAt string `db:"created_at"` } -func (this PkgVersion) GetFile() []byte -func (this PkgVersion) GetSourceMap() []byte +func (this PkgVersion) GetFile(app *do.Injector) ([]byte, error) { + if this.Id == 0 { + return nil, contracts.ErrPkgUnknown + } + + res, ok := do.MustInvoke[contracts.GetResource](app)("PkgVersion") + + if !ok { + return nil, contracts.ErrResNotFound + } + + file := []byte{} + + _, err := res.GetDBTable().Where("id", this.Id).Value(&file, "file") + + return file, err +} + +func (this PkgVersion) GetSourceMap(app *do.Injector) ([]byte, error) { + if this.Id == 0 { + return nil, contracts.ErrPkgUnknown + } + + res, ok := do.MustInvoke[contracts.GetResource](app)("PkgVersion") + + if !ok { + return nil, contracts.ErrResNotFound + } + + file := []byte{} + + _, err := res.GetDBTable().Where("id", this.Id).Value(&file, "sourcemap") + + return file, err +} type GetPkgVersion func(pkg string, opts ...PkgOption) (PkgVersion, bool)