mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
optimize add topic for message only
This commit is contained in:
parent
8cf1d2f24b
commit
91621b8a58
@ -19,7 +19,7 @@ export function Home() {
|
|||||||
navigate('/admin')
|
navigate('/admin')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [])
|
}, [app])
|
||||||
|
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,32 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function addChannelTopic(token, channelId, message, assets ) {
|
export async function addChannelTopic(token, channelId, message, assets ) {
|
||||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
|
||||||
checkResponse(topic);
|
|
||||||
let slot = await topic.json();
|
|
||||||
|
|
||||||
// add each asset
|
|
||||||
|
|
||||||
let subject = { data: JSON.stringify(message, (key, value) => {
|
let subject = { data: JSON.stringify(message, (key, value) => {
|
||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`,
|
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
|
||||||
checkResponse(unconfirmed);
|
|
||||||
|
|
||||||
let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
|
if (assets == null || assets.length == 0) {
|
||||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}&confirm=true`,
|
||||||
checkResponse(confirmed);
|
{ method: 'POST', body: JSON.stringify(subject) });
|
||||||
|
checkResponse(topic);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
||||||
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
|
checkResponse(topic);
|
||||||
|
|
||||||
return;
|
let slot = await topic.json();
|
||||||
|
|
||||||
|
// add each asset
|
||||||
|
|
||||||
|
let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`,
|
||||||
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
|
checkResponse(unconfirmed);
|
||||||
|
|
||||||
|
let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
|
||||||
|
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||||
|
checkResponse(confirmed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,31 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
|
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
|
||||||
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
|
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
|
||||||
checkResponse(topic);
|
|
||||||
let slot = await topic.json();
|
|
||||||
|
|
||||||
// add each asset
|
|
||||||
|
|
||||||
let subject = { data: JSON.stringify(message, (key, value) => {
|
let subject = { data: JSON.stringify(message, (key, value) => {
|
||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
|
||||||
checkResponse(unconfirmed);
|
|
||||||
|
|
||||||
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
if (assets == null || assets.length == 0) {
|
||||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
|
||||||
checkResponse(confirmed);
|
{ method: 'POST', body: JSON.stringify(subject) });
|
||||||
|
checkResponse(topic);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
|
||||||
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
|
checkResponse(topic);
|
||||||
|
let slot = await topic.json();
|
||||||
|
|
||||||
return;
|
// add each asset
|
||||||
|
|
||||||
|
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
||||||
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
|
checkResponse(unconfirmed);
|
||||||
|
|
||||||
|
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
||||||
|
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||||
|
checkResponse(confirmed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ export function useAppContext() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!state) {
|
if (state == null) {
|
||||||
return {}
|
return {};
|
||||||
}
|
}
|
||||||
if (state.access === 'user') {
|
if (state.access === 'user') {
|
||||||
return { state, actions: userActions }
|
return { state, actions: userActions }
|
||||||
|
Loading…
Reference in New Issue
Block a user