-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Added URL mapping for Release attachments like on github.com #1700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
2e6c39b
1a539a6
aefa570
0a9a812
5ca8651
84d22d8
52b4dea
98cb0d2
7aa17f7
4119816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,31 @@ func Action(ctx *context.Context) { | |
ctx.Redirect(redirectTo) | ||
} | ||
|
||
// RedirectDownload return a file based on the the following infos: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated the |
||
func RedirectDownload(ctx *context.Context) { | ||
var ( | ||
vTag = ctx.Params("vTag") | ||
fileName = ctx.Params("fileName") | ||
) | ||
tagNames := []string{vTag} | ||
curRepo := ctx.Repo.Repository | ||
releases, err := models.GetReleasesByRepoIDAndNames(curRepo.ID, tagNames) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there should be also added or statement to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need, it'll fall through :) |
||
ctx.Handle(404, "RedirectDownload -> Release not found", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to be a 500 error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done |
||
return | ||
} | ||
|
||
if len(releases) == 1 { | ||
release := releases[0] | ||
att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName) | ||
if err != nil { | ||
ctx.Handle(404, "RedirectDownload -> Attachment not found", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to be a 500 error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will return ErrAttachmentNotExist error when no attachment by that filename exists. I think logic need to remade for GetAttachmentByReleaseIDFileName to return nil, nil when no attachment is found, so that it could be easily returned 404 on nil, nil and 500 on nil, err There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it can also be a DB-error, in which case it should be an error... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if err != nil {
if _, ok := err.(*ErrAttachmentNotFound); ok {
ctx.Handle(404, "RedirectDownload: Attachment not found", err)
return
}
ctx.Handle(500, "RedirectDownload: Failed to get attachment", err)
return
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guys I'm getting pissed off just past the full code and I copy and past it... 🥇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I give up !!!! I will stop pushing my features on this repo I will use my features myself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bkcsoft test your code before you post it because it is broken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return | ||
} | ||
ctx.Redirect(setting.AppSubURL + "/attachments/" + att.UUID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. place this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End the function with |
||
|
||
// Download download an archive of a repository | ||
func Download(ctx *context.Context) { | ||
var ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -486,6 +486,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |
m.Get("/:id/:action", repo.ChangeMilestonStatus) | ||
m.Post("/delete", repo.DeleteMilestone) | ||
}, reqRepoWriter, context.RepoRef()) | ||
m.Group("/releases", func() { | ||
m.Get("/download/:vTag/:fileName", repo.RedirectDownload) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to the Group just below (since they are identical) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef()) | ||
m.Group("/releases", func() { | ||
m.Get("/new", repo.NewRelease) | ||
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,21 +53,25 @@ | |
<div class="download"> | ||
<h2>{{$.i18n.Tr "repo.release.downloads"}}</h2> | ||
<ul class="list"> | ||
{{$tagname := .TagName}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're using a named range, you don't need this assignment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this assignment is needed because tag range is not named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct |
||
{{if .Attachments}} | ||
{{range $attachment := .Attachments}} | ||
<li> | ||
<!-- {{AppSubUrl}}/attachments/{{$attachment.UUID}} --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented out code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will not remove this out because I want to add for each release an option to display like github url or leave it the old way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. than it has to be done before it gets merged in master There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok it's removed now I will do that later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove old comments :) |
||
<a target="_blank" rel="noopener" href="{{$.RepoLink}}/releases/download/{{$tagname}}/{{$attachment.Name}}"> | ||
<span class="ui image octicon octicon-desktop-download" title='{{$attachment.Name}}'></span> {{$attachment.Name}} | ||
<a target="_blank" href="{{$.RepoLink}}/releases/download/{{$tagname}}/{{$attachment.Name}}" class="ui right"><span class="ui image octicon octicon-file-binary" title='{{$attachment.Name}}'></span>{{$attachment.FileSize}}</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should not be tag inside tag. File size shoud be moved out of link, seperated with space and placed in brackets: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it is not forbidden in HTML and there is a reason so I leave it. The font displayed is different from the front of the row with the filename so that is the reason I put this inside of another . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but why would you need that? Why first link is not enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the font is displayed differently from the other file description. The MB is some kind of Time New Roman. It is convenient for the user to give him a choice of either clicking on the file size, the icon or the filename to download. It is UI experience. |
||
</a> | ||
</li> | ||
{{end}} | ||
{{end}} | ||
<li> | ||
<a href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (ZIP)</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> | ||
</li> | ||
{{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}} | ||
</a> | ||
</li> | ||
{{end}} | ||
{{end}} | ||
|
||
</ul> | ||
</div> | ||
{{else}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to
return nil, nil
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ?????????????????????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can later understand and check if file was not found or if there was some internal error that you have to return error 500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of telling me how to change it why don't you post the full code so that I get what you try to mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i hope you are happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you changed it in wrong function and wrong line. You need to change:
return nil, ErrAttachmentNotExist{0, attach.UUID}
toreturn nin, nin
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you expressed it wrong that's why I could not understand!