# "in" (old_in) - complete feature inventory for a from-scratch rebuild Source tree: /home/tahinli/Documents/Code/Rust/old_in (read-only inventory; nothing modified). Crates: crates/in-core (store, config, thumbs, live), crates/in-client (OIDC client to im), crates/in-web (HTTP app on topcoat 0.9.0). Method: every source file was read by a dedicated pass (turso_store.rs and tests were split), then cross-checked by grep. Items marked "(unverified)" were not confirmed against source. --- ## 1. Purpose 1. "in" is a personal file drive: folders, file upload (small and chunked/resumable), download, preview, thumbnails, trash, share links, per-person shares, quotas. 2. Sign-in is delegated to sibling app "im" (OIDC, PKCE, RS256 id_token, introspection per request). im also provides the user directory (full pass + live stream) and avatars. 3. Storage is local disk (default) or Cloudflare R2 (S3 API) for final blobs; upload staging is always local. 4. A machine "service API" (bearer keys) lets other family apps push, fetch and delete blobs against a per-service account and quota. 5. Single binary, server-rendered HTML with small inline JS, SSE for live updates, SQLite-compatible Turso database. --- ## 2. User-facing features Conventions: "owner" = the signed-in user who owns a row. Cross-owner access always answers 404 (never 403) on purpose. Mutations are HTML form POSTs that answer 303 back to the page with `?refusal=&on=` on failure. JSON "API" routes answer HTTP 200 with `{"ok": ...}` or `{"err": ""}`. Unauthenticated page GETs redirect 303 to `/`. ### 2.1 Sign-in and session - GET `/` : signed-in browser gets 303 to `/drive`; signed-out gets the sign-in card (link to `/auth/login`). Store error renders a scaffold note. - GET `/auth/login` : OIDC start. Sets flight cookie `in_session_pkce` (sealed JSON {verifier, state, nonce, next, exp}, Max-Age 600). 303 to `{issuer}/authorize` (response_type=code, scope "openid profile email", PKCE S256, 32-byte verifier, 16-byte state and nonce). `next` accepted only as a local absolute path. - GET `/auth/callback` : `?error=X` -> `/?auth_error=X`; missing code/state or flight cookie -> `invalid_request`; expired flight or state mismatch -> `invalid_state`; exchange failure -> `exchange_failed`. Success sets session cookie and redirects to `next`. - GET `/auth/logout` : clears `in_session`, 303 to `{issuer}/logout?back=/`. (State-changing GET; logout CSRF possible, see oddities.) - Per request: `current_user` opens the session cookie, checks local exp, then introspects with im every request. Only explicit `active:false` clears the cookie; transport errors read as signed out but keep the cookie. A disabled local account reads as signed out. First provisioned user becomes admin. - GET `/api/me` : session probe. 204 signed in, 401 signed out (empty body), 500 on store failure. - GET `/whoami` : appears in one place as a route; probably test-only (unverified). ### 2.2 Drive (browse, folders) - GET `/drive` (`?folder=`, `?q=`, `?sort=key:dir`, `?kind=all|folders|files`, `?edit=`, `?share=kind:id`, `?move=kind:id`, `?created=`, `?refusal=&on=`). - Owner view of a folder: `current_folder` requires owned, live folder with no trashed ancestor; otherwise 404 (store errors also 404). If that fails, `granted_folder` tries a grant; grantee gets the read-only `drive_shared` view. Otherwise 404. - Listing: subfolders first, then files, from `list_children`. Row: chip, name, "Shared" chip (from `shared_target_ids`, silent on error), size (files), created date, download count (files). Folder rows link `/drive?folder=`, file rows `/view/`. - Row Options menu (details element): Rename (`?edit=`), Share (`?share=`), Move (`?move=`), Delete (POST), Download (files, `/file/?dl=1`). - Breadcrumb trail root-first, hidden in search and at root; errors silently truncate it. - Sorting keys: name (default asc), uploaded (created_at), size, downloads. Bare key defaults: name asc, others desc. Unknown key = standing order. Folders sort by name for size/downloads. Ties broken by id. Sorting done in page layer. - Kind filter `all|folders|files` (unknown = all), applied after sort. - Filter bar: search box (`q`), sort select and kind select (autosubmit), "+" menu (New folder; upload input `#drive-upload-input`). - Search mode (`q` trimmed, non-empty): `store.search(user, q, 50)` library-wide, folders and files separately, ignores current folder; caption "Search results"; NoResults empty state; no row options. - Empty states: `EmptyFolder` (note a kind filter that hides everything also shows this), `NoResults`, `SharedFolderEmpty` for grantees. - Rename-in-place when `?edit=`: inline form posting to `/api/folder/rename` or `/api/file/rename`, input maxlength 255, required. - Created-link panel `?created=`: one-time share URL `{origin}/s/{token}` with "copy once" note. - Refusal banner from `?refusal=` for names create, rename, move, delete, upload (not share). - GET `/search` : 303 to `/drive?q=` (blank -> `/drive`). Only `q` forwarded. - Move picker `?move=kind:id`: modal listing "Drive" root plus all owned live folders (depth-first, one list_children per folder, N+1). Folder target excludes its own subtree (display-path prefix match, a folder name containing " / " can confuse it). Each row is a POST form (`/api/file/move` with folder_id, or `/api/folder/move` with parent_id; blank = root). - Share modal `?share=kind:id` rendered by `share.rs` (see 2.7). - Grantee view `drive_shared`: granted folder title, "Shared with you" + access chip (View only / May download), listing with sort and kind only (q/edit/share/move ignored), trail stops at granted root, no write affordances. Folder mutations (all owner-only, POST, 303 back via `back_to`, refusal via redirect): - POST `/api/folder/create` (`parent_id`, `name`). Parent must be owned and live. Blank name -> quick-create "New folder" (postfixed by store) and redirect to `/drive?folder=&edit=` (sort/kind dropped). Name not trimmed when stored. - POST `/api/folder/rename` (`id`, `name`). Owned+live folder. No server-side trim, emptiness or length check in this layer (HTML maxlength only); the store enforces names. - POST `/api/folder/move` (`id`, `parent_id`). Owned+live folder and parent. Cycles/self-nesting -> store `Cycle` -> refusal `Forbidden`. - POST `/api/folder/delete` (`id`). Soft-trashes the subtree (store). Cross-owner / missing -> NotFound refusal. - store error mapping: QuotaExceeded -> QuotaExceeded; NotFound/CrossOwner -> NotFound; Cycle -> Forbidden; other -> Unavailable. Name rules (store): labels only, path components stripped (`../../etc` stored as `etc`), control chars removed, empty -> "Untitled", max 255 chars (postfixed names truncate the stem so the total fits; the extension itself is not truncated). Collisions among live siblings get " (2)", " (3)"... inserted before the extension for files (`report.txt` -> `report (2).txt`; extension-less `note` -> `note (2)`), appended for folders (`root (2)`). Files and folders are separate namespaces. Name match is exact and case-sensitive (BINARY collation; "Zeta" sorts before "alpha"). ### 2.3 Upload Two paths, both owner-only. A. Single-shot multipart (`POST /files`): fields `folder_id` (must precede file parts) and one or more `file` parts. Each part fully buffered in memory, then `insert_file`. Empty list = redirect with no refusal. Folder must be owned and live (else NotFound, redirect `/drive`). Stops at the first refusal; files already inserted stay; only that refusal is reported. Redirect `303 /drive?folder=` (+ `&refusal=&on=upload`). Body limit 2 GiB (main.rs). Parse errors return Unavailable before any insert. Blob puts happen inside the store's write transaction. B. Chunked, resumable (JS in the drive page; threshold 8 MiB in JS `LIMIT = 8388608`; smaller files use A). Chunk size fixed at 8 MiB (`CHUNK_SIZE = 8388608`, server-fixed, returned by start). Chunk body limit 32 MiB (main.rs `/api/upload`). - POST `/api/upload/start` body `{folder_id?, name, size_bytes}` -> `{id, chunk_size}`. Folder must be owned, live. Quota pre-check against user quota minus other active sessions' declared sizes (`staged_claim`). Creates session row `state=active`, `expires_at = now + 24h` (`UPLOAD_TTL_HOURS = 24`), and staging dir. - GET `/api/upload/{id}` -> `{id, chunk_size, size_bytes, name, folder_id, uploaded: [indexes]}`. Works on expired sessions; lets the client skip staged chunks. Other owner / unknown -> `{"err":"NotFound"}`. - PUT `/api/upload/{id}/{index}` raw body -> `{received_bytes, size_bytes}`. Index must be < chunk_count; byte length must equal the expected length (last chunk may be short) else `BadChunk`; expired or not-active -> `UploadExpired`. Written atomically to `uploads//`. `received_bytes` is measured from disk, not incremented. - POST `/api/upload/{id}/finish` -> `{ok: ""}`. Requires all chunks; assembles them in order to a temp file, checks total size; MIME sniffed from first 1 MiB (never the uploader's claim); thumbnail computed outside the transaction; then in one IMMEDIATE transaction: re-checks session active and unexpired, parent live, quota (excluding this session's own claim), name collision (postfix, never refused); adopts the temp to `files/`, puts thumb, inserts row, marks session `done`, refreshes usage; staging dir removed after commit. Chunks kept on refusal so the client can retry. Refusals: UploadExpired, NotFound, BadChunk, QuotaExceeded. - POST `/api/upload/{id}/abort` -> `{ok: null}`. Marks active session aborted and removes staging dir. Idempotent (unknown id answers `{err:"not_found"}` in one path, per upload.rs). - Client behaviour (JS in drive page): 3 attempts per chunk, backoff 1000*attempt ms; one session restart on UploadExpired; resume key in localStorage `in-upload:::`. - Expired sessions: boot sweep marks active sessions past `expires_at` as aborted and deletes staging dirs (`prune_expired_uploads`); rows are kept as aborted. Quota: `used_bytes` counts all live and trashed file bytes; checked at start, at finish and for service pushes. Staged sessions' declared sizes count against new uploads' headroom. ### 2.4 Download, preview, viewer - GET `/file/{id}` (`?dl=1` forces attachment; presence of the key counts, even `dl=0`). - Unauthenticated -> 303 `/`. Not visible (not owner and no grant, or trashed and not owner) -> 404. - Forced download needs `may_download` (owner, or grant with can_download; trashed files are not downloadable). Otherwise 404. - Inline only if not forced and mime in: image/* (except image/heic), video/*, audio/*, application/pdf, text/plain; never image/svg+xml or text/html (forced to attachment). - Content-Disposition: `inline|attachment; filename=""; filename*=UTF-8''`; ASCII fallback maps non-[A-Za-z0-9._-] to `_`. - Content-Type = stored mime (not re-sniffed). `Accept-Ranges: bytes`. `Cache-Control: private, max-age=31536000, immutable`. - Range: single `bytes=a-b`, `a-`, `-N` only; multi-range, malformed, start>end, `-0` ignored (full 200). Start past end -> 416 with `Content-Range: bytes */total`. Valid -> 206 with `Content-Range`. - Streams via `file_stream` (64 KiB frames per doc). - Download counter `download_count` incremented only when forced, successful, and either no Range or range starts at 0. - GET `/thumb/{id}` : webp thumbnail (`image/webp`), visible to the same audience as `/file` (trashed owner can still fetch). Not visible -> plain 404. ETag = quoted FNV-1a hex of bytes; `If-None-Match` exact match -> 304; `Cache-Control: private, max-age=31536000, immutable`. - GET `/view/{id}` : viewer page. Not visible -> framework 404. Shows entry chip, name, meta "mime · size", uploaded date, download count, details panel (size, uploaded, downloads). Back link: trashed -> `/trash`; `?from=shared` -> `/shared`; else `/drive`. Download button only when may_download; "View only" note for non-owner without download. - Viewer kinds (`viewer_kind`): Image (``, all viewers), Video and Audio (house media player, all viewers), PDF (``) and Text (`