From c516ce206080960cf8d621eeff774dc38ec043e8 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 09:29:33 +0300 Subject: [PATCH 1/9] hotfix login --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 3bffdd6b..4c5e825d 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -11,7 +11,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { csrf := rand.string(30) ctx.set_cookie(name: 'csrf', value: csrf) - if app.is_logged_in(mut ctx) { + if !app.is_logged_in(mut ctx) { return ctx.not_found() } From 6818b7fb25d6ad333e8ce95241503975c658a043 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 11:51:07 +0300 Subject: [PATCH 2/9] main: Add veb.Middleware to App;make use of app.before_request --- src/gitly.v | 1 + src/main.v | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/gitly.v b/src/gitly.v index ece88086..214d97c3 100644 --- a/src/gitly.v +++ b/src/gitly.v @@ -23,6 +23,7 @@ const namechange_period = time.hour * 24 @[heap] pub struct App { veb.StaticHandler + veb.Middleware[Context] started_at i64 pub mut: db sqlite.DB diff --git a/src/main.v b/src/main.v index f38b405c..5af48d6e 100644 --- a/src/main.v +++ b/src/main.v @@ -12,6 +12,8 @@ fn main() { return } mut app := new_app()! + + app.use(handler: app.before_request) // vweb.run_at(new_app()!, http_port) veb.run_at[App, Context](mut app, port: http_port, family: .ip, timeout_in_seconds: 2) or { From bd260777c59e01a7c9495d4e20ef73000c3d9220 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 14:11:39 +0300 Subject: [PATCH 3/9] login: get logic back --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 4c5e825d..3bffdd6b 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -11,7 +11,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { csrf := rand.string(30) ctx.set_cookie(name: 'csrf', value: csrf) - if !app.is_logged_in(mut ctx) { + if app.is_logged_in(mut ctx) { return ctx.not_found() } From 8a0bbf4b941114a7f9fde0bca9ac614f417407bc Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 16:46:59 +0300 Subject: [PATCH 4/9] app: hotfix request timeout, add url var and dump it (don't ask me) --- src/gitly.v | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitly.v b/src/gitly.v index 214d97c3..02391037 100644 --- a/src/gitly.v +++ b/src/gitly.v @@ -132,6 +132,7 @@ pub fn (mut app App) init_server() { } pub fn (mut app App) before_request(mut ctx Context) { + url := ctx.req.url ctx.logged_in = app.is_logged_in(mut ctx) app.load_settings() @@ -142,6 +143,7 @@ pub fn (mut app App) before_request(mut ctx Context) { User{} } } + dump(url) } @['/'] From 1d4f83197b0a3d3372f2ba594461159660e701e5 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 17:25:41 +0300 Subject: [PATCH 5/9] fix logic if logged in --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 3bffdd6b..61179a50 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -12,7 +12,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { ctx.set_cookie(name: 'csrf', value: csrf) if app.is_logged_in(mut ctx) { - return ctx.not_found() + return ctx.redirect("/" + ctx.user.username) } return $veb.html() From 40651ab8715146407bc499f6f80005ab3c51b834 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Sat, 22 Mar 2025 08:56:59 +0300 Subject: [PATCH 6/9] (draft) debug with dump info --- src/repo_routes.v | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/repo_routes.v b/src/repo_routes.v index 77b55ca9..bb8e2bb2 100644 --- a/src/repo_routes.v +++ b/src/repo_routes.v @@ -151,8 +151,9 @@ pub fn (mut app App) handle_tree(mut ctx Context, username string, repo_name str } repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() } - + dump(repo) return app.tree(mut ctx, username, repo_name, repo.primary_branch, '') + // return app.tree(mut ctx, username, repo_name, repo.primary_branch, repo.git_dir) } @['/:username/:repo_name/tree/:branch_name'] @@ -258,6 +259,8 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str repo_id := new_repo2.id // primary_branch := git.get_repository_primary_branch(repo_path) primary_branch := new_repo2.git_repo.primary_branch() + dump(primary_branch) + dump(repo_id) app.update_repo_primary_branch(repo_id, primary_branch) or { ctx.error('There was an error while adding the repo') return app.new(mut ctx) @@ -279,6 +282,8 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str if !has_first_repo_activity { app.add_activity(ctx.user.id, 'first_repo') or { app.info(err.str()) } } + // dump(new_repo) + // dump(new_repo2) return ctx.redirect('/${ctx.user.username}/repos') } @@ -309,6 +314,9 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br // app.fetch_tags(repo) or { app.info(err.str()) } ctx.current_path = '/${path}' + // if ctx.current_path.starts_with('.') { + // ctx.current_path = ctx.current_path[1..] + // } if ctx.current_path.contains('/favicon.svg') { return ctx.not_found() } @@ -331,10 +339,12 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br up = ctx.req.url.all_before_last('/') } } + dump(up) if ctx.current_path.starts_with('/') { ctx.current_path = ctx.current_path[1..] } + // dump(ctx) mut items := app.find_repository_items(repo_id, branch_name, ctx.current_path) branch := app.find_repo_branch_by_name(repo.id, branch_name) From ab7e1a918659866d6fe655776099fa6c0159dacd Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Sat, 22 Mar 2025 12:04:18 +0300 Subject: [PATCH 7/9] fix git primary_branch. draft. TODO: clear debug stmts --- src/repo_routes.v | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/repo_routes.v b/src/repo_routes.v index bb8e2bb2..8439138f 100644 --- a/src/repo_routes.v +++ b/src/repo_routes.v @@ -237,6 +237,7 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str clone_url: valid_clone_url is_public: is_public } + dump(new_repo) if is_clone_url_empty { os.mkdir(new_repo.git_dir) or { panic(err) } new_repo.git('init --bare') @@ -258,9 +259,10 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str } repo_id := new_repo2.id // primary_branch := git.get_repository_primary_branch(repo_path) - primary_branch := new_repo2.git_repo.primary_branch() + // dump(new_repo2) + primary_branch := new_repo2.primary_branch dump(primary_branch) - dump(repo_id) + // dump(repo_id) app.update_repo_primary_branch(repo_id, primary_branch) or { ctx.error('There was an error while adding the repo') return app.new(mut ctx) From 7267f2cea3741ca5edb68155e81c2d88cf0d643f Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Sat, 22 Mar 2025 13:39:19 +0300 Subject: [PATCH 8/9] clean up: remove dumps --- src/repo_routes.v | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/repo_routes.v b/src/repo_routes.v index 8439138f..087766cd 100644 --- a/src/repo_routes.v +++ b/src/repo_routes.v @@ -151,7 +151,6 @@ pub fn (mut app App) handle_tree(mut ctx Context, username string, repo_name str } repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() } - dump(repo) return app.tree(mut ctx, username, repo_name, repo.primary_branch, '') // return app.tree(mut ctx, username, repo_name, repo.primary_branch, repo.git_dir) } @@ -237,7 +236,6 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str clone_url: valid_clone_url is_public: is_public } - dump(new_repo) if is_clone_url_empty { os.mkdir(new_repo.git_dir) or { panic(err) } new_repo.git('init --bare') @@ -259,10 +257,7 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str } repo_id := new_repo2.id // primary_branch := git.get_repository_primary_branch(repo_path) - // dump(new_repo2) primary_branch := new_repo2.primary_branch - dump(primary_branch) - // dump(repo_id) app.update_repo_primary_branch(repo_id, primary_branch) or { ctx.error('There was an error while adding the repo') return app.new(mut ctx) @@ -284,8 +279,6 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str if !has_first_repo_activity { app.add_activity(ctx.user.id, 'first_repo') or { app.info(err.str()) } } - // dump(new_repo) - // dump(new_repo2) return ctx.redirect('/${ctx.user.username}/repos') } @@ -341,12 +334,10 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br up = ctx.req.url.all_before_last('/') } } - dump(up) if ctx.current_path.starts_with('/') { ctx.current_path = ctx.current_path[1..] } - // dump(ctx) mut items := app.find_repository_items(repo_id, branch_name, ctx.current_path) branch := app.find_repo_branch_by_name(repo.id, branch_name) From f81e29772f7cbb7d726fb7daaa5ad9c3c609e572 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Sat, 22 Mar 2025 13:55:56 +0300 Subject: [PATCH 9/9] repo_routes: clean up --- src/repo_routes.v | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/repo_routes.v b/src/repo_routes.v index 087766cd..dca67006 100644 --- a/src/repo_routes.v +++ b/src/repo_routes.v @@ -151,8 +151,8 @@ pub fn (mut app App) handle_tree(mut ctx Context, username string, repo_name str } repo := app.find_repo_by_name_and_username(repo_name, username) or { return ctx.not_found() } + return app.tree(mut ctx, username, repo_name, repo.primary_branch, '') - // return app.tree(mut ctx, username, repo_name, repo.primary_branch, repo.git_dir) } @['/:username/:repo_name/tree/:branch_name'] @@ -309,9 +309,6 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br // app.fetch_tags(repo) or { app.info(err.str()) } ctx.current_path = '/${path}' - // if ctx.current_path.starts_with('.') { - // ctx.current_path = ctx.current_path[1..] - // } if ctx.current_path.contains('/favicon.svg') { return ctx.not_found() }