linstrom/server/apiLinstrom.go
mStar 1bb6cd8a70 bleh
More API stuff. Lots of bleh. Really boring

Also need to figure out a somewhat generic way for "requires ownership"
permission and then a combinator for permissions
2024-11-04 16:25:39 +01:00

94 lines
4.1 KiB
Go

package server
import "net/http"
func setupLinstromApiRouter() http.Handler {
router := http.NewServeMux()
router.Handle("/v1/", http.StripPrefix("/v1", setupLinstromApiV1Router()))
return router
}
func setupLinstromApiV1Router() http.Handler {
router := http.NewServeMux()
// Notes
router.HandleFunc("GET /notes/{noteId}", linstromGetNote)
router.HandleFunc("POST /notes", linstromNewNote)
router.HandleFunc("PATCH /notes/{noteId}", linstromUpdateNote)
router.HandleFunc("DELETE /notes/{noteId}", linstromDeleteNote)
// Reactions
router.HandleFunc("GET /notes/{noteId}/reactions", linstromGetReactions)
router.HandleFunc("POST /notes/{noteId}/reactions", linstromAddReaction)
router.HandleFunc("PATCH /notes/{noteId}/reactions", linstromUpdateReaction)
router.HandleFunc("DELETE /notes/{noteId}/reactions", linstromDeleteReaction)
// Boosts
router.HandleFunc("GET /notes/{noteId}/boosts", linstromGetBoosts)
router.HandleFunc("POST /notes/{noteId}/boosts", linstromAddBoost)
router.HandleFunc("DELETE /notes/{noteId}/boosts", linstromRemoveBoost)
// Quotes
router.HandleFunc("GET /notes/{noteId}/quotes", linstromGetQuotes)
router.HandleFunc("POST /notes/{noteId}/quotes", linstromAddQuote)
// Pinning
router.HandleFunc("POST /notes/{noteId}/pin", linstromPinNote)
router.HandleFunc("DELETE /notes/{noteId}/pin", linstromUnpinNote)
// Reports
router.HandleFunc("POST /notes/{noteId}/report", linstromReportNote)
router.HandleFunc("DELETE /notes/{noteId}/report", linstromRetractReportNote)
// Admin
router.HandleFunc("POST /notes/{noteId}/admin/cw", linstromForceCWNote)
// Accounts
// Creating a new account happens either during fetch of a remote one or during registration with a passkey
router.HandleFunc("GET /accounts/{accountId}", linstromGetAccount)
// Technically also requires authenticated account to also be owner or correct admin perms,
// but that's annoying to handle in a general sense. So leaving that to the function
router.HandleFunc(
"PATCH /accounts/{accountId}",
requireValidSessionMiddleware(linstromUpdateAccount),
)
// Technically also requires authenticated account to also be owner or correct admin perms,
// but that's annoying to handle in a general sense. So leaving that to the function
router.HandleFunc(
"DELETE /accounts/{accountId}",
requireValidSessionMiddleware(linstromDeleteAccount),
)
// Follow
router.HandleFunc("GET /accounts/{accountId}/follow", linstromIsFollowingAccount)
router.HandleFunc("POST /accounts/{accountId}/follow", linstromFollowAccount)
router.HandleFunc("DELETE /accounts/{accountId}/follow", linstromUnfollowAccount)
// Block
router.HandleFunc("GET /accounts/{accountId}/block", linstromIsBlockingAccount)
router.HandleFunc("POST /accounts/{accountId}/block", linstromBlockAccount)
router.HandleFunc("DELETE /accounts/{accountId}/block", linstromUnblockAccount)
// Mute
router.HandleFunc("GET /accounts/{accountId}/mute", linstromIsMutedAccount)
router.HandleFunc("POST /accounts/{accountId}/mute", linstromMuteAccount)
router.HandleFunc("DELETE /accounts/{accountId}/mute", linstromUnmuteAccount)
// Report
router.HandleFunc("POST /accounts/{accountId}/reports", linstromReportAccount)
router.HandleFunc("DELETE /accounts/{accountId}/reports", linstromRetractReportAccount)
// Admin
router.HandleFunc("POST /accounts/{accountId}/admin/roles", linstromAdminAddRoleAccount)
router.HandleFunc(
"DELETE /accounts/{accountId}/admin/roles/{roleName}",
linstromAdminRemoveRoleAccount,
)
router.HandleFunc("POST /accounts/{accountId}/admin/warn", linstromAdminWarnAccount)
// Roles
router.HandleFunc("GET /roles/{roleId}", linstromGetRole)
router.HandleFunc("POST /roles", linstromCreateRole)
router.HandleFunc("PATCH /roles/{roleId}", linstromUpdateRole)
router.HandleFunc("DELETE /roles/{roleId}", linstromDeleteRole)
// Media metadata
router.HandleFunc("GET /media/{mediaId}", linstromGetMediaMetadata)
router.HandleFunc("POST /media", linstromNewMediaMetadata)
router.HandleFunc("PATCH /media/{mediaId}", linstromUpdateMediaMetadata)
router.HandleFunc("DELETE /media/{mediaId}", linstromDeleteMediaMetadata)
// Event streams
router.HandleFunc("/streams", linstromEventStream)
return router
}