Skip to content

Commit c7574b5

Browse files
KirCutenibazshab
andauthored
feat(github_release): support Source code (zip/tar.gz) (#1581)
* support Github Release Source code (zip/tar.gz) * fix TarballUrl and ZipballUrl * fix show source code by allversion --------- Co-authored-by: nibazshab <44338441+nibazshab@users.noreply.github.com>
1 parent 9e852ba commit c7574b5

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

drivers/github_releases/driver.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func (d *GithubReleases) List(ctx context.Context, dir model.Obj, args model.Lis
5151
if d.Addition.ShowReadme {
5252
files = append(files, point.GetOtherFile(d.GetRequest, args.Refresh)...)
5353
}
54+
if d.Addition.ShowSourceCode{
55+
files = append(files, point.GetSourceCode()...)
56+
}
5457
} else if strings.HasPrefix(point.Point, path) { // 仓库目录的父目录
5558
nextDir := GetNextDir(point.Point, path)
5659
if nextDir == "" {
@@ -117,6 +120,10 @@ func (d *GithubReleases) List(ctx context.Context, dir model.Obj, args model.Lis
117120
}
118121

119122
files = append(files, point.GetReleaseByTagName(tagName)...)
123+
124+
if d.Addition.ShowSourceCode{
125+
files = append(files, point.GetSourceCodeByTagName(tagName)...)
126+
}
120127
}
121128
}
122129
}

drivers/github_releases/meta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Addition struct {
1010
RepoStructure string `json:"repo_structure" type:"text" required:"true" default:"OpenListTeam/OpenList" help:"structure:[path:]org/repo"`
1111
ShowReadme bool `json:"show_readme" type:"bool" default:"true" help:"show README、LICENSE file"`
1212
Token string `json:"token" type:"string" required:"false" help:"GitHub token, if you want to access private repositories or increase the rate limit"`
13+
ShowSourceCode bool `json:"show_source_code" type:"bool" default:"false" help:"show Source code (zip/tar.gz)"`
1314
ShowAllVersion bool `json:"show_all_version" type:"bool" default:"false" help:"show all versions"`
1415
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 "`
1516
}

drivers/github_releases/types.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,60 @@ func (m *MountPoint) GetAllVersionSize() int64 {
143143
return size
144144
}
145145

146+
func (m *MountPoint) GetSourceCode() []File {
147+
files := make([]File, 0)
148+
149+
// 无法获取文件大小,此处设为 1
150+
files = append(files, File{
151+
Path: m.Point + "/" + "Source code (zip)",
152+
FileName: "Source code (zip)",
153+
Size: 1,
154+
Type: "file",
155+
UpdateAt: m.Release.CreatedAt,
156+
CreateAt: m.Release.CreatedAt,
157+
Url: m.Release.ZipballUrl,
158+
})
159+
files = append(files, File{
160+
Path: m.Point + "/" + "Source code (tar.gz)",
161+
FileName: "Source code (tar.gz)",
162+
Size: 1,
163+
Type: "file",
164+
UpdateAt: m.Release.CreatedAt,
165+
CreateAt: m.Release.CreatedAt,
166+
Url: m.Release.TarballUrl,
167+
})
168+
169+
return files
170+
}
171+
172+
func (m *MountPoint) GetSourceCodeByTagName(tagName string) []File {
173+
for _, item := range *m.Releases {
174+
if item.TagName == tagName {
175+
files := make([]File, 0)
176+
files = append(files, File{
177+
Path: m.Point + "/" + "Source code (zip)",
178+
FileName: "Source code (zip)",
179+
Size: 1,
180+
Type: "file",
181+
UpdateAt: item.CreatedAt,
182+
CreateAt: item.CreatedAt,
183+
Url: item.ZipballUrl,
184+
})
185+
files = append(files, File{
186+
Path: m.Point + "/" + "Source code (tar.gz)",
187+
FileName: "Source code (tar.gz)",
188+
Size: 1,
189+
Type: "file",
190+
UpdateAt: item.CreatedAt,
191+
CreateAt: item.CreatedAt,
192+
Url: item.TarballUrl,
193+
})
194+
return files
195+
}
196+
}
197+
return nil
198+
}
199+
146200
func (m *MountPoint) GetOtherFile(get func(url string) (*resty.Response, error), refresh bool) []File {
147201
if m.OtherFile == nil || refresh {
148202
resp, _ := get("https://api.github.com/repos/" + m.Repo + "/contents")

0 commit comments

Comments
 (0)