package main
import "net/http"
func (s *server) routes(mux *http.ServeMux) {
// Public — no login required.
mux.HandleFunc("GET /{$}", s.handleLanding)
mux.HandleFunc("GET /r/{repo...}", s.handleRepoView)
mux.HandleFunc("GET /repo-blob/{repo...}", s.handleRepoBlob)
mux.HandleFunc("GET /repo-archive/{repo...}", s.handleRepoArchive)
mux.HandleFunc("GET /repo-commits/{repo...}", s.handleRepoCommits)
mux.HandleFunc("GET /repo-commit/{repo...}", s.handleRepoCommitDetail)
mux.HandleFunc("GET /repo-mrs/{repo...}", s.handleMRList)
mux.HandleFunc("GET /repo-mr/{repo...}", s.handleMRDetail)
mux.HandleFunc("GET /login", s.handleLoginForm)
mux.HandleFunc("POST /login", s.handleLogin)
mux.HandleFunc("POST /logout", s.handleLogout)
mux.HandleFunc("GET /changelog", s.handleChangelog)
mux.HandleFunc("GET /search", s.handleSearch)
mux.HandleFunc("GET /security", s.handleSecurity)
mux.HandleFunc("GET /explore", s.handleExplore)
mux.HandleFunc("GET /u/{username}", s.handleUserProfile)
mux.HandleFunc("GET /lang/{lang}", s.handleSetLang)
mux.HandleFunc("GET /theme/{theme}", s.handleSetTheme)
// Anonymous read-only git-over-HTTPS for public repos (clone/fetch
// only — no receive-pack). Deliberately at the site root, not under a
// prefix, so clone URLs look like "https://domain/owner/repo.git" —
// see the long comment in handlers_git_http.go for why that's safe.
mux.HandleFunc("GET /{gitpath...}", s.handleGitInfoRefs)
mux.HandleFunc("POST /{gitpath...}", s.handleGitUploadPack)
// Self-service — any logged-in user, scoped to their own stuff via
// CheckAccess inside the handlers.
// Repo sub-actions get their own path prefixes rather than a suffix
// after {repo...} — net/http's mux requires a "..." wildcard to be the
// last segment of a pattern, so "/r/{repo...}/settings" isn't legal.
mux.HandleFunc("GET /dashboard", s.requireLogin(s.handleDashboard))
mux.HandleFunc("POST /repos", s.requireLogin(s.handleCreateRepo))
mux.HandleFunc("POST /repos/import", s.requireLogin(s.handleImportRepo))
mux.HandleFunc("GET /repo-settings/{repo...}", s.requireLogin(s.handleRepoSettingsForm))
mux.HandleFunc("POST /repo-settings/{repo...}", s.requireLogin(s.handleRepoSettingsSave))
mux.HandleFunc("POST /repo-grant/{repo...}", s.requireLogin(s.handleCollabGrant))
mux.HandleFunc("POST /repo-revoke/{repo...}", s.requireLogin(s.handleCollabRevoke))
mux.HandleFunc("POST /repo-delete/{repo...}", s.requireLogin(s.handleRepoDelete))
mux.HandleFunc("GET /repo-mr-new/{repo...}", s.requireLogin(s.handleMRNewForm))
mux.HandleFunc("POST /repo-mr-new/{repo...}", s.requireLogin(s.handleMRCreate))
mux.HandleFunc("POST /repo-mr-merge/{repo...}", s.requireLogin(s.handleMRMerge))
mux.HandleFunc("POST /repo-mr-close/{repo...}", s.requireLogin(s.handleMRClose))
mux.HandleFunc("POST /repo-mr-comment/{repo...}", s.requireLogin(s.handleMRComment))
mux.HandleFunc("GET /settings", s.requireLogin(s.handleSettings))
mux.HandleFunc("POST /settings/profile", s.requireLogin(s.handleUpdateProfile))
mux.HandleFunc("POST /settings/keys/add", s.requireLogin(s.handleAddOwnKey))
mux.HandleFunc("POST /settings/keys/remove", s.requireLogin(s.handleRemoveOwnKey))
mux.HandleFunc("POST /settings/password", s.requireLogin(s.handleChangePassword))
mux.HandleFunc("POST /pins", s.requireLogin(s.handleAddPin))
mux.HandleFunc("POST /pins/remove", s.requireLogin(s.handleRemovePin))
mux.HandleFunc("GET /notifications", s.requireLogin(s.handleNotifications))
mux.HandleFunc("POST /notifications/accept", s.requireLogin(s.handleAcceptNotification))
mux.HandleFunc("POST /notifications/dismiss", s.requireLogin(s.handleDismissNotification))
// Admin — instance-admin accounts only.
mux.HandleFunc("GET /admin", s.requireAdmin(s.handleAdminIndex))
mux.HandleFunc("GET /admin/users", s.requireAdmin(s.handleAdminUsersList))
mux.HandleFunc("POST /admin/users", s.requireAdmin(s.handleAdminUsersCreate))
mux.HandleFunc("POST /admin/users/delete", s.requireAdmin(s.handleAdminUsersDelete))
mux.HandleFunc("POST /admin/users/set-admin", s.requireAdmin(s.handleAdminUsersSetAdmin))
mux.HandleFunc("GET /admin/repos", s.requireAdmin(s.handleAdminRepos))
mux.HandleFunc("GET /admin/trust", s.requireAdmin(s.handleAdminTrustList))
mux.HandleFunc("POST /admin/trust/approve", s.requireAdmin(s.handleAdminTrustApprove))
mux.HandleFunc("GET /admin/audit", s.requireAdmin(s.handleAdminAudit))
}