| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | import os |
| 5 | |
| 6 | @['/:username/:repo_name/tag/:tag/:format'] |
| 7 | pub fn (mut app App) handle_download_tag_archive(username string, repo_name string, tag string, format string) veb.Result { |
| 8 | // access checking will be implemented in another module |
| 9 | user := app.get_user_by_username(username) or { return ctx.not_found() } |
| 10 | repo := app.find_repo_by_name_and_user_id(repo_name, user.id) or { return ctx.not_found() } |
| 11 | |
| 12 | archive_abs_path := os.abs_path(app.config.archive_path) |
| 13 | snapshot_format := if format == 'zip' { 'zip' } else { 'tar.gz' } |
| 14 | snapshot_name := '${username}_${repo_name}_${tag}.${snapshot_format}' |
| 15 | archive_path := '${archive_abs_path}/${snapshot_name}' |
| 16 | |
| 17 | if format == 'zip' { |
| 18 | repo.archive_tag(tag, archive_path, .zip) |
| 19 | } else { |
| 20 | repo.archive_tag(tag, archive_path, .tar) |
| 21 | } |
| 22 | |
| 23 | archive_content := os.read_file(archive_path) or { return ctx.not_found() } |
| 24 | |
| 25 | return app.send_file(mut ctx, snapshot_name, archive_content) |
| 26 | } |
| 27 | |