Skip to content
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

Allow display of LFS stored Readme.md on directory page (#6073) #6099

Merged
merged 11 commits into from Feb 21, 2019
62 changes: 33 additions & 29 deletions routers/repo/view.go
Expand Up @@ -108,36 +108,40 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["IsLFSFile"] = false

// FIXME: what happens when README file is an image?
if isTextFile {
if setting.LFS.StartServer {
if meta := lfs.IsPointerFile(&buf); meta != nil {
if meta, _ = ctx.Repo.Repository.GetLFSMetaObjectByOid(meta.Oid); meta != nil {
ctx.Data["IsLFSFile"] = true
isLFSFile = true

// OK read the lfs object
var err error
dataRc, err = lfs.ReadMetaObject(meta)
if err != nil {
ctx.ServerError("ReadMetaObject", err)
return
}
defer dataRc.Close()

buf = make([]byte, 1024)
n, _ = dataRc.Read(buf)
buf = buf[:n]

isTextFile = base.IsTextFile(buf)
ctx.Data["IsTextFile"] = isTextFile

fileSize = meta.Size
ctx.Data["FileSize"] = meta.Size
filenameBase64 := base64.RawURLEncoding.EncodeToString([]byte(readmeFile.Name()))
ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
isLFSFile = true
}
if isTextFile && setting.LFS.StartServer {
meta := lfs.IsPointerFile(&buf)
if meta != nil {
meta, err = ctx.Repo.Repository.GetLFSMetaObjectByOid(meta.Oid)
if err != models.ErrLFSObjectNotExist {
ctx.ServerError("GetLFSMetaObject", err)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
}
}

if meta != nil {
ctx.Data["IsLFSFile"] = true
isLFSFile = true

// OK read the lfs object
var err error
dataRc, err = lfs.ReadMetaObject(meta)
if err != nil {
ctx.ServerError("ReadMetaObject", err)
return
}
defer dataRc.Close()

buf = make([]byte, 1024)
n, _ = dataRc.Read(buf)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
buf = buf[:n]

isTextFile = base.IsTextFile(buf)
ctx.Data["IsTextFile"] = isTextFile

fileSize = meta.Size
ctx.Data["FileSize"] = meta.Size
filenameBase64 := base64.RawURLEncoding.EncodeToString([]byte(readmeFile.Name()))
ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
isLFSFile = true
}
}

Expand Down