mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Fix lfs file viewer (#14568)
This commit is contained in:
		@@ -385,7 +385,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	fileSize := blob.Size()
 | 
						fileSize := blob.Size()
 | 
				
			||||||
	ctx.Data["FileIsSymlink"] = entry.IsLink()
 | 
						ctx.Data["FileIsSymlink"] = entry.IsLink()
 | 
				
			||||||
	ctx.Data["FileSize"] = fileSize
 | 
					 | 
				
			||||||
	ctx.Data["FileName"] = blob.Name()
 | 
						ctx.Data["FileName"] = blob.Name()
 | 
				
			||||||
	ctx.Data["RawFileLink"] = rawLink + "/" + ctx.Repo.TreePath
 | 
						ctx.Data["RawFileLink"] = rawLink + "/" + ctx.Repo.TreePath
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -395,21 +394,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	isTextFile := base.IsTextFile(buf)
 | 
						isTextFile := base.IsTextFile(buf)
 | 
				
			||||||
	isLFSFile := false
 | 
						isLFSFile := false
 | 
				
			||||||
	ctx.Data["IsTextFile"] = isTextFile
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	isDisplayingSource := ctx.Query("display") == "source"
 | 
						isDisplayingSource := ctx.Query("display") == "source"
 | 
				
			||||||
	isDisplayingRendered := !isDisplayingSource
 | 
						isDisplayingRendered := !isDisplayingSource
 | 
				
			||||||
	isRepresentableAsText := base.IsRepresentableAsText(buf)
 | 
					 | 
				
			||||||
	ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
 | 
					 | 
				
			||||||
	if !isRepresentableAsText {
 | 
					 | 
				
			||||||
		// If we can't show plain text, always try to render.
 | 
					 | 
				
			||||||
		isDisplayingSource = false
 | 
					 | 
				
			||||||
		isDisplayingRendered = true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	ctx.Data["IsDisplayingSource"] = isDisplayingSource
 | 
					 | 
				
			||||||
	ctx.Data["IsDisplayingRendered"] = isDisplayingRendered
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Check for LFS meta file
 | 
						//Check for LFS meta file
 | 
				
			||||||
	if isTextFile && setting.LFS.StartServer {
 | 
						if isTextFile && setting.LFS.StartServer {
 | 
				
			||||||
@@ -422,7 +408,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if meta != nil {
 | 
							if meta != nil {
 | 
				
			||||||
			ctx.Data["IsLFSFile"] = true
 | 
					 | 
				
			||||||
			isLFSFile = true
 | 
								isLFSFile = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// OK read the lfs object
 | 
								// OK read the lfs object
 | 
				
			||||||
@@ -445,14 +430,25 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
			buf = buf[:n]
 | 
								buf = buf[:n]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			isTextFile = base.IsTextFile(buf)
 | 
								isTextFile = base.IsTextFile(buf)
 | 
				
			||||||
			ctx.Data["IsTextFile"] = isTextFile
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			fileSize = meta.Size
 | 
								fileSize = meta.Size
 | 
				
			||||||
			ctx.Data["FileSize"] = meta.Size
 | 
								ctx.Data["RawFileLink"] = fmt.Sprintf("%s/media/%s/%s", ctx.Repo.RepoLink, ctx.Repo.BranchNameSubURL(), ctx.Repo.TreePath)
 | 
				
			||||||
			filenameBase64 := base64.RawURLEncoding.EncodeToString([]byte(blob.Name()))
 | 
					 | 
				
			||||||
			ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						isRepresentableAsText := base.IsRepresentableAsText(buf)
 | 
				
			||||||
 | 
						if !isRepresentableAsText {
 | 
				
			||||||
 | 
							// If we can't show plain text, always try to render.
 | 
				
			||||||
 | 
							isDisplayingSource = false
 | 
				
			||||||
 | 
							isDisplayingRendered = true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx.Data["IsLFSFile"] = isLFSFile
 | 
				
			||||||
 | 
						ctx.Data["FileSize"] = fileSize
 | 
				
			||||||
 | 
						ctx.Data["IsTextFile"] = isTextFile
 | 
				
			||||||
 | 
						ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
 | 
				
			||||||
 | 
						ctx.Data["IsDisplayingSource"] = isDisplayingSource
 | 
				
			||||||
 | 
						ctx.Data["IsDisplayingRendered"] = isDisplayingRendered
 | 
				
			||||||
 | 
						ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check LFS Lock
 | 
						// Check LFS Lock
 | 
				
			||||||
	lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
 | 
						lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
 | 
				
			||||||
	ctx.Data["LFSLock"] = lfsLock
 | 
						ctx.Data["LFSLock"] = lfsLock
 | 
				
			||||||
@@ -542,7 +538,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
			ctx.Data["MarkupType"] = markupType
 | 
								ctx.Data["MarkupType"] = markupType
 | 
				
			||||||
			ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
 | 
								ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ctx.Repo.CanEnableEditor() {
 | 
						if ctx.Repo.CanEnableEditor() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user