supporting non-federated config

This commit is contained in:
Roland Osborne 2022-07-29 14:23:02 -07:00
parent 9f134f9644
commit 89bd4d9361
23 changed files with 156 additions and 34 deletions

View File

@ -3,7 +3,7 @@ import { RegistryWrapper, RegistryItem } from './Registry.styled';
import { useRegistry } from './useRegistry.hook';
import { Button, Input, List } from 'antd';
import { Logo } from '../../../../../Logo/Logo';
import { MoreOutlined } from '@ant-design/icons';
import { SearchOutlined, MoreOutlined } from '@ant-design/icons';
export function Registry() {
@ -22,8 +22,17 @@ export function Registry() {
return (
<RegistryWrapper>
<Input.Search placeholder="Server" value={state.server} onChange={(e) => actions.setServer(e.target.value)}
onSearch={actions.getRegistry} style={{ width: '100%' }} />
{ state.server && (
<Input.Search placeholder="Server" value={state.server}
onChange={(e) => actions.setServer(e.target.value)}
onSearch={actions.getRegistry} style={{ width: '100%' }} />
)}
{ !state.server && (
<div class="local">
<div class="local-name">{ window.location.host }</div>
<Button icon={<SearchOutlined />} onClick={actions.getRegistry}></Button>
</div>
)}
<div class="contacts">
<List
locale={{ emptyText: '' }}

View File

@ -9,6 +9,23 @@ export const RegistryWrapper = styled.div`
overflow-x: hidden;
flex-direction: column;
.local {
display: flex;
flex-directionL row;
align-items: center;
justify-content: center;
.local-name {
border: 1px solid rgb(221, 221, 221);
height: 32px;
display: flex;
align-items: center;
padding-right: 8px;
padding-left: 8px;
background-color: rgb(238, 238, 238);
}
}
.contacts {
flex-grow: 1
background-color: #fefefe;

View File

@ -22,7 +22,12 @@ export function useRegistry() {
useEffect(() => {
if (profile?.state?.profile) {
let identity = profile.state.profile;
updateState({ server: identity.node });
if (identity.node == null || identity.node == '') {
updateState({ server: null });
}
else {
updateState({ server: identity.node });
}
}
}, [profile]);

View File

@ -1,4 +1,4 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
import { checkResponse, fetchWithCustomTimeout } from './fetchUtil';
var base64 = require('base-64');
export async function addAccount(username, password, token) {
@ -8,7 +8,7 @@ export async function addAccount(username, password, token) {
}
let headers = new Headers()
headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password));
let profile = await fetchWithTimeout(`/account/profile${access}`, { method: 'POST', headers: headers })
let profile = await fetchWithCustomTimeout(`/account/profile${access}`, { method: 'POST', headers: headers }, 60000)
checkResponse(profile);
return await profile.json()
}

View File

@ -1,9 +1,13 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
let host = "";
if (server) {
host = `https://${server}`
}
if (message == null && (assets == null || assets.length == 0)) {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}`,
{ method: 'POST', body: JSON.stringify({}) });
checkResponse(topic);
let slot = await topic.json();
@ -14,14 +18,14 @@ export async function addContactChannelTopic(server, token, channelId, message,
if (value !== null) return value
}), datatype: 'superbasictopic' };
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
{ method: 'POST', body: JSON.stringify(subject) });
checkResponse(topic);
let slot = await topic.json();
return slot.id;
}
else {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}`,
{ method: 'POST', body: JSON.stringify({}) });
checkResponse(topic);
let slot = await topic.json();
@ -33,7 +37,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
const formData = new FormData();
formData.append('asset', asset.image);
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
@ -48,7 +52,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
formData.append('asset', asset.video);
let thumb = "vthumb;video;" + asset.position
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
@ -63,7 +67,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
const formData = new FormData();
formData.append('asset', asset.audio);
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
@ -79,11 +83,11 @@ export async function addContactChannelTopic(server, token, channelId, message,
if (value !== null) return value
}), datatype: 'superbasictopic' };
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
let unconfirmed = await fetchWithTimeout(`${host}/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}`,
let confirmed = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
{ method: 'PUT', body: JSON.stringify('confirmed') });
checkResponse(confirmed);
return slot.id;

View File

@ -15,3 +15,10 @@ export async function fetchWithTimeout(url, options) {
]);
}
export async function fetchWithCustomTimeout(url, options, timeout) {
return Promise.race([
fetch(url, options).catch(err => { throw new Error(url + ' failed'); }),
new Promise((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), timeout))
]);
}

View File

@ -1,7 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelDetail(server, token, channelId) {
let detail = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' });
let host = "";
if (server) {
host = `https://${server}`;
}
let detail = await fetchWithTimeout(`${host}/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' });
checkResponse(detail)
return await detail.json()
}

View File

@ -1,7 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelSummary(server, token, channelId) {
let summary = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/summary?contact=${token}`, { method: 'GET' });
let host = "";
if (server) {
host = `https://${server}`;
}
let summary = await fetchWithTimeout(`${host}/content/channels/${channelId}/summary?contact=${token}`, { method: 'GET' });
checkResponse(summary)
return await summary.json()
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelTopic(server, token, channelId, topicId) {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
let host = "";
if (server) {
host = `https://${server}`;
}
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
{ method: 'GET' });
checkResponse(topic)
return await topic.json()

View File

@ -1,4 +1,9 @@
export function getContactChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}`
let host = "";
if (server) {
host = `https://${server}`;
}
return `${host}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}`
}

