diff --git a/docs/APP_API.md b/docs/APP_API.md new file mode 100644 index 0000000..0acb29b --- /dev/null +++ b/docs/APP_API.md @@ -0,0 +1,40 @@ +# App API (`/api/app/*`) + +The JSON API the Refetch mobile and desktop apps +([refetch_flutter](https://github.com/refetch-io/refetch_flutter)) call for +everything that writes or needs the signed-in person's private data. + +The apps **read public data straight from Appwrite** (posts, comments, channels +and topics are readable by anyone). Writes can't go there directly: a vote also +moves the story's score counters, and comments and submissions run rate limits, +duplicate checks, mentions and notifications. Those rules live in +`src/server/*.server.ts`, so these routes call the same functions the website's +server functions call — nothing is duplicated. + +## Auth + +Every route needs `Authorization: Bearer `. The app mints the JWT +with `account.createJWT()`; the route verifies it with Appwrite (`account.get` +as that user), the same check `establishSession` does for the website. A missing, +expired or forged token gets `401 { "error": "Please sign in to continue.", "code": "unauthorized" }`. + +## Responses + +- Success: `200 { "data": … }` +- Failure: `{ "error": "", "code"?, "existingId"? }` with + `400` (validation or a rule), `401` (`unauthorized`), `409` (`duplicate`) or + `429` (`rate_limited`); `500` for an unexpected error. + +## Routes + +| Method | Path | Body | `data` | +| --- | --- | --- | --- | +| POST | `/api/app/session` | `{}` | `{ user }`. Call after signing in; creates or renames the profile. | +| POST | `/api/app/vote` | `{ resourceType: 'post' \| 'comment', resourceId, direction: 'up' \| 'down' }` | `{ vote: 'up' \| 'down' \| null, count }`. Same direction again removes the vote. | +| POST | `/api/app/votes` | `{ posts?: string[], comments?: string[] }` (≤ 200 each) | `{ posts: { [id]: 'up' \| 'down' }, comments: { … } }` | +| POST | `/api/app/comments` | `{ postId, content, replyId? }` | the new comment | +| DELETE | `/api/app/comments/:id` | — | — (your own comments only) | +| POST | `/api/app/submit` | `{ title, url, comment? }` | `{ id }`; `409` with `existingId` when the link was already shared | + +Validation lives in `src/lib/app-api.ts` (unit tested); the request handling in +`src/server/app-api.server.ts`. diff --git a/src/api/moderation.ts b/src/api/moderation.ts index 7a0b606..37757ba 100644 --- a/src/api/moderation.ts +++ b/src/api/moderation.ts @@ -4,7 +4,12 @@ import { z } from 'zod' import type { ActionResult } from '@/lib/types' import { REPORT_NOTE_MAX, REPORT_REASON_VALUES, type ModerationItem } from '@/lib/reports' import { isValidId } from '@/lib/url' -import { countModerationQueue, createReport, listModerationQueue, resolveReports } from '@/server/reports.server' +import { + countModerationQueue, + createReport, + listModerationQueue, + resolveReports, +} from '@/server/reports.server' import { getSessionUser } from '@/server/session.server' const id = z.string().refine(isValidId, 'Invalid id') @@ -41,7 +46,7 @@ export const fetchModerationCount = createServerFn({ method: 'GET' }).handler(as return user?.moderator ? countModerationQueue() : 0 }) -export const resolveReport =createServerFn({ method: 'POST' }) +export const resolveReport = createServerFn({ method: 'POST' }) .validator(z.object({ resourceType, resourceId: id, action: z.enum(['dismiss', 'remove']) })) .handler(async ({ data }): Promise => { const user = await getSessionUser({ fresh: true }) diff --git a/src/components/layout/navigation.tsx b/src/components/layout/navigation.tsx index f552fe9..2625f1e 100644 --- a/src/components/layout/navigation.tsx +++ b/src/components/layout/navigation.tsx @@ -67,10 +67,7 @@ function SidebarChannels({ pathname }: { pathname: string }) { {/* Negative margin + padding leaves room for focus rings inside the scroll clip. */} -