mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-20 20:07:03 +01:00
Merge branch 'master' of github.com:gogits/gogs
This commit is contained in:
commit
d2ceb001d0
7 changed files with 89 additions and 22 deletions
|
@ -6,6 +6,7 @@ package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -42,6 +43,14 @@ func IsMarkdownFile(name string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsTextFile(data []byte) (string, bool) {
|
||||||
|
contentType := http.DetectContentType(data)
|
||||||
|
if strings.Index(contentType, "text/") != -1 {
|
||||||
|
return contentType, true
|
||||||
|
}
|
||||||
|
return contentType, false
|
||||||
|
}
|
||||||
|
|
||||||
func IsReadmeFile(name string) bool {
|
func IsReadmeFile(name string) bool {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if len(name) < 6 {
|
if len(name) < 6 {
|
||||||
|
|
|
@ -291,7 +291,7 @@ function initRepository() {
|
||||||
$clone.find('button[data-link]').on("click",function (e) {
|
$clone.find('button[data-link]').on("click",function (e) {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
if (!$this.hasClass('btn-primary')) {
|
if (!$this.hasClass('btn-primary')) {
|
||||||
$clone.find('.btn-primary').removeClass('btn-primary').addClass("btn-default");
|
$clone.find('.input-group-btn .btn-primary').removeClass('btn-primary').addClass("btn-default");
|
||||||
$(this).addClass('btn-primary').removeClass('btn-default');
|
$(this).addClass('btn-primary').removeClass('btn-default');
|
||||||
$url.val($this.data("link"));
|
$url.val($this.data("link"));
|
||||||
$clone.find('span.clone-url').text($this.data('link'));
|
$clone.find('span.clone-url').text($this.data('link'));
|
||||||
|
|
|
@ -6,11 +6,11 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/codegangsta/martini"
|
"github.com/codegangsta/martini"
|
||||||
|
|
||||||
"github.com/gogits/git"
|
|
||||||
"github.com/gogits/webdav"
|
"github.com/gogits/webdav"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
@ -96,6 +96,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"]
|
branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"]
|
||||||
|
rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + params["branchname"]
|
||||||
|
|
||||||
if len(treename) != 0 && repoFile == nil {
|
if len(treename) != 0 && repoFile == nil {
|
||||||
ctx.Handle(404, "repo.Single", nil)
|
ctx.Handle(404, "repo.Single", nil)
|
||||||
|
@ -103,12 +104,10 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoFile != nil && repoFile.IsFile() {
|
if repoFile != nil && repoFile.IsFile() {
|
||||||
if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob {
|
if blob, err := repoFile.LookupBlob(); err != nil {
|
||||||
ctx.Data["FileIsLarge"] = true
|
|
||||||
} else if blob, err := repoFile.LookupBlob(); err != nil {
|
|
||||||
//log.Error("repo.Single(repoFile.LookupBlob): %v", err)
|
|
||||||
ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err)
|
ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err)
|
||||||
} else {
|
} else {
|
||||||
|
ctx.Data["FileSize"] = repoFile.Size
|
||||||
ctx.Data["IsFile"] = true
|
ctx.Data["IsFile"] = true
|
||||||
ctx.Data["FileName"] = repoFile.Name
|
ctx.Data["FileName"] = repoFile.Name
|
||||||
ext := path.Ext(repoFile.Name)
|
ext := path.Ext(repoFile.Name)
|
||||||
|
@ -116,13 +115,20 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
ext = ext[1:]
|
ext = ext[1:]
|
||||||
}
|
}
|
||||||
ctx.Data["FileExt"] = ext
|
ctx.Data["FileExt"] = ext
|
||||||
|
ctx.Data["FileLink"] = rawLink + "/" + treename
|
||||||
|
|
||||||
|
data := blob.Contents()
|
||||||
|
_, isTextFile := base.IsTextFile(data)
|
||||||
|
ctx.Data["FileIsText"] = isTextFile
|
||||||
|
|
||||||
readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
|
readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name)
|
||||||
ctx.Data["ReadmeExist"] = readmeExist
|
ctx.Data["ReadmeExist"] = readmeExist
|
||||||
if readmeExist {
|
if readmeExist {
|
||||||
ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), ""))
|
ctx.Data["FileContent"] = string(base.RenderMarkdown(data, ""))
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["FileContent"] = string(blob.Contents())
|
if isTextFile {
|
||||||
|
ctx.Data["FileContent"] = string(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,17 +157,19 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
|
|
||||||
if readmeFile != nil {
|
if readmeFile != nil {
|
||||||
ctx.Data["ReadmeExist"] = true
|
ctx.Data["ReadmeExist"] = true
|
||||||
// if file large than 1M not show it
|
if blob, err := readmeFile.LookupBlob(); err != nil {
|
||||||
if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob {
|
|
||||||
ctx.Data["FileIsLarge"] = true
|
|
||||||
} else if blob, err := readmeFile.LookupBlob(); err != nil {
|
|
||||||
ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err)
|
ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
// current repo branch link
|
ctx.Data["FileSize"] = readmeFile.Size
|
||||||
|
ctx.Data["FileLink"] = rawLink + "/" + treename
|
||||||
|
data := blob.Contents()
|
||||||
|
_, isTextFile := base.IsTextFile(data)
|
||||||
|
ctx.Data["FileIsText"] = isTextFile
|
||||||
ctx.Data["FileName"] = readmeFile.Name
|
ctx.Data["FileName"] = readmeFile.Name
|
||||||
ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), branchLink))
|
if isTextFile {
|
||||||
|
ctx.Data["FileContent"] = string(base.RenderMarkdown(data, branchLink))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +209,44 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
ctx.HTML(200, "repo/single")
|
ctx.HTML(200, "repo/single")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SingleDownload(ctx *middleware.Context, params martini.Params) {
|
||||||
|
if !ctx.Repo.IsValid {
|
||||||
|
ctx.Handle(404, "repo.SingleDownload", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params["branchname"]) == 0 {
|
||||||
|
params["branchname"] = "master"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get tree path
|
||||||
|
treename := params["_1"]
|
||||||
|
|
||||||
|
repoFile, err := models.GetTargetFile(params["username"], params["reponame"],
|
||||||
|
params["branchname"], params["commitid"], treename)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(404, "repo.SingleDownload(GetTargetFile)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
blob, err := repoFile.LookupBlob()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(404, "repo.SingleDownload(LookupBlob)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := blob.Contents()
|
||||||
|
contentType, isTextFile := base.IsTextFile(data)
|
||||||
|
ctx.Res.Header().Set("Content-Type", contentType)
|
||||||
|
if !isTextFile {
|
||||||
|
ctx.Res.Header().Set("Content-Type", contentType)
|
||||||
|
ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename))
|
||||||
|
ctx.Res.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
|
}
|
||||||
|
ctx.Res.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
func Http(ctx *middleware.Context, params martini.Params) {
|
func Http(ctx *middleware.Context, params martini.Params) {
|
||||||
/*if !ctx.Repo.IsValid {
|
/*if !ctx.Repo.IsValid {
|
||||||
return
|
return
|
||||||
|
|
|
@ -30,6 +30,10 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block text-center">Need help cloning? Visit <a href="#">Help</a>!</p>
|
<p class="help-block text-center">Need help cloning? Visit <a href="#">Help</a>!</p>
|
||||||
|
<hr/>
|
||||||
|
<div class="clone-zip text-center">
|
||||||
|
<a class="btn btn-success btn-lg" href="#"><i class="fa fa-suitcase"></i>Download ZIP</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group {{if .IsRepositoryWatching}}watching{{else}}no-watching{{end}}" id="gogs-repo-watching" data-watch="/{{.Owner.Name}}/{{.Repository.Name}}/action/watch" data-unwatch="/{{.Owner.Name}}/{{.Repository.Name}}/action/unwatch">
|
<div class="btn-group {{if .IsRepositoryWatching}}watching{{else}}no-watching{{end}}" id="gogs-repo-watching" data-watch="/{{.Owner.Name}}/{{.Repository.Name}}/action/watch" data-unwatch="/{{.Owner.Name}}/{{.Repository.Name}}/action/unwatch">
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="source-toolbar">
|
<div class="source-toolbar">
|
||||||
{{ $n := len .Treenames}}
|
{{ $n := len .Treenames}}
|
||||||
{{if not .IsFile}}<button class="btn btn-default pull-right"><i class="fa fa-plus-square"></i>Add File</button>{{end}}
|
{{if not .IsFile}}<button class="btn btn-default pull-right hidden"><i class="fa fa-plus-square"></i>Add File</button>{{end}}
|
||||||
<div class="dropdown branch-switch">
|
<div class="dropdown branch-switch">
|
||||||
<a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>{{.Branchname}}
|
<a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>{{.Branchname}}
|
||||||
<b class="caret"></b></a>
|
<b class="caret"></b></a>
|
||||||
|
|
|
@ -3,13 +3,19 @@
|
||||||
{{if .ReadmeExist}}
|
{{if .ReadmeExist}}
|
||||||
<i class="icon fa fa-book"></i>
|
<i class="icon fa fa-book"></i>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
<div class="btn-group pull-right">
|
||||||
|
<a class="btn btn-default hidden" href="#">Edit</a>
|
||||||
|
<a class="btn btn-default" href="{{.FileLink}}">Raw</a>
|
||||||
|
<a class="btn btn-default hidden" href="#">Blame</a>
|
||||||
|
<a class="btn btn-default hidden" href="#">History</a>
|
||||||
|
<a class="btn btn-danger hidden" href="#">Delete</a>
|
||||||
|
</div>
|
||||||
<i class="icon fa fa-file-text-o"></i>
|
<i class="icon fa fa-file-text-o"></i>
|
||||||
{{end}}{{.FileName}}
|
{{end}}{{.FileName}} {{FileSize .FileSize}}
|
||||||
<a class="btn btn-default pull-right" href="#">Raw</a>
|
|
||||||
</div>
|
</div>
|
||||||
{{if .FileIsLarge}}
|
{{if not .FileIsText}}
|
||||||
<div class="panel-footer">
|
<div class="panel-footer text-center">
|
||||||
Large file size 1000kb
|
<a href="{{.FileLink}}" class="btn btn-default">View Raw</a>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if .ReadmeExist}}
|
{{if .ReadmeExist}}
|
||||||
|
@ -22,7 +28,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="lines-num"></td>
|
<td class="lines-num"></td>
|
||||||
<td class="lines-code markdown"><pre class="prettyprint linenums lang-{{.FileExt}}">{{.FileContent}}</pre></td>
|
<td class="lines-code markdown"><pre class="prettyprint linenums{{if .FileExt}} lang-{{.FileExt}}{{end}}">{{.FileContent}}</pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
2
web.go
2
web.go
|
@ -152,6 +152,7 @@ func runWeb(*cli.Context) {
|
||||||
r.Get("/branches", repo.Branches)
|
r.Get("/branches", repo.Branches)
|
||||||
r.Get("/src/:branchname", repo.Single)
|
r.Get("/src/:branchname", repo.Single)
|
||||||
r.Get("/src/:branchname/**", repo.Single)
|
r.Get("/src/:branchname/**", repo.Single)
|
||||||
|
r.Get("/raw/:branchname/**", repo.SingleDownload)
|
||||||
r.Get("/commits/:branchname", repo.Commits)
|
r.Get("/commits/:branchname", repo.Commits)
|
||||||
r.Get("/commits/:branchname", repo.Commits)
|
r.Get("/commits/:branchname", repo.Commits)
|
||||||
}, ignSignIn, middleware.RepoAssignment(true))
|
}, ignSignIn, middleware.RepoAssignment(true))
|
||||||
|
@ -161,6 +162,7 @@ func runWeb(*cli.Context) {
|
||||||
m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Diff)
|
m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Diff)
|
||||||
|
|
||||||
m.Group("/:username", func(r martini.Router) {
|
m.Group("/:username", func(r martini.Router) {
|
||||||
|
r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single)
|
||||||
r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single)
|
r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single)
|
||||||
r.Any("/:reponame/**", repo.Http)
|
r.Any("/:reponame/**", repo.Http)
|
||||||
}, ignSignIn)
|
}, ignSignIn)
|
||||||
|
|
Loading…
Reference in a new issue