mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 21:19:16 +00:00
supporting non-federated config
This commit is contained in:
parent
9f134f9644
commit
89bd4d9361
@ -3,7 +3,7 @@ import { RegistryWrapper, RegistryItem } from './Registry.styled';
|
|||||||
import { useRegistry } from './useRegistry.hook';
|
import { useRegistry } from './useRegistry.hook';
|
||||||
import { Button, Input, List } from 'antd';
|
import { Button, Input, List } from 'antd';
|
||||||
import { Logo } from '../../../../../Logo/Logo';
|
import { Logo } from '../../../../../Logo/Logo';
|
||||||
import { MoreOutlined } from '@ant-design/icons';
|
import { SearchOutlined, MoreOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
export function Registry() {
|
export function Registry() {
|
||||||
|
|
||||||
@ -22,8 +22,17 @@ export function Registry() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<RegistryWrapper>
|
<RegistryWrapper>
|
||||||
<Input.Search placeholder="Server" value={state.server} onChange={(e) => actions.setServer(e.target.value)}
|
{ state.server && (
|
||||||
onSearch={actions.getRegistry} style={{ width: '100%' }} />
|
<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">
|
<div class="contacts">
|
||||||
<List
|
<List
|
||||||
locale={{ emptyText: '' }}
|
locale={{ emptyText: '' }}
|
||||||
|
@ -9,6 +9,23 @@ export const RegistryWrapper = styled.div`
|
|||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
flex-direction: column;
|
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 {
|
.contacts {
|
||||||
flex-grow: 1
|
flex-grow: 1
|
||||||
background-color: #fefefe;
|
background-color: #fefefe;
|
||||||
|
@ -22,7 +22,12 @@ export function useRegistry() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (profile?.state?.profile) {
|
if (profile?.state?.profile) {
|
||||||
let identity = 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]);
|
}, [profile]);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithCustomTimeout } from './fetchUtil';
|
||||||
var base64 = require('base-64');
|
var base64 = require('base-64');
|
||||||
|
|
||||||
export async function addAccount(username, password, token) {
|
export async function addAccount(username, password, token) {
|
||||||
@ -8,7 +8,7 @@ export async function addAccount(username, password, token) {
|
|||||||
}
|
}
|
||||||
let headers = new Headers()
|
let headers = new Headers()
|
||||||
headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password));
|
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);
|
checkResponse(profile);
|
||||||
return await profile.json()
|
return await profile.json()
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
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 host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`
|
||||||
|
}
|
||||||
|
|
||||||
if (message == null && (assets == null || assets.length == 0)) {
|
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({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -14,14 +18,14 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), 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) });
|
{ method: 'POST', body: JSON.stringify(subject) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
return slot.id;
|
return slot.id;
|
||||||
}
|
}
|
||||||
else {
|
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({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -33,7 +37,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.image);
|
formData.append('asset', asset.image);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -48,7 +52,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
formData.append('asset', asset.video);
|
formData.append('asset', asset.video);
|
||||||
let thumb = "vthumb;video;" + asset.position
|
let thumb = "vthumb;video;" + asset.position
|
||||||
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
|
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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -63,7 +67,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.audio);
|
formData.append('asset', asset.audio);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["acopy;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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -79,11 +83,11 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
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}`,
|
let unconfirmed = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(unconfirmed);
|
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') });
|
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||||
checkResponse(confirmed);
|
checkResponse(confirmed);
|
||||||
return slot.id;
|
return slot.id;
|
||||||
|
@ -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))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelDetail(server, token, channelId) {
|
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)
|
checkResponse(detail)
|
||||||
return await detail.json()
|
return await detail.json()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelSummary(server, token, channelId) {
|
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)
|
checkResponse(summary)
|
||||||
return await summary.json()
|
return await summary.json()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelTopic(server, token, channelId, topicId) {
|
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' });
|
{ method: 'GET' });
|
||||||
checkResponse(topic)
|
checkResponse(topic)
|
||||||
return await topic.json()
|
return await topic.json()
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
export function getContactChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
|
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}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
|
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
let rev = ''
|
let rev = ''
|
||||||
if (revision != null) {
|
if (revision != null) {
|
||||||
rev = `&revision=${revision}`
|
rev = `&revision=${revision}`
|
||||||
@ -17,7 +22,7 @@ export async function getContactChannelTopics(server, token, channelId, revision
|
|||||||
if (end != null) {
|
if (end != null) {
|
||||||
edn = `&end=${end}`
|
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' });
|
{ method: 'GET' });
|
||||||
checkResponse(topics)
|
checkResponse(topics)
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannels(server, token, viewRevision, channelRevision) {
|
export async function getContactChannels(server, token, viewRevision, channelRevision) {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
let param = "?contact=" + token
|
let param = "?contact=" + token
|
||||||
if (viewRevision != null) {
|
if (viewRevision != null) {
|
||||||
param += '&viewRevision=' + viewRevision
|
param += '&viewRevision=' + viewRevision
|
||||||
@ -8,7 +13,7 @@ export async function getContactChannels(server, token, viewRevision, channelRev
|
|||||||
if (channelRevision != null) {
|
if (channelRevision != null) {
|
||||||
param += '&channelRevision=' + channelRevision
|
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)
|
checkResponse(channels)
|
||||||
return await channels.json()
|
return await channels.json()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactProfile(server, guid, token) {
|
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);
|
checkResponse(profile);
|
||||||
return await profile.json()
|
return await profile.json()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getListing(server) {
|
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);
|
checkResponse(listing);
|
||||||
return await listing.json();
|
return await listing.json();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
export function getListingImageUrl(server, guid) {
|
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`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getListingMessage(server, guid) {
|
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);
|
checkResponse(listing);
|
||||||
return await listing.json();
|
return await listing.json();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeContactChannel(server, token, channelId) {
|
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' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeContactChannelTopic(server, token, channelId, topicId) {
|
export async function removeContactChannelTopic(server, token, channelId, topicId) {
|
||||||
|
let host = "";
|
||||||
let channel = await fetchWithTimeout(`https://${server}//content/channels/${channelId}/topics/${topicId}?contact=${token}`,
|
if (server) {
|
||||||
|
host = `https://${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}?contact=${token}`,
|
||||||
{ method: 'DELETE' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setCardCloseMessage(server, message) {
|
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);
|
checkResponse(status);
|
||||||
return await status.json();
|
return await status.json();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setCardOpenMessage(server, message) {
|
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);
|
checkResponse(status);
|
||||||
return await status.json();
|
return await status.json();
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setContactChannelTopicSubject(server, token, channelId, topicId, asset) {
|
export async function setContactChannelTopicSubject(server, token, channelId, topicId, asset) {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (asset.image) {
|
if (asset.image) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.image);
|
formData.append('asset', asset.image);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
return {
|
return {
|
||||||
@ -20,7 +25,7 @@ export async function setContactChannelTopicSubject(server, token, channelId, to
|
|||||||
formData.append('asset', asset.video);
|
formData.append('asset', asset.video);
|
||||||
let thumb = "vthumb;video;" + asset.position
|
let thumb = "vthumb;video;" + asset.position
|
||||||
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
|
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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
return {
|
return {
|
||||||
@ -35,7 +40,7 @@ export async function setContactChannelTopicSubject(server, token, channelId, to
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.audio);
|
formData.append('asset', asset.audio);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["acopy;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);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
return {
|
return {
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setContactChannelTopicSubject(server, token, channelId, topicId, data) {
|
export async function setContactChannelTopicSubject(server, token, channelId, topicId, data) {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
let subject = { data: JSON.stringify(data, (key, value) => {
|
let subject = { data: JSON.stringify(data, (key, value) => {
|
||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), 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) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,14 @@ export function useUploadContext() {
|
|||||||
abort(`:${channelId}`, topicId);
|
abort(`:${channelId}`, topicId);
|
||||||
},
|
},
|
||||||
addContactTopic: (server, token, cardId, channelId, topicId, files, success, failure) => {
|
addContactTopic: (server, token, cardId, channelId, topicId, files, success, failure) => {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`
|
||||||
|
}
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const entry = {
|
const entry = {
|
||||||
index: index.current,
|
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,
|
files,
|
||||||
assets: [],
|
assets: [],
|
||||||
current: null,
|
current: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user