| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // handleControlRoute dispatches endpoints that mutate or stream management |
| 9 | // state. Keeping these together makes their authentication and HTTP method |
| 10 | // requirements visible without mixing them into page and asset routing. |
| 11 | func (a *App) handleControlRoute(writer http.ResponseWriter, request *http.Request) bool { |
| 12 | switch { |
| 13 | case request.Method == http.MethodPost && request.URL.Path == "/manage/rpc" : |
| 14 | a.rpc(writer, request) |
| 15 | case request.Method == http.MethodGet && request.URL.Path == "/api/join-policy" : |
| 16 | a.joinPolicy(writer) |
| 17 | case request.Method == http.MethodPost && request.URL.Path == "/api/invites/claim" : |
| 18 | a.claimInvite(writer, request) |
| 19 | case request.Method == http.MethodGet && request.URL.Path == "/manage/jobs/status" : |
| 20 | a.jobStatus(writer, request) |
| 21 | default: |
| 22 | return false |
| 23 | } |
| 24 | return true |
| 25 | } |
| 26 | |
| 27 | // handleBrowseRoute dispatches authenticated browse pages and compatibility |
| 28 | // redirects. API and asset endpoints remain in the public route group. |
| 29 | func (a *App) handleBrowseRoute(writer http.ResponseWriter, request *http.Request) bool { |
| 30 | if request.URL.Path == "/manage/status" || request.URL.Path == "/tools" { |
| 31 | http.Redirect(writer, request, requestPrefix(request)+"/manage/health" , http.StatusMovedPermanently) |
| 32 | return true |
| 33 | } |
| 34 | if request.Method == http.MethodGet && isBrowsePath(request.URL.Path) { |
| 35 | a.browse(writer, request) |
| 36 | return true |
| 37 | } |
| 38 | if request.URL.Path == "/share" { |
| 39 | http.Redirect(writer, request, requestPrefix(request)+"/files" , http.StatusSeeOther) |
| 40 | return true |
| 41 | } |
| 42 | return false |
| 43 | } |
| 44 | |
| 45 | func isBrowsePath(path string) bool { |
| 46 | return path == "/repos" || path == "/repo" || path == "/files" || path == "/file" || |
| 47 | path == "/approvals" || path == "/profile" || path == "/wiki" || |
| 48 | strings.HasPrefix(path, "/wiki/" ) || path == "/manage/health" || roomRoute(path).tab != "" |
| 49 | } |
| 50 | |
| 51 | // handleWebMCPRoute dispatches the browser-facing query bridge separately |
| 52 | // from HTML pages so its contract can evolve independently. |
| 53 | func (a *App) handleWebMCPRoute(writer http.ResponseWriter, request *http.Request) bool { |
| 54 | if request.Method != http.MethodGet { |
| 55 | return false |
| 56 | } |
| 57 | switch request.URL.Path { |
| 58 | case "/webmcp.js" : |
| 59 | a.webMCP(writer, request) |
| 60 | case "/webmcp/query" : |
| 61 | a.webMCPQuery(writer, request) |
| 62 | default: |
| 63 | return false |
| 64 | } |
| 65 | return true |
| 66 | } |