mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Improve release page UI (#3693)
* Improve release page ui by adding size Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation to a.MustSize() Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
		@@ -11,6 +11,7 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	"code.gitea.io/gitea/modules/setting"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
	api "code.gitea.io/sdk/gitea"
 | 
			
		||||
@@ -75,6 +76,16 @@ func (a *Attachment) Size() (int64, error) {
 | 
			
		||||
	return fi.Size(), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MustSize returns the result of a.Size() by ignoring errors
 | 
			
		||||
func (a *Attachment) MustSize() int64 {
 | 
			
		||||
	size, err := a.Size()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error(4, "size: %v", err)
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	return size
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DownloadURL returns the download url of the attached file
 | 
			
		||||
func (a *Attachment) DownloadURL() string {
 | 
			
		||||
	return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID)
 | 
			
		||||
 
 | 
			
		||||
@@ -68,17 +68,18 @@
 | 
			
		||||
								<ul class="list">
 | 
			
		||||
									{{if $.Repository.UnitEnabled $.UnitTypeCode}}
 | 
			
		||||
									<li>
 | 
			
		||||
										<a href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (ZIP)</a>
 | 
			
		||||
										<a href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><strong><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (ZIP)</strong></a>
 | 
			
		||||
									</li>
 | 
			
		||||
									<li>
 | 
			
		||||
										<a href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (TAR.GZ)</a>
 | 
			
		||||
										<a href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><strong><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (TAR.GZ)</strong></a>
 | 
			
		||||
									</li>
 | 
			
		||||
									{{end}}
 | 
			
		||||
									{{if .Attachments}}
 | 
			
		||||
									{{range .Attachments}}
 | 
			
		||||
									<li>
 | 
			
		||||
										<a target="_blank" rel="noopener" href="{{AppSubUrl}}/attachments/{{.UUID}}">
 | 
			
		||||
											<span class="ui image octicon octicon-desktop-download" title='{{.Name}}'></span> {{.Name}}
 | 
			
		||||
											<strong><span class="ui image octicon octicon-package" title='{{.Name}}'></span> {{.Name}}</strong>
 | 
			
		||||
											<span class="ui text grey right">{{.MustSize | FileSize}}</span>
 | 
			
		||||
										</a>
 | 
			
		||||
									</li>
 | 
			
		||||
									{{end}}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user