Skip to content

Commit

Permalink
Increased limit to 100k lines, warning message is now on bottom and l…
Browse files Browse the repository at this point in the history
…inked to raw
  • Loading branch information
HenriquerPimentel committed May 8, 2024
1 parent 2cebd53 commit 88accfd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
20 changes: 9 additions & 11 deletions modules/markup/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(``)},
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion modules/setting/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var UI = struct {
MaxRows int
}{
MaxFileSize: 524288,
MaxRows: 5000,
MaxRows: 100000,
},
Admin: struct {
UserPagingNum int
Expand Down

0 comments on commit 88accfd

Please sign in to comment.