add a couple post endpoints + /timelines/home
This commit is contained in:
parent
dd72a1f4c1
commit
9f052dc9ef
24 changed files with 462 additions and 32 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"git.sleepycat.moe/sam/mercury/web/api"
|
||||
"git.sleepycat.moe/sam/mercury/web/api/accounts"
|
||||
"git.sleepycat.moe/sam/mercury/web/api/blogs"
|
||||
"git.sleepycat.moe/sam/mercury/web/api/posts"
|
||||
"git.sleepycat.moe/sam/mercury/web/api/timelines"
|
||||
"git.sleepycat.moe/sam/mercury/web/app"
|
||||
"git.sleepycat.moe/sam/mercury/web/auth"
|
||||
"git.sleepycat.moe/sam/mercury/web/frontend"
|
||||
|
@ -22,6 +24,37 @@ func Routes(app *app.App) {
|
|||
r.Post("/sign_up", auth.PostSignup)
|
||||
})
|
||||
|
||||
// APIv1 handlers
|
||||
app.Router.Route("/api/v1", func(r chi.Router) {
|
||||
unauthedAccess := !app.AppConfig.Security.RestrictAPI
|
||||
unauthedTimelineAccess := app.AppConfig.Security.PublicTimelines && !app.AppConfig.Security.RestrictAPI
|
||||
_ = unauthedTimelineAccess
|
||||
|
||||
// account handlers
|
||||
accounts := accounts.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopeAccountsRead, unauthedAccess)).
|
||||
Get("/accounts/{accountID}", api.WrapHandlerT(accounts.GetID))
|
||||
r.With(app.APIAuth(database.TokenScopeAccountsMe, false)).
|
||||
Get("/accounts/@me", api.WrapHandlerT(accounts.GetMe))
|
||||
|
||||
blogs := blogs.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopeBlogsRead, unauthedAccess)).
|
||||
Get("/blogs/{blogID}", api.WrapHandlerT(blogs.GetID))
|
||||
r.With(app.APIAuth(database.TokenScopeBlogsRead, unauthedAccess)).
|
||||
Get("/blogs/lookup/{blogName}", api.WrapHandlerT(blogs.LookupName))
|
||||
|
||||
posts := posts.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopePostsRead, unauthedAccess)).
|
||||
Get("/posts/{postID}", api.WrapHandlerT(posts.GetID))
|
||||
r.With(app.APIAuth(database.TokenScopePostsWrite, false)).
|
||||
Post("/blogs/{blogID}/posts", api.WrapHandlerT(posts.Create))
|
||||
|
||||
timelines := timelines.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopeTimeline, false)).
|
||||
Get("/timelines/home", api.WrapHandlerT(timelines.Home))
|
||||
|
||||
})
|
||||
|
||||
// web app handlers
|
||||
// also assets
|
||||
app.Router.Group(func(r chi.Router) {
|
||||
|
@ -35,20 +68,4 @@ func Routes(app *app.App) {
|
|||
r.HandleFunc("/web/@{username}", frontend.ServeUser)
|
||||
r.HandleFunc("/web/@{username}/posts/{postID}", frontend.ServeStatus)
|
||||
})
|
||||
|
||||
// APIv1 handlers
|
||||
app.Router.Route("/api/v1", func(r chi.Router) {
|
||||
// account handlers
|
||||
accounts := accounts.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopeAccountsRead, true)).
|
||||
Get("/accounts/{accountID}", api.WrapHandlerT(accounts.GetID))
|
||||
r.With(app.APIAuth(database.TokenScopeAccountsMe, false)).
|
||||
Get("/accounts/@me", api.WrapHandlerT(accounts.GetMe))
|
||||
|
||||
blogs := blogs.New(app)
|
||||
r.With(app.APIAuth(database.TokenScopeBlogsRead, true)).
|
||||
Get("/blogs/{blogID}", api.WrapHandlerT(blogs.GetID))
|
||||
r.With(app.APIAuth(database.TokenScopeBlogsRead, true)).
|
||||
Get("/blogs/lookup/{blogName}", api.WrapHandlerT(blogs.LookupName))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue