]> source.dussan.org Git - gitblit.git/commitdiff
Fix for #1018 and #1025 browser LFS links 1027/head
authorPaul Martin <paul@paulsputer.com>
Mon, 21 Mar 2016 17:41:19 +0000 (17:41 +0000)
committerPaul Martin <paul@paulsputer.com>
Mon, 21 Mar 2016 17:41:19 +0000 (17:41 +0000)
+ View and Raw both download the actual file
+ Blame will show the metafile

src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
src/main/java/com/gitblit/wicket/pages/CommitPage.java
src/main/java/com/gitblit/wicket/pages/TreePage.java
src/main/java/com/gitblit/wicket/panels/LinkPanel.java

index 9bc1570d44b02a4b8dc546c25ef412f0504d3a9c..eaff2067dc9cc855dc4b9fce2c97c0f69d0e41f8 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.gitblit.wicket.pages;
 
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -23,9 +24,13 @@ import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.apache.wicket.markup.html.link.ExternalLink;
+import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;
+import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
+import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
+import org.apache.wicket.util.resource.IResourceStream;
 import org.eclipse.jgit.diff.DiffEntry.ChangeType;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
@@ -35,6 +40,7 @@ import com.gitblit.Keys;
 import com.gitblit.models.GitNote;
 import com.gitblit.models.PathModel.PathChangeModel;
 import com.gitblit.models.SubmoduleModel;
+import com.gitblit.models.UserModel;
 import com.gitblit.servlet.RawServlet;
 import com.gitblit.utils.DiffUtils;
 import com.gitblit.utils.DiffUtils.DiffComparator;
@@ -42,6 +48,7 @@ import com.gitblit.utils.DiffUtils.DiffOutput;
 import com.gitblit.utils.DiffUtils.DiffOutputType;
 import com.gitblit.utils.JGitUtils;
 import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.CacheControl.LastModified;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.CommitHeaderPanel;
@@ -135,7 +142,6 @@ public class CommitDiffPage extends RepositoryPage {
                        @Override
                        public void populateItem(final Item<PathChangeModel> item) {
                                final PathChangeModel entry = item.getModelObject();
-                               final String filestoreItemUrl = entry.isFilestoreItem() ? JGitUtils.getLfsRepositoryUrl(getContextUrl(), repositoryName, entry.getFilestoreOid()) : null; 
                                
                                Label changeType = new Label("changeType", "");
                                WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
@@ -162,7 +168,34 @@ public class CommitDiffPage extends RepositoryPage {
                                        item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId));
                                } else {
                                        // add relative link
-                                       item.add(new LinkPanel("pathName", "list", entry.path, entry.isFilestoreItem() ? filestoreItemUrl : "#n" + entry.objectId));
+                                       if (entry.isFilestoreItem()) {
+                                       
+                                               item.add(new LinkPanel("pathName", "list", entry.path, new Link<Object>("link", null) {
+                                                        
+                                                       private static final long serialVersionUID = 1L;
+
+                                                       @Override
+                                                   public void onClick() {
+                                                               IResourceStream resourceStream = new AbstractResourceStreamWriter() {
+                                                                                                                                       
+                                                                       private static final long serialVersionUID = 1L;
+       
+                                                                       @Override 
+                                                           public void write(OutputStream output) {
+                                                                               UserModel user =  GitBlitWebSession.get().getUser();
+                                                                           user = user == null ? UserModel.ANONYMOUS : user;
+                                                                               
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
+                                                                       }
+                                                               };
+                                                               
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
+                                                   }}));
+                                       }
+                                       else
+                                       {
+                                               item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId));
+                                       }
                                }
 
                                // quick links
@@ -188,8 +221,53 @@ public class CommitDiffPage extends RepositoryPage {
                                        if (entry.isFilestoreItem()) {
                                                item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));
                                                