View File

@ -1,6 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
let host = "";
if (server) {
host = `https://${server}`;
}
let rev = ''
if (revision != null) {
rev = `&revision=${revision}`
@ -17,7 +22,7 @@ export async function getContactChannelTopics(server, token, channelId, revision
if (end != null) {
edn = `&end=${end}`
}
let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`,
let topics = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`,
{ method: 'GET' });
checkResponse(topics)
return {

View File

@ -1,6 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannels(server, token, viewRevision, channelRevision) {
let host = "";
if (server) {
host = `https://${server}`;
}
let param = "?contact=" + token
if (viewRevision != null) {
param += '&viewRevision=' + viewRevision
@ -8,7 +13,7 @@ export async function getContactChannels(server, token, viewRevision, channelRev
if (channelRevision != null) {
param += '&channelRevision=' + channelRevision
}
let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' });
let channels = await fetchWithTimeout(`${host}/content/channels${param}`, { method: 'GET' });
checkResponse(channels)
return await channels.json()
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactProfile(server, guid, token) {
let profile = await fetchWithTimeout(`https://${server}/profile/message?contact=${guid}.${token}`, { method: 'GET', });
let host = "";
if (server) {
host = `https://${server}`;
}
let profile = await fetchWithTimeout(`${host}/profile/message?contact=${guid}.${token}`, { method: 'GET', });
checkResponse(profile);
return await profile.json()
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getListing(server) {
let listing = await fetchWithTimeout(`https://${server}/account/listing`, { method: 'GET' });
let host = "";
if (server) {
host = `https://${server}`;
}
let listing = await fetchWithTimeout(`${host}/account/listing`, { method: 'GET' });
checkResponse(listing);
return await listing.json();
}

View File

@ -1,5 +1,10 @@
export function getListingImageUrl(server, guid) {
return `https://${server}/account/listing/${guid}/image`
let host = "";
if (server) {
host = `https://${server}`;
}
return `${host}/account/listing/${guid}/image`
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getListingMessage(server, guid) {
let listing = await fetchWithTimeout(`https://${server}/account/listing/${guid}/message`, { method: 'GET' });
let host = "";
if (server) {
host = `https://${server}`;
}
let listing = await fetchWithTimeout(`${host}/account/listing/${guid}/message`, { method: 'GET' });
checkResponse(listing);
return await listing.json();
}

View File

@ -1,8 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeContactChannel(server, token, channelId) {
let host = "";
if (server) {
host = `https://${server}`;
}
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?contact=${token}`,
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}?contact=${token}`,
{ method: 'DELETE' });
checkResponse(channel);
}

View File

@ -1,8 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeContactChannelTopic(server, token, channelId, topicId) {
let channel = await fetchWithTimeout(`https://${server}//content/channels/${channelId}/topics/${topicId}?contact=${token}`,
let host = "";
if (server) {
host = `https://${server}`;
}
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}?contact=${token}`,
{ method: 'DELETE' });
checkResponse(channel);
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setCardCloseMessage(server, message) {
let status = await fetchWithTimeout(`https://${server}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) });
let host = "";
if (server) {
host = `https://${server}`;
}
let status = await fetchWithTimeout(`${host}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) });
checkResponse(status);
return await status.json();
}

View File

@ -1,7 +1,12 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setCardOpenMessage(server, message) {
let status = await fetchWithTimeout(`https://${server}/contact/openMessage`, { method: 'PUT', body: JSON.stringify(message) });
let host = "";
if (server) {
host = `https://${server}`;
}
let status = await fetchWithTimeout(`${host}/contact/openMessage`, { method: 'PUT', body: JSON.stringify(message) });
checkResponse(status);
return await status.json();
}

View File

@ -1,11 +1,16 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setContactChannelTopicSubject(server, token, channelId, topicId, asset) {
let host = "";
if (server) {
host = `https://${server}`;
}
if (asset.image) {
const formData = new FormData();
formData.append('asset', asset.image);
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
return {
@ -20,7 +25,7 @@ export async function setContactChannelTopicSubject(server, token, channelId, to
formData.append('asset', asset.video);
let thumb = "vthumb;video;" + asset.position
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
return {
@ -35,7 +40,7 @@ export async function setContactChannelTopicSubject(server, token, channelId, to
const formData = new FormData();
formData.append('asset', asset.audio);
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
return {

View File

@ -1,11 +1,16 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setContactChannelTopicSubject(server, token, channelId, topicId, data) {
let host = "";
if (server) {
host = `https://${server}`;
}
let subject = { data: JSON.stringify(data, (key, value) => {
if (value !== null) return value
}), datatype: 'superbasictopic' };
let channel = await fetchWithTimeout(`https://${server}//content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`,
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`,
{ method: 'PUT', body: JSON.stringify(subject) });
checkResponse(channel);
}

View File

@ -82,10 +82,14 @@ export function useUploadContext() {
abort(`:${channelId}`, topicId);
},
addContactTopic: (server, token, cardId, channelId, topicId, files, success, failure) => {
let host = "";
if (server) {
host = `https://${server}`
}
const controller = new AbortController();
const entry = {
index: index.current,
url: `https://${server}/content/channels/${channelId}/topics/${topicId}/assets?contact=${token}`,
url: `${host}/content/channels/${channelId}/topics/${topicId}/assets?contact=${token}`,
files,
assets: [],
current: null,