From d486fd9322a3fe1cf514d9fcc80d8996d9f49979 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 10 Feb 2025 13:47:32 +0800 Subject: [PATCH] *: project -> category --- handle_category_index.go | 6 +++--- handle_repo_index.go | 6 +++--- handle_repo_tree.go | 6 +++--- main.go | 6 +++--- templates/repo_index.html | 2 +- templates/repo_tree_dir.html | 2 +- templates/repo_tree_file.html | 2 +- diff --git a/handle_category_index.go b/handle_category_index.go index 407d0e735717744187820759196958ebc10dbdf7..953557ac6c98edf73bbab9226ad9328cf81a6a6a 100644 --- a/handle_category_index.go +++ b/handle_category_index.go @@ -9,9 +9,9 @@ ) func handle_category_index(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) - project_name := r.PathValue("project_name") - data["category_name"] = project_name - entries, err := os.ReadDir(filepath.Join(config.Git.Root, project_name)) + category_name := r.PathValue("category_name") + data["category_name"] = category_name + entries, err := os.ReadDir(filepath.Join(config.Git.Root, category_name)) if err != nil { _, _ = w.Write([]byte("Error listing repos: " + err.Error())) return diff --git a/handle_repo_index.go b/handle_repo_index.go index 89aeba67ce410eb2d4b0e28ce34743de55adf96f..44ba4817653c85c7228eb7bc03331326485da7dd 100644 --- a/handle_repo_index.go +++ b/handle_repo_index.go @@ -15,9 +15,9 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) // TODO: Sanitize path values - project_name, repo_name := r.PathValue("project_name"), r.PathValue("repo_name") - data["project_name"], data["repo_name"] = project_name, repo_name - repo, err := git.PlainOpen(filepath.Join(config.Git.Root, project_name, repo_name+".git")) + category_name, repo_name := r.PathValue("category_name"), r.PathValue("repo_name") + data["category_name"], data["repo_name"] = category_name, repo_name + repo, err := git.PlainOpen(filepath.Join(config.Git.Root, category_name, repo_name+".git")) if err != nil { _, _ = w.Write([]byte("Error opening repo: " + err.Error())) return diff --git a/handle_repo_tree.go b/handle_repo_tree.go index 8b8630dc3dd378a8d543b782dfa04964ea127475..cc792020a1b9ea0df033346e05f6e1c77e149cd7 100644 --- a/handle_repo_tree.go +++ b/handle_repo_tree.go @@ -16,9 +16,9 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) // TODO: Sanitize path values - project_name, repo_name, path_spec := r.PathValue("project_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") - data["project_name"], data["repo_name"], data["path_spec"] = project_name, repo_name, path_spec - repo, err := git.PlainOpen(filepath.Join(config.Git.Root, project_name, repo_name+".git")) + category_name, repo_name, path_spec := r.PathValue("category_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") + data["category_name"], data["repo_name"], data["path_spec"] = category_name, repo_name, path_spec + repo, err := git.PlainOpen(filepath.Join(config.Git.Root, category_name, repo_name+".git")) if err != nil { _, _ = w.Write([]byte("Error opening repo: " + err.Error())) return diff --git a/main.go b/main.go index b144b5286700820fcc949178db5ee0172cf93ab2..18733c453d2c250785008d7c80ff5a35271288bb 100644 --- a/main.go +++ b/main.go @@ -32,9 +32,9 @@ clog.Fatal(1, "Serving static: "+err.Error()) } http.HandleFunc("/{$}", handle_index) - http.HandleFunc("/{project_name}/{$}", handle_category_index) - http.HandleFunc("/{project_name}/repos/{repo_name}/{$}", handle_repo_index) - http.HandleFunc("/{project_name}/repos/{repo_name}/tree/{ref}/{rest...}", handle_repo_tree) + http.HandleFunc("/{category_name}/{$}", handle_category_index) + http.HandleFunc("/{category_name}/repos/{repo_name}/{$}", handle_repo_index) + http.HandleFunc("/{category_name}/repos/{repo_name}/tree/{ref}/{rest...}", handle_repo_tree) listener, err := net.Listen(config.HTTP.Net, config.HTTP.Addr) if err != nil { diff --git a/templates/repo_index.html b/templates/repo_index.html index 13ac023e4395c9a5c78aa7670712e5d13f55304e..dc8d672d9a18d7332e5cf84be67a8456fd3675fd 100644 --- a/templates/repo_index.html +++ b/templates/repo_index.html @@ -3,7 +3,7 @@ -{{ .project_name }}/repos/{{ .repo_name }} +{{ .category_name }}/repos/{{ .repo_name }}
diff --git a/templates/repo_tree_dir.html b/templates/repo_tree_dir.html index 93fa830b1b59860b816de6e9d2c7a0947295a3c0..aa96b5d01a80c0e3eed3870457253021c7495687 100644 --- a/templates/repo_tree_dir.html +++ b/templates/repo_tree_dir.html @@ -3,7 +3,7 @@ -{{ .project_name }}/repos/{{ .repo_name }}/{{ .path_spec }} +{{ .category_name }}/repos/{{ .repo_name }}/{{ .path_spec }}
diff --git a/templates/repo_tree_file.html b/templates/repo_tree_file.html index 7cf335a926cb2a26086dac406c67b09e2290cbf7..72bf42b3c31457d9f70aabeff49a76ec6c5fe5b3 100644 --- a/templates/repo_tree_file.html +++ b/templates/repo_tree_file.html @@ -3,7 +3,7 @@ -{{ .project_name }}/repos/{{ .repo_name }}/{{ .path_spec }} +{{ .category_name }}/repos/{{ .repo_name }}/{{ .path_spec }}

-- 2.48.1