| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | |
| 5 | const port = 8082 |
| 6 | |
| 7 | pub struct Context { |
| 8 | veb.Context |
| 9 | } |
| 10 | |
| 11 | pub struct App { |
| 12 | } |
| 13 | |
| 14 | fn main() { |
| 15 | mut app := &App{} |
| 16 | veb.run[App, Context](mut app, port) |
| 17 | } |
| 18 | |
| 19 | pub fn (mut app App) index() veb.Result { |
| 20 | return $veb.html() |
| 21 | } |
| 22 | |
| 23 | @['/upload'; post] |
| 24 | pub fn (mut app App) upload(mut ctx Context) veb.Result { |
| 25 | fdata := ctx.files['upfile'] |
| 26 | |
| 27 | data_rows := fdata[0].data.split('\n') |
| 28 | |
| 29 | mut output_data := '' |
| 30 | |
| 31 | for elem in data_rows { |
| 32 | delim_row := elem.split('\t') |
| 33 | output_data += '${delim_row[0]}\t${delim_row[1]}\t${delim_row[0].int() + delim_row[1].int()}\n' |
| 34 | } |
| 35 | |
| 36 | output_data = output_data.all_before_last('\n') |
| 37 | |
| 38 | println(output_data) |
| 39 | |
| 40 | ctx.set_header(.content_disposition, 'attachment; filename=results.txt') |
| 41 | ctx.send_response_to_client('application/octet-stream', output_data) |
| 42 | |
| 43 | return $veb.html() |
| 44 | } |
| 45 | |