Increased limit to 100k lines, warning message is now on bottom and linked to raw

This commit is contained in:
Henrique Pimentel 2024-04-10 21:49:24 +01:00 committed by Henrique Pimentel
parent 8b8c64f862
commit fce76ef193
3 changed files with 11 additions and 13 deletions

View File

@ -1335,7 +1335,7 @@ LEVEL = Info
;MAX_FILE_SIZE = 524288
;;
;; Maximum allowed rows to render CSV files. (Set to 0 for no limit)
;MAX_ROWS = 5000
;MAX_ROWS = 100000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -39,8 +39,8 @@ func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
{Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)},
{Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
{Element: "td", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(`tw-flex tw-justify-center tw-items-center`)},
{Element: "a", AllowAttr: "href", Regexp: regexp.MustCompile(`\?display=source`)},
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(`tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14`)},
{Element: "a", AllowAttr: "href", Regexp: regexp.MustCompile(``)},
}
}
@ -81,7 +81,6 @@ func writeField(w io.Writer, element, class, field string) error {
// Render implements markup.Renderer
func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
tmpBlock := bufio.NewWriter(output)
warnBlock := bufio.NewWriter(tmpBlock)
maxSize := setting.UI.CSV.MaxFileSize
maxRows := setting.UI.CSV.MaxRows
@ -129,23 +128,22 @@ func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.W
row++
}
if _, err = tmpBlock.WriteString("</table>"); err != nil {
return err
}
// Check if maxRows or maxSize is reached, and if true, warn.
if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) {
locale := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
// Construct the HTML string
warn := `<div class="tw-flex tw-justify-center tw-items-center"><div>` + locale.TrString("repo.file_too_large") + ` <a class="source" href="?display=source">` + locale.TrString("repo.file_view_source") + `</a></div></div>`
warn := `<div class="tw-flex tw-justify-center tw-items-center tw-py-4 tw-text-14"><div>` + locale.TrString("repo.file_too_large") + ` <a class="source" href="` + ctx.Links.RawLink() + `/` + ctx.RelativePath + `">` + locale.TrString("repo.file_view_raw") + `</a></div></div>`
// Write the HTML string to the output
if _, err := warnBlock.WriteString(warn); err != nil {
return err
}
if err = warnBlock.Flush(); err != nil {
if _, err := tmpBlock.WriteString(warn); err != nil {
return err
}
}
if _, err = tmpBlock.WriteString("</table>"); err != nil {
return err
}
return tmpBlock.Flush()
}

View File

@ -112,7 +112,7 @@ var UI = struct {
MaxRows int
}{
MaxFileSize: 524288,
MaxRows: 5000,
MaxRows: 100000,
},
Admin: struct {
UserPagingNum int