Rework /room/{}/item and pagination query

- Now it use `skipToken` and `top` to (mostly) align to OData spec.

- Its response type is now a normal struct and is documented.

- Room metadata is now excluded from room item query.
This commit is contained in:
oxalica 2024-09-03 01:59:31 -04:00
parent 77216aa0f8
commit b05f704406
6 changed files with 158 additions and 196 deletions

View file

@ -178,25 +178,26 @@ async function connectRoom(url) {
log(`fetching room: ${url}`);
const auth = await signData({ typ: 'auth' });
fetch(
`${url}/item`,
{
headers: {
'Authorization': auth,
},
},
)
.then(async (resp) => {
return [resp.status, await resp.json()];
})
// TODO: This response format is to-be-decided.
const genFetchOpts = async () => ({ headers: { 'Authorization': await signData({ typ: 'auth' }) } });
genFetchOpts()
.then(opts => fetch(url, opts))
.then(async (resp) => { return [resp.status, await resp.json()]; })
.then(async ([status, json]) => {
if (status !== 200) throw new Error(`status ${status}: ${json.error.message}`);
const [{ title }, items] = json
document.title = `room: ${title}`
document.title = `room: ${json.title}`
})
.catch((e) => {
log(`failed to get room metadata: ${e}`);
});
genFetchOpts()
.then(opts => fetch(`${url}/item`, opts))
.then(async (resp) => { return [resp.status, await resp.json()]; })
.then(async ([status, json]) => {
if (status !== 200) throw new Error(`status ${status}: ${json.error.message}`);
const { items } = json
items.reverse();
for (const [_cid, chat] of items) {
for (const chat of items) {
await showChatMsg(chat);
}
log('---history---');