mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-20 08:00:52 +00:00
[FEAT] Restrict file size of blame operation
- Currently there exists a restriction to not render and show files that are larger than what's configured in `[UI].MAX_DISPLAY_FILE_SIZE`. - Apply the same restriction to the blame operation as well, as the blame operation can be seen as displaying a file. - Add integration test. - Ref: #2394
This commit is contained in:
parent
b604b89108
commit
d8a267d3ab
3 changed files with 75 additions and 9 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/highlight"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
@ -69,6 +70,14 @@ func RefBlame(ctx *context.Context) {
|
|||
ctx.Data["FileSize"] = blob.Size()
|
||||
ctx.Data["FileName"] = blob.Name()
|
||||
|
||||
// Do not display a blame view if the size of the file is
|
||||
// larger than what is configured as the maximum.
|
||||
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||
ctx.Data["IsFileTooLarge"] = true
|
||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["NumLinesSet"] = true
|
||||
ctx.Data["NumLines"], err = blob.GetBlobLineCount()
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue