@@ -19,7 +19,7 @@ from parseBody import parseMPFD
19
19
20
20
const
21
21
name = " TW5 server"
22
- version = " 1.2.0 "
22
+ version = " 1.2.2 "
23
23
style = staticRead (" style.css" )
24
24
temp = staticRead (" template.html" )
25
25
js = staticRead (" main.js" )
@@ -33,6 +33,7 @@ tw5server -a:localhost -p:8000 -d:dir -b:backup
33
33
-d directory to servering, default `current dir`
34
34
-b backup directory name, default `backup`
35
35
-l show log message
36
+ -m max size of uploaded file (MB), default 100
36
37
37
38
Backups auto-clean strategy:
38
39
Keep 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
157
158
file = body[" file" ]
158
159
filename = file.fields[" filename" ]
159
160
file_body = file.body
160
- override = body.getOrDefault (" override " ).body
161
+ overwrite = body.getOrDefault (" overwrite " ).body
161
162
162
163
var
163
164
rsp_content = " "
164
165
code = Http400
165
166
166
- if fileExists (path / filename) and " yes" != override :
167
+ if fileExists (path / filename) and " yes" != overwrite :
167
168
let
168
169
(_, base, ext) = filename.splitFile ()
169
170
newName = base & " -" & time_now () & ext
@@ -185,8 +186,8 @@ proc savePost(req: Request, path, url_path: string, log: bool): NimHttpResponse
185
186
logmsg (msg, log)
186
187
return (code: code, content: rsp_content, headers: {" status" : " ok" }.newHttpHeaders ())
187
188
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 )
190
191
proc handleHttpRequest (req: Request ): Future [void ] {.async .} =
191
192
let
192
193
url_path = req.url.path.replace (" %20" , " " ).decodeUrl ()
273
274
backup = " backup"
274
275
title = " TW5 server"
275
276
log = false
277
+ maxbody = 100 # max body length (MB)
276
278
277
279
for kind, key, val in parseopt.getopt ():
278
280
case kind
@@ -293,6 +295,8 @@ for kind, key, val in parseopt.getopt():
293
295
backup = val
294
296
of " l" , " log" :
295
297
log = true
298
+ of " m" , " max" :
299
+ maxbody = parseInt (val)
296
300
else :
297
301
assert (false )
298
302
@@ -329,5 +333,5 @@ proc handleCtrlC() {.noconv.} =
329
333
330
334
setControlCHook (handleCtrlC)
331
335
332
- serve (settings, backup, log)
336
+ serve (settings, backup, log, maxbody = maxbody * 1024 * 1024 )
333
337
runForever ()
0 commit comments