1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Make the max document length configurable

This commit is contained in:
Daniel Heath 2018-05-02 16:27:35 +10:00
parent a976007642
commit f86dc1095a
2 changed files with 22 additions and 16 deletions

View File

@ -57,6 +57,7 @@ func main() {
c.GlobalBool("allow-insecure-markup"), c.GlobalBool("allow-insecure-markup"),
c.GlobalBool("allow-file-uploads"), c.GlobalBool("allow-file-uploads"),
c.GlobalUint("max-upload-mb"), c.GlobalUint("max-upload-mb"),
c.GlobalUint("max-document-length"),
logger(c.GlobalBool("debug")), logger(c.GlobalBool("debug")),
) )
return nil return nil
@ -143,6 +144,11 @@ func main() {
Value: 2, Value: 2,
Usage: "Largest file upload (in mb) allowed", Usage: "Largest file upload (in mb) allowed",
}, },
cli.UintFlag{
Name: "max-document-length",
Value: 100000000,
Usage: "Largest wiki page (in characters) allowed",
},
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {

View File

@ -38,7 +38,7 @@ type Site struct {
Fileuploads bool Fileuploads bool
MaxUploadSize uint MaxUploadSize uint
Logger *lumber.ConsoleLogger Logger *lumber.ConsoleLogger
MaxDocumentSize uint // in runes; about a 10mb limit by default
saveMut sync.Mutex saveMut sync.Mutex
sitemapUpToDate bool // TODO this makes everything use a pointer sitemapUpToDate bool // TODO this makes everything use a pointer
} }
@ -69,6 +69,7 @@ func Serve(
allowInsecure bool, allowInsecure bool,
fileuploads bool, fileuploads bool,
maxUploadSize uint, maxUploadSize uint,
maxDocumentSize uint,
logger *lumber.ConsoleLogger, logger *lumber.ConsoleLogger,
) { ) {
var customCSS []byte var customCSS []byte
@ -84,20 +85,19 @@ func Serve(
} }
router := Site{ router := Site{
filepathToData, PathToData: filepathToData,
customCSS, Css: customCSS,
defaultPage, DefaultPage: defaultPage,
defaultPassword, DefaultPassword: defaultPassword,
debounce, Debounce: debounce,
diary, Diary: diary,
sessions.NewCookieStore([]byte(secret)), SessionStore: sessions.NewCookieStore([]byte(secret)),
secretCode, SecretCode: secretCode,
allowInsecure, AllowInsecure: allowInsecure,
fileuploads, Fileuploads: fileuploads,
maxUploadSize, MaxUploadSize: maxUploadSize,
logger, Logger: logger,
sync.Mutex{}, MaxDocumentSize: maxDocumentSize,
false,
}.Router() }.Router()
if TLS { if TLS {
@ -586,7 +586,7 @@ func (s *Site) handlePageUpdate(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong JSON"}) c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong JSON"})
return return
} }
if len(json.NewText) > 100000000 { if uint(len(json.NewText)) > s.MaxDocumentSize {
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Too much"}) c.JSON(http.StatusOK, gin.H{"success": false, "message": "Too much"})
return return
} }