implementing focus module

This commit is contained in:
Roland Osborne 2024-11-21 23:39:27 -08:00
parent 01031d65d6
commit 66a09949ea
4 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
import { TopicDetailEntity } from '../entities';
export async function getChannelTopicDetail(node: string, secure: boolean, token: string, channelId: string, topicId: string): Promise<TopicDetailEntity> {
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`;
const detail = await fetchWithTimeout(endpoint, { method: 'GET' });
checkResponse(detail.status);
return await detail.json();
}

View File

@ -0,0 +1,15 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
import { TopicEntity } from '../entities';
export async function getChannelTopics(node: string, secure: boolean, token: string, channelId: stirng, revision: number | null, count: number | null, begin: number | null, end: number | null): Promise<{marker: number, revision: number, topics: TopicEntity[]}> {
const params = (revision ? `&revision=${revision}` : '') + (count ? `&count=${count}` : '') + (begin ? `&begin=${begin}` : '') + (end ? `&end=${end}` : '');
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics?agent=${token}${params}`;
const topics = await fetchWithTimeout(endpoint, { method: 'GET' });
checkResponse(topics.status);
return {
marker: topics.headers.get('topic-marker'),
revision: topics.headers.get('topic-revision'),
topics: await topics.json(),
}
}

View File

@ -0,0 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
import { TopicDetailEntity } from '../entities';
export async function getContactChannelTopicDetail(node: string, secure: boolean, guidToken: string, channelId: string, topicId: string): Promise<TopicDetailEntity> {
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics/${topicId}/detail?contact=${guidToken}`;
const detail = await fetchWithTimeout(endpoint, { method: 'GET' });
checkResponse(detail.status);
return await detail.json();
}

View File

@ -0,0 +1,14 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
import { TopicEntity } from '../entities';
export async function getContactChannelTopics(node: string, secure: boolean, guidToken: string, channelId: string, revision: number | null, count: number | null, begin: number | null, end: number | null): Promise<{ marker: number, revision: number, topics: TopicEntity[]}> {
const params = (revision ? `&revision=${revision}` : '') + (count ? `&count=${count}` : '') + (begin ? `&begin=${begin}` : '') + (end ? `&end=${end}` : '');
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics?contact=${guidToken}${params}`;
const topics = await fetchWithTimeout(endpoint, { method: 'GET' });
checkResponse(topics.status);
return {
marker: topics.headers.get('topic-marker'),
revision: topics.headers.get('topic-revision'),
topics: await topics.json(),
}
}