diff --git a/net/web/src/User/SideBar/Contacts/Cards/Registry/Registry.jsx b/net/web/src/User/SideBar/Contacts/Cards/Registry/Registry.jsx index 518d3430..f43c11ae 100644 --- a/net/web/src/User/SideBar/Contacts/Cards/Registry/Registry.jsx +++ b/net/web/src/User/SideBar/Contacts/Cards/Registry/Registry.jsx @@ -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 ( - actions.setServer(e.target.value)} - onSearch={actions.getRegistry} style={{ width: '100%' }} /> + { state.server && ( + actions.setServer(e.target.value)} + onSearch={actions.getRegistry} style={{ width: '100%' }} /> + )} + { !state.server && ( +
+
{ window.location.host }
+ +
+ )}
{ 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]); diff --git a/net/web/src/api/addAccount.js b/net/web/src/api/addAccount.js index 6eccf8e3..5937c857 100644 --- a/net/web/src/api/addAccount.js +++ b/net/web/src/api/addAccount.js @@ -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() } diff --git a/net/web/src/api/addContactChannelTopic.js b/net/web/src/api/addContactChannelTopic.js index cfc36c69..5f88f9bf 100644 --- a/net/web/src/api/addContactChannelTopic.js +++ b/net/web/src/api/addContactChannelTopic.js @@ -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; diff --git a/net/web/src/api/fetchUtil.js b/net/web/src/api/fetchUtil.js index 6ea98813..e4eb445d 100644 --- a/net/web/src/api/fetchUtil.js +++ b/net/web/src/api/fetchUtil.js @@ -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)) + ]); +} + diff --git a/net/web/src/api/getContactChannelDetail.js b/net/web/src/api/getContactChannelDetail.js index 4d2e1a17..ef8e5499 100644 --- a/net/web/src/api/getContactChannelDetail.js +++ b/net/web/src/api/getContactChannelDetail.js @@ -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() } diff --git a/net/web/src/api/getContactChannelSummary.js b/net/web/src/api/getContactChannelSummary.js index 84221417..278cbfa6 100644 --- a/net/web/src/api/getContactChannelSummary.js +++ b/net/web/src/api/getContactChannelSummary.js @@ -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() } diff --git a/net/web/src/api/getContactChannelTopic.js b/net/web/src/api/getContactChannelTopic.js index 9b921ee0..0715c122 100644 --- a/net/web/src/api/getContactChannelTopic.js +++ b/net/web/src/api/getContactChannelTopic.js @@ -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() diff --git a/net/web/src/api/getContactChannelTopicAssetUrl.js b/net/web/src/api/getContactChannelTopicAssetUrl.js index 6051f74b..ec531c2b 100644 --- a/net/web/src/api/getContactChannelTopicAssetUrl.js +++ b/net/web/src/api/getContactChannelTopicAssetUrl.js @@ -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}` } diff --git a/net/web/src/api/getContactChannelTopics.js b/net/web/src/api/getContactChannelTopics.js index cf55dd36..df5d621a 100644 --- a/net/web/src/api/getContactChannelTopics.js +++ b/net/web/src/api/getContactChannelTopics.js @@ -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 { diff --git a/net/web/src/api/getContactChannels.js b/net/web/src/api/getContactChannels.js index 3edd9b1c..d4769672 100644 --- a/net/web/src/api/getContactChannels.js +++ b/net/web/src/api/getContactChannels.js @@ -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() } diff --git a/net/web/src/api/getContactProfile.js b/net/web/src/api/getContactProfile.js index 611f42fb..2d9577d9 100644 --- a/net/web/src/api/getContactProfile.js +++ b/net/web/src/api/getContactProfile.js @@ -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() } diff --git a/net/web/src/api/getListing.js b/net/web/src/api/getListing.js index e6a31f8e..4a77ff10 100644 --- a/net/web/src/api/getListing.js +++ b/net/web/src/api/getListing.js @@ -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(); } diff --git a/net/web/src/api/getListingImageUrl.js b/net/web/src/api/getListingImageUrl.js index d972ddb4..9399b0db 100644 --- a/net/web/src/api/getListingImageUrl.js +++ b/net/web/src/api/getListingImageUrl.js @@ -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` } diff --git a/net/web/src/api/getListingMessage.js b/net/web/src/api/getListingMessage.js index aebad94b..1bd9eba4 100644 --- a/net/web/src/api/getListingMessage.js +++ b/net/web/src/api/getListingMessage.js @@ -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(); } diff --git a/net/web/src/api/removeContactChannel.js b/net/web/src/api/removeContactChannel.js index 4ee6f5a5..fc3c38c6 100644 --- a/net/web/src/api/removeContactChannel.js +++ b/net/web/src/api/removeContactChannel.js @@ -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); } diff --git a/net/web/src/api/removeContactChannelTopic.js b/net/web/src/api/removeContactChannelTopic.js index 1d5a2efa..ffd46a31 100644 --- a/net/web/src/api/removeContactChannelTopic.js +++ b/net/web/src/api/removeContactChannelTopic.js @@ -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); } diff --git a/net/web/src/api/setCardCloseMessage.js b/net/web/src/api/setCardCloseMessage.js index 4e0a64b2..f479224e 100644 --- a/net/web/src/api/setCardCloseMessage.js +++ b/net/web/src/api/setCardCloseMessage.js @@ -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(); } diff --git a/net/web/src/api/setCardOpenMessage.js b/net/web/src/api/setCardOpenMessage.js index b9e39884..f89bcd93 100644 --- a/net/web/src/api/setCardOpenMessage.js +++ b/net/web/src/api/setCardOpenMessage.js @@ -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(); } diff --git a/net/web/src/api/setContactChannelTopicAsset.js b/net/web/src/api/setContactChannelTopicAsset.js index 333c3b6c..eda4244a 100644 --- a/net/web/src/api/setContactChannelTopicAsset.js +++ b/net/web/src/api/setContactChannelTopicAsset.js @@ -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 { diff --git a/net/web/src/api/setContactChannelTopicSubject.js b/net/web/src/api/setContactChannelTopicSubject.js index 26cd412f..dce13224 100644 --- a/net/web/src/api/setContactChannelTopicSubject.js +++ b/net/web/src/api/setContactChannelTopicSubject.js @@ -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); } diff --git a/net/web/src/context/useUploadContext.hook.js b/net/web/src/context/useUploadContext.hook.js index 4331cd79..eb01c7fe 100644 --- a/net/web/src/context/useUploadContext.hook.js +++ b/net/web/src/context/useUploadContext.hook.js @@ -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,