fix(saves): return valid cloud settings and persist tutorial skips
Return the unframed BLK expected by the cloud settings client. Allow the basic ground tutorial to be skipped and save the tutorial preference immediately.
This commit is contained in:
1 parent
a2667a16a0
commit
32e9201a5f
4 files changed
+63
-12
No files matched your search
@@ -18,21 +18,29 @@ import {
|
||||
import { withAccount } from './account-context.ts';
|
||||
import { headerOrPayloadInt, headerOrPayloadString } from './payload-params.ts';
|
||||
|
||||
/** `cln_get_meta_blk`: returns schema, compression negotiation, and saved block versions/hashes. */
|
||||
/**
|
||||
* `cln_get_meta_blk`: returns schema, compression negotiation, and saved block versions/hashes.
|
||||
* `GetMetaHandler::handleResponse` (0x46659c0 -> 0x3280a50) parses the raw HTTP body directly
|
||||
* with `DataBlock::loadFromStream` without stripping the `'i'` char compression marker.
|
||||
*/
|
||||
export function getMetaBlkAction(accounts: AccountStore, cloudSettings: CloudSettingsStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => ({
|
||||
kind: 'data',
|
||||
kind: 'raw-blk',
|
||||
blk: cloudSettings.buildMetaBlk(account.userId),
|
||||
}));
|
||||
}
|
||||
|
||||
/** `cln_get_general_blk`: returns `ContainerBlk` (`version:i`, `content { ... }`) for a valid `blkType`. */
|
||||
/**
|
||||
* `cln_get_general_blk`: returns `ContainerBlk` (`version:i`, `content { ... }`) for a valid `blkType`.
|
||||
* `LoadingHandler::handleResponse` (0x4667930 -> `ContainerBlk::load` 0x466a9e0 -> 0x3280a50)
|
||||
* likewise reads bare binary BLK directly from the HTTP response buffer.
|
||||
*/
|
||||
export function getGeneralBlkAction(accounts: AccountStore, cloudSettings: CloudSettingsStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const blkType = headerOrPayloadString(context, 'blkType');
|
||||
if (!blkType || !isSupportedGeneralBlkType(blkType)) return { kind: 'error', code: 'BAD_PARAM' };
|
||||
const stored = cloudSettings.loadContainer(account.userId, blkType) ?? buildContainerBlk(1, emptyBlock('content'));
|
||||
return { kind: 'data', blk: stored };
|
||||
return { kind: 'raw-blk', blk: stored };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
/**
|
||||
* The char service's three kinds of answer (implementation notes; aces.exe 2.61.0.37,
|
||||
* The char service's answer shapes (implementation notes; aces.exe 2.61.0.37,
|
||||
* CharServerClient::handleReqResult at 0x336d590):
|
||||
* - data: HTTP 200, a compression marker and a BLK;
|
||||
* - data: HTTP 200, a compression marker ('i') and a binary BLK (`loadBlkFromAnswer`, 0x336fd60);
|
||||
* - raw-blk: HTTP 200, a bare binary BLK with no compression marker, for `online_storage`
|
||||
* endpoints (`GetMetaHandler` 0x46659c0 and `LoadingHandler` 0x4667930 -> `0x3280a50`);
|
||||
* - json: HTTP 200, UTF-8 JSON for custom JSON actions;
|
||||
* - done: HTTP 200 with a body starting "!OK", for requests that expect no data;
|
||||
* - error: a body starting "!ERROR:" followed by an error code.
|
||||
*/
|
||||
import { formatBlkText, type BlkBlock } from '@wto/blk';
|
||||
import { encodeBlk, formatBlkText, type BlkBlock } from '@wto/blk';
|
||||
import type { ServiceResponse } from '../server/exchange.ts';
|
||||
import { encodeDataAnswer } from './char-payload.ts';
|
||||
|
||||
export type CharAnswer =
|
||||
| { readonly kind: 'data'; readonly blk: BlkBlock }
|
||||
| { readonly kind: 'raw-blk'; readonly blk: BlkBlock }
|
||||
| { readonly kind: 'json'; readonly data: unknown }
|
||||
| { readonly kind: 'done' }
|
||||
| { readonly kind: 'error'; readonly code: string };
|
||||
@@ -19,6 +23,8 @@ export function toResponse(answer: CharAnswer): ServiceResponse {
|
||||
switch (answer.kind) {
|
||||
case 'data':
|
||||
return { status: 200, headers: BINARY, body: encodeDataAnswer(answer.blk), logNotes: { responseText: formatBlkText(answer.blk) } };
|
||||
case 'raw-blk':
|
||||
return { status: 200, headers: BINARY, body: encodeBlk(answer.blk), logNotes: { responseText: formatBlkText(answer.blk) } };
|
||||
case 'json': {
|
||||
const body = JSON.stringify(answer.data);
|
||||
return { status: 200, headers: JSON_HEADERS, body, logNotes: { responseText: body } };
|
||||
|
||||
Reference in new issue
Block a user