Skip to content

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

Closed

Conversation

al-sabr
Copy link
Contributor

@al-sabr al-sabr commented May 10, 2017

Implement a Git Hub style URL mapping for the attachment files in Release.

See screenshot : screenshot

@lunny lunny added the type/enhancement An improvement of existing functionality label May 10, 2017
@lunny lunny added this to the 1.3.0 milestone May 10, 2017
@lunny
Copy link
Member

lunny commented May 10, 2017

An integration test is welcome.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 10, 2017
{{if .Attachments}}
{{range $attachment := .Attachments}}
<li>
<!-- {{AppSubUrl}}/attachments/{{$attachment.UUID}} -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@lafriks lafriks May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

than it has to be done before it gets merged in master

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok it's removed now I will do that later

curRepo := ctx.Repo.Repository

releases, err := models.GetReleasesByRepoIDAndNames(curRepo.ID, tagNames)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be also added or statement to check len(releases) == 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, it'll fall through :)

@@ -142,6 +157,22 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) {
return attachments, x.Where("comment_id=?", commentID).Find(&attachments)
}

/* Author : github.com/gdeverlant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add Author in comments, it will be visible in git history anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lafriks
Copy link
Member

lafriks commented May 10, 2017

Also need to fix this error: repo.go:271:1: comment on exported function RedirectDownload should be of the form "RedirectDownload ..."

Otherwise good job 👍

@@ -268,6 +268,34 @@ func Action(ctx *context.Context) {
ctx.Redirect(redirectTo)
}

// RedirectDownload return a file based on the the following infos:
Copy link
Member

@bkcsoft bkcsoft May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"// RedirectDownload returns a file based on tag and filename" :)

fileName = ctx.Params("fileName")
)
var tagNames []string
tagNames = append(tagNames, vTag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do tagNames := []string{vTag}

@@ -53,21 +53,25 @@
<div class="download">
<h2>{{$.i18n.Tr "repo.release.downloads"}}</h2>
<ul class="list">
{{$tagname := .TagName}}
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assignment is needed because tag range is not named

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things before LGTM :)

}
ctx.Redirect(setting.AppSubURL + "/attachments/" + att.UUID)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End the function with ctx.Handle(404, "RedirectDownload", nil) otherwise you get a 500 error if the release doesn't exist :)

@@ -486,6 +486,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:id/:action", repo.ChangeMilestonStatus)
m.Post("/delete", repo.DeleteMilestone)
}, reqRepoWriter, context.RepoRef())
// New redirection from fake url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this comment

@@ -486,6 +486,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:id/:action", repo.ChangeMilestonStatus)
m.Post("/delete", repo.DeleteMilestone)
}, reqRepoWriter, context.RepoRef())
// New redirection from fake url
m.Group("/releases", func() {
m.Get("/download/:vTag/:fileName", repo.RedirectDownload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the Group just below (since they are identical)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{{if .Attachments}}
{{range $attachment := .Attachments}}
<li>
<!-- {{AppSubUrl}}/attachments/{{$attachment.UUID}} -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove old comments :)

curRepo := ctx.Repo.Repository
releases, err := models.GetReleasesByRepoIDAndNames(curRepo.ID, tagNames)
if err != nil {
ctx.Handle(404, "RedirectDownload -> Release not found", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be a 500 error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done

release := releases[0]
att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName)
if err != nil {
ctx.Handle(404, "RedirectDownload -> Attachment not found", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be a 500 error

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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...

Copy link
Member

Choose a reason for hiding this comment

The 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
}

Copy link
Contributor Author

@al-sabr al-sabr May 10, 2017

Choose a reason for hiding this comment

The 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... 🥇

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Thanx for the inputs.

Copy link
Contributor Author

@al-sabr al-sabr May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bkcsoft test your code before you post it because it is broken.
You didn't declared ErrAttachmentNotFound
I'm fedup with your recommendations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

release := releases[0]
att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName)
if err != nil {
ctx.Handle(404, "RedirectDownload -> Attachment not found", err)
Copy link
Member

Choose a reason for hiding this comment

The 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

if err != nil {
return nil, err
} else if !has {
return nil, ErrAttachmentNotExist{0, attach.UUID}
Copy link
Member

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

Copy link
Contributor Author

@al-sabr al-sabr May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?????????????????????

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

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} to return nin, nin

Copy link
Contributor Author

@al-sabr al-sabr May 11, 2017

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!

ctx.Handle(404, "RedirectDownload -> Attachment not found", err)
return
}
ctx.Redirect(setting.AppSubURL + "/attachments/" + att.UUID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

place this into if att != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<li>
<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>
Copy link
Member

Choose a reason for hiding this comment

The 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: </a> ({{$attachment.FileSize}})

Copy link
Contributor Author

@al-sabr al-sabr May 10, 2017

Choose a reason for hiding this comment

The 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 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why would you need that? Why first link is not enough?

Copy link
Contributor Author

@al-sabr al-sabr May 10, 2017

Choose a reason for hiding this comment

The 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.

@@ -268,6 +268,33 @@ func Action(ctx *context.Context) {
ctx.Redirect(redirectTo)
}

// RedirectDownload return a file based on the the following infos:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeated the

Copy link
Contributor Author

@al-sabr al-sabr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a look

if err != nil {
return nil, err
} else if !has {
return nil, ErrAttachmentNotExist{0, attach.UUID}
Copy link
Contributor Author

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.

ctx.Handle(404, "RedirectDownload -> Attachment not found", err)
return
}
ctx.Redirect(setting.AppSubURL + "/attachments/" + att.UUID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -486,6 +486,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:id/:action", repo.ChangeMilestonStatus)
m.Post("/delete", repo.DeleteMilestone)
}, reqRepoWriter, context.RepoRef())
// New redirection from fake url
m.Group("/releases", func() {
m.Get("/download/:vTag/:fileName", repo.RedirectDownload)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -104,7 +114,7 @@ func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) {
attach := &Attachment{UUID: uuid}
has, err := e.Get(attach)
if err != nil {
return nil, err
return nil, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have changed this

@al-sabr
Copy link
Contributor Author

al-sabr commented May 11, 2017

can you guys remove this pull request totally I will not work on this anymore

@pgaskin
Copy link
Contributor

pgaskin commented May 11, 2017

It cannot be deleted, but it can be closed.

@al-sabr al-sabr closed this May 11, 2017
@al-sabr
Copy link
Contributor Author

al-sabr commented May 11, 2017

See for new pull request #1707

@al-sabr al-sabr deleted the git-style-release-url-attachments branch May 11, 2017 23:00
@lunny lunny removed this from the 1.3.0 milestone May 12, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants