mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-07 16:31:01 +01:00
Do not read file if it is too large
This commit is contained in:
parent
f53085691e
commit
7684e1720d
@ -164,14 +164,18 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||||||
// Only some file types are editable online as text.
|
// Only some file types are editable online as text.
|
||||||
ctx.Data["IsFileText"] = typesniffer.DetectContentType(buf).IsRepresentableAsText()
|
ctx.Data["IsFileText"] = typesniffer.DetectContentType(buf).IsRepresentableAsText()
|
||||||
|
|
||||||
d, _ := io.ReadAll(dataRc)
|
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||||
|
ctx.Data["IsFileTooLarge"] = true
|
||||||
buf = append(buf, d...)
|
|
||||||
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
|
|
||||||
log.Error("ToUTF8: %v", err)
|
|
||||||
ctx.Data["FileContent"] = string(buf)
|
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["FileContent"] = content
|
d, _ := io.ReadAll(dataRc)
|
||||||
|
|
||||||
|
buf = append(buf, d...)
|
||||||
|
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
|
||||||
|
log.Error("ToUTF8: %v", err)
|
||||||
|
ctx.Data["FileContent"] = string(buf)
|
||||||
|
} else {
|
||||||
|
ctx.Data["FileContent"] = content
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Append filename from query, or empty string to allow username the new file.
|
// Append filename from query, or empty string to allow username the new file.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user