-                                               item.add(new ExternalLink("view", filestoreItemUrl));
-                                               item.add(new ExternalLink("raw", filestoreItemUrl));
+                                               item.add(new Link<Object>("view", null) {
+                                                        
+                                                       private static final long serialVersionUID = 1L;
+
+                                                       @Override
+                                                   public void onClick() {
+                                                
+                                                        IResourceStream resourceStream = new AbstractResourceStreamWriter() {
+                                                                                                                                       
+                                                                       private static final long serialVersionUID = 1L;
+
+                                                                       @Override 
+                                                             public void write(OutputStream output) {
+                                                                        UserModel user =  GitBlitWebSession.get().getUser();
+                                                                            user = user == null ? UserModel.ANONYMOUS : user;
+                                                                               
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
+                                                             }
+                                                         };
+                                                             
+                                                       
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
+                                                   }});
+                                               
+                                               item.add(new Link<Object>("raw", null) {
+                                                        
+                                                       private static final long serialVersionUID = 1L;
+
+                                                       @Override
+                                                   public void onClick() {
+                                                
+                                                        IResourceStream resourceStream = new AbstractResourceStreamWriter() {
+                                                                                                                                       
+                                                                       private static final long serialVersionUID = 1L;
+
+                                                                       @Override 
+                                                             public void write(OutputStream output) {
+                                                                        UserModel user =  GitBlitWebSession.get().getUser();
+                                                                            user = user == null ? UserModel.ANONYMOUS : user;
+                                                                               
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
+                                                             }
+                                                         };
+                                                             
+                                                       
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
+                                                   }});
                                        } else {
                                                
                                                item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
index c8411738675f9ef4c40a44eed4c420c58e5a2a31..417afe30fed3c604d0b66a894e39e5ed1a385364 100644 (file)
  */\r
 package com.gitblit.wicket.pages;\r
 \r
+import java.io.OutputStream;\r
+import java.sql.Blob;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
+import java.util.concurrent.Callable;\r
 \r
 import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.behavior.SimpleAttributeModifier;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
+import org.apache.wicket.markup.html.link.DownloadLink;\r
 import org.apache.wicket.markup.html.link.ExternalLink;\r
+import org.apache.wicket.markup.html.link.Link;\r
+import org.apache.wicket.markup.html.link.ResourceLink;\r
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+import org.apache.wicket.model.AbstractReadOnlyModel;\r
+import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.StringResourceModel;\r
+import org.apache.wicket.request.target.basic.RedirectRequestTarget;\r
+import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;\r
+import org.apache.wicket.util.resource.AbstractResourceStream;\r
+import org.apache.wicket.util.resource.AbstractResourceStreamWriter;\r
+import org.apache.wicket.util.resource.IResourceStream;\r
+import org.bouncycastle.jcajce.provider.symmetric.Threefish;\r
 import org.eclipse.jgit.diff.DiffEntry.ChangeType;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.manager.FilestoreManager;\r
+import com.gitblit.manager.GitblitManager;\r
+import com.gitblit.models.FilestoreModel;\r
 import com.gitblit.models.GitNote;\r
+import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.PathModel.PathChangeModel;\r
 import com.gitblit.models.SubmoduleModel;\r
+import com.gitblit.models.UserModel;\r
 import com.gitblit.servlet.RawServlet;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.CacheControl;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.CommitHeaderPanel;\r
@@ -198,7 +220,31 @@ public class CommitPage extends RepositoryPage {
                                        }\r
                                        \r
                                        if (entry.isFilestoreItem()) {\r
-                                               item.add(new LinkPanel("pathName", "list", entry.path, filestoreItemUrl));\r
+                                               item.add(new LinkPanel("pathName", "list", entry.path, new Link<Object>("link", null) {\r
+                                                        \r
+                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                       @Override\r
+                                                   public void onClick() {\r
+                                                \r
+                                                        IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                       \r
+                                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                                       @Override \r
+                                                             public void write(OutputStream output) {\r
+                                                                        UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                            user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                               \r
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                             }\r
+                                                         };\r
+                                                             \r
+                                                       \r
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                   }}));\r
+                                               \r
+                                               \r
                                        } else {\r
                                                item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,\r
                                                        WicketUtils.newPathParameter(repositoryName, entry.commitId, path)));\r
@@ -232,8 +278,56 @@ public class CommitPage extends RepositoryPage {
                                        if (entry.isFilestoreItem()) {\r
                                                item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));\r
                                                \r
-                                               item.add(new ExternalLink("view", filestoreItemUrl));\r
-                                               item.add(new ExternalLink("raw", filestoreItemUrl));\r
+                                               \r
+                                               \r
+                                               item.add(new Link<Object>("view", null) {\r
+                                                        \r
+                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                       @Override\r
+                                                   public void onClick() {\r
+                                                \r
+                                                        IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                       \r
+                                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                                       @Override \r
+                                                             public void write(OutputStream output) {\r
+                                                                        UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                            user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                               \r
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                             }\r
+                                                         };\r
+                                                             \r
+                                                       \r
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                   }});\r
+                                               \r
+                                               item.add(new Link<Object>("raw", null) {\r
+                                                        \r
+                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                       @Override\r
+                                                   public void onClick() {\r
+                                                \r
+                                                        IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                       \r
+                                                                       private static final long serialVersionUID = 1L;\r
+\r
+                                                                       @Override \r
+                                                             public void write(OutputStream output) {\r
+                                                                        UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                            user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                               \r
+                                                               app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                             }\r
+                                                         };\r
+                                                             \r
+                                                       \r
+                                                       getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                   }});\r
+                                                                                               \r
                                        } else {\r
                                                item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));\r
                                                \r
index f13821472703580854ad462482ebc26133690e45..3961e044f1bb657b222d2e397e2274a9120376fa 100644 (file)
  */\r
 package com.gitblit.wicket.pages;\r
 \r
+import java.io.OutputStream;\r
 import java.util.List;\r
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
 import org.apache.wicket.markup.html.link.ExternalLink;\r
+import org.apache.wicket.markup.html.link.Link;\r
 import org.apache.wicket.markup.html.panel.Fragment;\r
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;\r
+import org.apache.wicket.util.resource.AbstractResourceStreamWriter;\r
+import org.apache.wicket.util.resource.IResourceStream;\r
 import org.eclipse.jgit.lib.FileMode;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
 import com.gitblit.models.PathModel;\r
 import com.gitblit.models.SubmoduleModel;\r
+import com.gitblit.models.UserModel;\r
 import com.gitblit.servlet.RawServlet;\r
 import com.gitblit.utils.ByteFormat;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.CacheControl;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.CommitHeaderPanel;\r
@@ -88,7 +95,7 @@ public class TreePage extends RepositoryPage {
 \r
                        @Override\r
                        public void populateItem(final Item<PathModel> item) {\r
-                               PathModel entry = item.getModelObject();\r
+                               final PathModel entry = item.getModelObject();\r
                                \r
                                item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));\r
                                \r
@@ -170,11 +177,77 @@ public class TreePage extends RepositoryPage {
                                                if (entry.isFilestoreItem()) {\r
                                                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));\r
                                                        \r
-                                                       final String filestoreItemUrl = JGitUtils.getLfsRepositoryUrl(getContextUrl(), repositoryName, entry.getFilestoreOid());\r
+                                                       item.add(new LinkPanel("pathName", "list", displayPath, new Link<Object>("link", null) {\r
+                                                                \r
+                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                               @Override\r
+                                                           public void onClick() {\r
+                                                        \r
+                                                                IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                               \r
+                                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                                               @Override \r
+                                                                     public void write(OutputStream output) {\r
+                                                                                UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                                    user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                                       \r
+                                                                       app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                                     }\r
+                                                                 };\r
+                                                                     \r
+                                                               \r
+                                                               getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                           }}));\r
                                                        \r
-                                                       item.add(new LinkPanel("pathName", "list", displayPath, filestoreItemUrl));\r
-                                                       links.add(new ExternalLink("view", filestoreItemUrl));\r
-                                                       links.add(new ExternalLink("raw", filestoreItemUrl));\r
+                                                       links.add(new Link<Object>("view", null) {\r
+                                                                \r
+                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                               @Override\r
+                                                           public void onClick() {\r
+                                                        \r
+                                                                IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                               \r
+                                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                                               @Override \r
+                                                                     public void write(OutputStream output) {\r
+                                                                                UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                                    user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                                       \r
+                                                                       app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                                     }\r
+                                                                 };\r
+                                                                     \r
+                                                               \r
+                                                               getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                           }});\r
+                                                       \r
+                                                       links.add(new Link<Object>("raw", null) {\r
+                                                                \r
+                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                               @Override\r
+                                                           public void onClick() {\r
+                                                        \r
+                                                                IResourceStream resourceStream = new AbstractResourceStreamWriter() {\r
+                                                                                                                                               \r
+                                                                               private static final long serialVersionUID = 1L;\r
+\r
+                                                                               @Override \r
+                                                                     public void write(OutputStream output) {\r
+                                                                                UserModel user =  GitBlitWebSession.get().getUser();\r
+                                                                                    user = user == null ? UserModel.ANONYMOUS : user;\r
+                                                                                       \r
+                                                                       app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);\r
+                                                                     }\r
+                                                                 };\r
+                                                                     \r
+                                                               \r
+                                                               getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));\r
+                                                           }});\r
                                                        \r
                                                } else {\r
                                                        item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));\r
index 06159ac3b641346b1bd5054be3d5299e70e3d96e..aa09be09336dcca1e5452c1fe0bd5f815af85965 100644 (file)
@@ -15,6 +15,9 @@
  */\r
 package com.gitblit.wicket.panels;\r
 \r
+import java.io.OutputStream;\r
+import java.util.concurrent.Callable;\r
+\r
 import org.apache.wicket.Component;\r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.behavior.SimpleAttributeModifier;\r
@@ -26,8 +29,13 @@ import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.html.panel.Panel;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
+import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;\r
+import org.apache.wicket.util.resource.AbstractResourceStreamWriter;\r
+import org.apache.wicket.util.resource.IResourceStream;\r
 \r
+import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 public class LinkPanel extends Panel {\r
@@ -108,6 +116,20 @@ public class LinkPanel extends Panel {
                add(link);\r
        }\r
 \r
+       public LinkPanel(String wicketId, String linkCssClass, String label, Link<?> link) {\r
+               super(wicketId);\r
+               \r
+               this.labelModel = new Model<String>(label);\r
+               \r
+               if (linkCssClass != null) {\r
+                       link.add(new SimpleAttributeModifier("class", linkCssClass));\r
+               }\r
+               \r
+               link.add(new Label("icon").setVisible(false));\r
+               link.add(new Label("label", labelModel));\r
+               add(link);\r
+       }\r
+\r
        public void setNoFollow() {\r
                Component c = get("link");\r
                c.add(new SimpleAttributeModifier("rel", "nofollow"));\r