Ver código fonte

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

undefined
Henrique Pimentel 1 mês atrás
pai
commit
fce76ef193
3 arquivos alterados com 11 adições e 13 exclusões
  1. 1
    1
      custom/conf/app.example.ini
  2. 9
    11
      modules/markup/csv/csv.go
  3. 1
    1
      modules/setting/ui.go

+ 1
- 1
custom/conf/app.example.ini Ver arquivo

;MAX_FILE_SIZE = 524288 ;MAX_FILE_SIZE = 524288
;; ;;
;; Maximum allowed rows to render CSV files. (Set to 0 for no limit) ;; Maximum allowed rows to render CSV files. (Set to 0 for no limit)
;MAX_ROWS = 5000
;MAX_ROWS = 100000


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

+ 9
- 11
modules/markup/csv/csv.go Ver arquivo

{Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)}, {Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)},
{Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)}, {Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
{Element: "td", 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(``)},
} }
} }


// Render implements markup.Renderer // Render implements markup.Renderer
func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error { func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
tmpBlock := bufio.NewWriter(output) tmpBlock := bufio.NewWriter(output)
warnBlock := bufio.NewWriter(tmpBlock)
maxSize := setting.UI.CSV.MaxFileSize maxSize := setting.UI.CSV.MaxFileSize
maxRows := setting.UI.CSV.MaxRows maxRows := setting.UI.CSV.MaxRows


row++ row++
} }


if _, err = tmpBlock.WriteString("</table>"); err != nil {
return err
}

// Check if maxRows or maxSize is reached, and if true, warn. // Check if maxRows or maxSize is reached, and if true, warn.
if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) { if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) {
locale := ctx.Ctx.Value(translation.ContextKey).(translation.Locale) locale := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)


// Construct the HTML string // 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 // 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 return err
} }
} }
if _, err = tmpBlock.WriteString("</table>"); err != nil {
return err
}

return tmpBlock.Flush() return tmpBlock.Flush()
} }

+ 1
- 1
modules/setting/ui.go Ver arquivo

MaxRows int MaxRows int
}{ }{
MaxFileSize: 524288, MaxFileSize: 524288,
MaxRows: 5000,
MaxRows: 100000,
}, },
Admin: struct { Admin: struct {
UserPagingNum int UserPagingNum int

Carregando…
Cancelar
Salvar