From 01bca2f1842b9fc3ea4e3481cf1a721d85559c85 Mon Sep 17 00:00:00 2001 From: nibazshab <44338441+nibazshab@users.noreply.github.com> Date: Mon, 26 May 2025 09:04:03 +0000 Subject: [PATCH] support Github Release Source code (zip/tar.gz) --- drivers/github_releases/driver.go | 6 ++++++ drivers/github_releases/meta.go | 1 + drivers/github_releases/types.go | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/drivers/github_releases/driver.go b/drivers/github_releases/driver.go index b35aa57a..6fd6c9e5 100644 --- a/drivers/github_releases/driver.go +++ b/drivers/github_releases/driver.go @@ -51,6 +51,9 @@ func (d *GithubReleases) List(ctx context.Context, dir model.Obj, args model.Lis if d.Addition.ShowReadme { files = append(files, point.GetOtherFile(d.GetRequest, args.Refresh)...) } + if d.Addition.ShowSourceCode{ + files = append(files, point.GetSourceCode()...) + } } else if strings.HasPrefix(point.Point, path) { // 仓库目录的父目录 nextDir := GetNextDir(point.Point, path) if nextDir == "" { @@ -85,6 +88,9 @@ func (d *GithubReleases) List(ctx context.Context, dir model.Obj, args model.Lis if d.Addition.ShowReadme { files = append(files, point.GetOtherFile(d.GetRequest, args.Refresh)...) } + if d.Addition.ShowSourceCode{ + files = append(files, point.GetSourceCode()...) + } } else if strings.HasPrefix(point.Point, path) { // 仓库目录的父目录 nextDir := GetNextDir(point.Point, path) if nextDir == "" { diff --git a/drivers/github_releases/meta.go b/drivers/github_releases/meta.go index 47b84d37..0c0bb740 100644 --- a/drivers/github_releases/meta.go +++ b/drivers/github_releases/meta.go @@ -10,6 +10,7 @@ type Addition struct { RepoStructure string `json:"repo_structure" type:"text" required:"true" default:"alistGo/alist" help:"structure:[path:]org/repo"` ShowReadme bool `json:"show_readme" type:"bool" default:"true" help:"show README、LICENSE file"` Token string `json:"token" type:"string" required:"false" help:"GitHub token, if you want to access private repositories or increase the rate limit"` + ShowSourceCode bool `json:"show_source_code" type:"bool" default:"false" help:"show Source code (zip/tar.gz)"` ShowAllVersion bool `json:"show_all_version" type:"bool" default:"false" help:"show all versions"` GitHubProxy string `json:"gh_proxy" type:"string" default:"" help:"GitHub proxy, e.g. https://ghproxy.net/github.com or https://gh-proxy.com/github.com "` } diff --git a/drivers/github_releases/types.go b/drivers/github_releases/types.go index b0a9ee61..00f86fc5 100644 --- a/drivers/github_releases/types.go +++ b/drivers/github_releases/types.go @@ -143,6 +143,32 @@ func (m *MountPoint) GetAllVersionSize() int64 { return size } +func (m *MountPoint) GetSourceCode() []File { + files := make([]File, 0) + + // 无法获取文件大小,此处设为 1 + files = append(files, File{ + Path: m.Point + "/" + "Source code (zip)", + FileName: "Source code (zip)", + Size: 1, + Type: "file", + UpdateAt: m.Release.CreatedAt, + CreateAt: m.Release.CreatedAt, + Url: m.Release.TarballUrl, + }) + files = append(files, File{ + Path: m.Point + "/" + "Source code (tar.gz)", + FileName: "Source code (tar.gz)", + Size: 1, + Type: "file", + UpdateAt: m.Release.CreatedAt, + CreateAt: m.Release.CreatedAt, + Url: m.Release.ZipballUrl, + }) + + return files +} + func (m *MountPoint) GetOtherFile(get func(url string) (*resty.Response, error), refresh bool) []File { if m.OtherFile == nil || refresh { resp, _ := get("https://api.github.com/repos/" + m.Repo + "/contents")