@@ -19,7 +19,7 @@ from parseBody import parseMPFD
1919
2020const
2121 name = " TW5 server"
22- version = " 1.2.0 "
22+ version = " 1.2.2 "
2323 style = staticRead (" style.css" )
2424 temp = staticRead (" template.html" )
2525 js = staticRead (" main.js" )
@@ -33,6 +33,7 @@ tw5server -a:localhost -p:8000 -d:dir -b:backup
3333-d directory to servering, default `current dir`
3434-b backup directory name, default `backup`
3535-l show log message
36+ -m max size of uploaded file (MB), default 100
3637
3738Backups auto-clean strategy:
3839Keep all backups in current month, keep only the newest one for previous months.
@@ -157,13 +158,13 @@ proc savePost(req: Request, path, url_path: string, log: bool): NimHttpResponse
157158 file = body[" file" ]
158159 filename = file.fields[" filename" ]
159160 file_body = file.body
160- override = body.getOrDefault (" override " ).body
161+ overwrite = body.getOrDefault (" overwrite " ).body
161162
162163 var
163164 rsp_content = " "
164165 code = Http400
165166
166- if fileExists (path / filename) and " yes" != override :
167+ if fileExists (path / filename) and " yes" != overwrite :
167168 let
168169 (_, base, ext) = filename.splitFile ()
169170 newName = base & " -" & time_now () & ext
@@ -185,8 +186,8 @@ proc savePost(req: Request, path, url_path: string, log: bool): NimHttpResponse
185186 logmsg (msg, log)
186187 return (code: code, content: rsp_content, headers: {" status" : " ok" }.newHttpHeaders ())
187188
188- proc serve (settings: NimHttpSettings , backup: string , log: bool ) =
189- var server = newAsyncHttpServer ()
189+ proc serve (settings: NimHttpSettings , backup: string , log: bool , maxbody: int ) =
190+ var server = newAsyncHttpServer (maxBody = maxbody )
190191 proc handleHttpRequest (req: Request ): Future [void ] {.async .} =
191192 let
192193 url_path = req.url.path.replace (" %20" , " " ).decodeUrl ()
273274 backup = " backup"
274275 title = " TW5 server"
275276 log = false
277+ maxbody = 100 # max body length (MB)
276278
277279for kind, key, val in parseopt.getopt ():
278280 case kind
@@ -293,6 +295,8 @@ for kind, key, val in parseopt.getopt():
293295 backup = val
294296 of " l" , " log" :
295297 log = true
298+ of " m" , " max" :
299+ maxbody = parseInt (val)
296300 else :
297301 assert (false )
298302
@@ -329,5 +333,5 @@ proc handleCtrlC() {.noconv.} =
329333
330334setControlCHook (handleCtrlC)
331335
332- serve (settings, backup, log)
336+ serve (settings, backup, log, maxbody = maxbody * 1024 * 1024 )
333337runForever ()
0 commit comments