| 1 | module main |
| 2 | |
| 3 | import net.http |
| 4 | import veb |
| 5 | |
| 6 | const port = 8082 |
| 7 | |
| 8 | struct App { |
| 9 | } |
| 10 | |
| 11 | struct Context { |
| 12 | veb.Context |
| 13 | } |
| 14 | |
| 15 | fn uploaded_file_contents(fdata []http.FileData) []veb.RawHtml { |
| 16 | mut files := []veb.RawHtml{} |
| 17 | for data in fdata { |
| 18 | files << data.data.replace_each(['\n', '<br>', '\n\r', '<br>', '\t', ' ', ' ', ' ']) |
| 19 | } |
| 20 | return files |
| 21 | } |
| 22 | |
| 23 | fn main() { |
| 24 | mut app := &App{} |
| 25 | veb.run[App, Context](mut app, port) |
| 26 | } |
| 27 | |
| 28 | pub fn (mut app App) index() veb.Result { |
| 29 | return $veb.html() |
| 30 | } |
| 31 | |
| 32 | @['/upload'; post] |
| 33 | pub fn (mut app App) upload() veb.Result { |
| 34 | dump(ctx.form) |
| 35 | dump(ctx.files) |
| 36 | fdata := ctx.files['upfile'] |
| 37 | files := uploaded_file_contents(fdata) |
| 38 | return $veb.html() |
| 39 | } |
| 40 | |
| 41 | @['/submit'; post] |
| 42 | pub fn (mut app App) submit() veb.Result { |
| 43 | dump(ctx.form) |
| 44 | form_data := ctx.form.clone() |
| 45 | return $veb.html() |
| 46 | } |
| 47 | |