Pin the server contract, tokens and strings to server dev a25db24; app API 2
The contract moves from f5b3dbb to the server's dev at a25db24971a0: version.json says
{"app_api": 2}, and the server now writes its own show cards (tool_show.json: one from the tree,
one from a device) and the files routes (files_listing.json, file_content.json,
file_content_withheld.json). Tokens from the same commit change only in the header; the strings
regenerate unchanged.
- APP_API is 2, and it is now the floor as well as the ceiling: a protocol-3 server that still
says app API 1 is a 2.0 build from before the show route and the files, and is refused as too
old, as 1.x is.
- The files routes are modelled (FileEntry, FileListing, FileContent, Withheld) and ApiClient
reads them: files(path), fileContent(path), and webFile(path) for the web UI's /files/view.
- shownText is documented against the server's real route, GET /api/v2/chats/{chat}/show with
?node=&version= or ?shown=, plain text up to 1 MB, 413 / 415 / 404; ClientTest pins the paths.
- The hand-written show cards leave ShowAndServerTest; ContractTest reads the server's.
Nothing in the app reads /api/v2/devices for its own token (devices() has no caller), so apps no
longer being listed there changes nothing here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
15 files changed
+302
-57
No files matched your search
@@ -230,9 +230,13 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
// --- What a `show` card opens -------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The text of a file a `show` card named, as the chat sees it now: the server rebuilds the
|
||||
* chat's view and checks the path again, so a grant taken away since takes the file away too.
|
||||
* Always plain text -- the app never asks for a page to render.
|
||||
* The text of a file a `show` card named, as the chat sees it now:
|
||||
* `GET /api/v2/chats/{chat}/show?node=<node_id>&version=<version_id>` for a file in the tree,
|
||||
* `?shown=<shown_id>` for the copy a linked device sent ([ShowCard.query]). The server rebuilds
|
||||
* the chat's view and checks the path again, so a grant taken away since takes the file away
|
||||
* too (404, in the server's words). `text/plain; charset=utf-8`, at most 1 MB: above it a 413,
|
||||
* and a 415 for a file that is not text. Always plain text -- an HTML file is its source, and
|
||||
* the app never asks for a page to render.
|
||||
*/
|
||||
suspend fun shownText(chatId: String, show: ShowCard): String = withContext(Dispatchers.IO) {
|
||||
val url = "$v2/chats/$chatId/show".toHttpUrl().newBuilder()
|
||||
@@ -252,6 +256,26 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
}
|
||||
}
|
||||
|
||||
// --- The person's files ------------------------------------------------------------------
|
||||
|
||||
/** A directory, as the person may see it (no chat's grants): `GET /api/v2/files?path=`. */
|
||||
suspend fun files(path: String = "/"): FileListing {
|
||||
val url = "$v2/files".toHttpUrl().newBuilder().addQueryParameter("path", path).build()
|
||||
return call(authed(url.toString()).get().build(), FileListing.serializer())
|
||||
}
|
||||
|
||||
/**
|
||||
* A file's text: `GET /api/v2/files/content?path=`. A file the server will not hand over as
|
||||
* text (not text, over 1 MB) is not an error: it comes back with `withheld` saying why.
|
||||
*/
|
||||
suspend fun fileContent(path: String): FileContent {
|
||||
val url = "$v2/files/content".toHttpUrl().newBuilder().addQueryParameter("path", path).build()
|
||||
return call(authed(url.toString()).get().build(), FileContent.serializer())
|
||||
}
|
||||
|
||||
/** A file of the tree in the web UI's own viewer (`/files/view`), for what the app does not draw. */
|
||||
fun webFile(path: String): String = "$base/files/view".toHttpUrl().newBuilder().addQueryParameter("path", path).build().toString()
|
||||
|
||||
/** The same file in the web UI's viewer, which renders HTML in its sealed frame. */
|
||||
fun webViewer(chatId: String, show: ShowCard): String = "$base/chat/$chatId/show".toHttpUrl().newBuilder()
|
||||
.apply { show.query.forEach { (k, v) -> addQueryParameter(k, v) } }
|
||||
|
||||
Reference in new issue
Block a user