allowing for http protocol

This commit is contained in:
Roland Osborne 2024-05-03 14:32:23 -07:00
parent aab471eed7
commit b3ad138fa3
83 changed files with 308 additions and 99 deletions

View File

@ -2,13 +2,15 @@ import { checkResponse, fetchWithCustomTimeout } from './fetchUtil';
import base64 from 'react-native-base64' import base64 from 'react-native-base64'
export async function addAccount(server, username, password, token) { export async function addAccount(server, username, password, token) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let access = ""; let access = "";
if (token) { if (token) {
access = `?token=${token}` access = `?token=${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 fetchWithCustomTimeout(`https://${server}/account/profile${access}`, { method: 'POST', headers: headers }, 60000) let profile = await fetchWithCustomTimeout(`${protocol}://${server}/account/profile${access}`, { method: 'POST', headers: headers }, 60000)
checkResponse(profile); checkResponse(profile);
return await profile.json() return await profile.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addAccountAccess(server, token, accountId) { export async function addAccountAccess(server, token, accountId) {
let access = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}/auth?token=${token}`, { method: 'POST' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let access = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}/auth?token=${token}`, { method: 'POST' })
checkResponse(access); checkResponse(access);
return await access.json() return await access.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addAccountCreate(server, token) { export async function addAccountCreate(server, token) {
let access = await fetchWithTimeout(`https://${server}/admin/accounts?token=${token}`, { method: 'POST' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let access = await fetchWithTimeout(`${protocol}://${server}/admin/accounts?token=${token}`, { method: 'POST' })
checkResponse(access); checkResponse(access);
return await access.json() return await access.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addCall(server, token, cardId) { export async function addCall(server, token, cardId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls?agent=${token}`, { method: 'POST', body: JSON.stringify(cardId)} ); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls?agent=${token}`, { method: 'POST', body: JSON.stringify(cardId)} );
checkResponse(call); checkResponse(call);
return await call.json(); return await call.json();
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addCard(server, token, message) { export async function addCard(server, token, message) {
let card = await fetchWithTimeout(`https://${server}/contact/cards?agent=${token}`, { method: 'POST', body: JSON.stringify(message)} ); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards?agent=${token}`, { method: 'POST', body: JSON.stringify(message)} );
checkResponse(card); checkResponse(card);
return await card.json(); return await card.json();
} }

View File

@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addChannel(server, token, type, data, cards ) { export async function addChannel(server, token, type, data, cards ) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let params = { dataType: type, data: JSON.stringify(data), groups: [], cards }; let params = { dataType: type, data: JSON.stringify(data), groups: [], cards };
let channel = await fetchWithTimeout(`https://${server}/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} ); let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} );
checkResponse(channel); checkResponse(channel);
return await channel.json(); return await channel.json();
} }

View File

@ -1,9 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addChannelTopic(server, token, channelId, messageType, message, assets ): string { export async function addChannelTopic(server, token, channelId, messageType, message, assets ): string {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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?agent=${token}`, let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${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,7 +16,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
if (value !== null) return value if (value !== null) return value
}), datatype: messageType }; }), datatype: messageType };
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}&confirm=true`, let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${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();
@ -22,7 +24,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
} }
else { else {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}`, let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${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();
@ -34,7 +36,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
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}&agent=${token}`, { method: 'POST', body: formData }); let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${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({
@ -49,7 +51,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
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(["vlq;video", "vhd;video", thumb])); let transform = encodeURIComponent(JSON.stringify(["vlq;video", "vhd;video", thumb]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${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({
@ -64,7 +66,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
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}&agent=${token}`, { method: 'POST', body: formData }); let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${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({
@ -80,11 +82,11 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
if (value !== null) return value if (value !== null) return value
}), datatype: messageType }; }), datatype: messageType };
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`, let unconfirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/subject?agent=${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?agent=${token}`, let confirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
{ method: 'PUT', body: JSON.stringify('confirmed') }); { method: 'PUT', body: JSON.stringify('confirmed') });
checkResponse(confirmed); checkResponse(confirmed);
return slot.id; return slot.id;

View File

@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addContactChannelTopic(server, token, channelId, messageType, message, assets ) { export async function addContactChannelTopic(server, token, channelId, messageType, message, assets ) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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(`${protocol}://${server}/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();
@ -13,14 +16,14 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
if (value !== null) return value if (value !== null) return value
}), datatype: messageType }; }), datatype: messageType };
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`, let topic = await fetchWithTimeout(`${protocol}://${server}/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(`${protocol}://${server}/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();
@ -32,7 +35,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
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(`${protocol}://${server}/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({
@ -47,7 +50,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
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(`${protocol}://${server}/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({
@ -62,7 +65,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
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(`${protocol}://${server}/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({
@ -78,11 +81,11 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
if (value !== null) return value if (value !== null) return value
}), datatype: messageType }; }), datatype: messageType };
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`, let unconfirmed = await fetchWithTimeout(`${protocol}://${server}/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(`${protocol}://${server}/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;

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addContactRing(server, token, call) { export async function addContactRing(server, token, call) {
let ring = await fetchWithTimeout(`https://${server}/talk/rings?contact=${token}`, { method: 'POST', body: JSON.stringify(call) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let ring = await fetchWithTimeout(`${protocol}://${server}/talk/rings?contact=${token}`, { method: 'POST', body: JSON.stringify(call) });
checkResponse(ring); checkResponse(ring);
} }

View File

@ -1,13 +1,15 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addFlag(server, guid, channel, topic) { export async function addFlag(server, guid, channel, topic) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
if (channel) { if (channel) {
const param = topic ? `&topic=${topic}` : ''; const param = topic ? `&topic=${topic}` : '';
const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}?channel=${channel}${param}`, { method: 'POST' } ); const flag = await fetchWithTimeout(`${protocol}://${server}/account/flag/${guid}?channel=${channel}${param}`, { method: 'POST' } );
checkResponse(flag); checkResponse(flag);
} }
else { else {
const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}`, { method: 'POST' } ); const flag = await fetchWithTimeout(`${protocol}://${server}/account/flag/${guid}`, { method: 'POST' } );
checkResponse(flag); checkResponse(flag);
} }
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function clearChannelCard(server, token, channelId, cardId ) { export async function clearChannelCard(server, token, channelId, cardId ) {
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'}); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'});
checkResponse(channel); checkResponse(channel);
return await channel.json(); return await channel.json();
} }

View File

@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64' import base64 from 'react-native-base64'
export async function clearLogin(server, token) { export async function clearLogin(server, token) {
let logout = await fetchWithTimeout(`https://${server}/account/apps?agent=${token}`, { method: 'DELETE' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let logout = await fetchWithTimeout(`${protocol}://${server}/account/apps?agent=${token}`, { method: 'DELETE' })
checkResponse(logout) checkResponse(logout)
} }

View File

@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64' import base64 from 'react-native-base64'
export async function createAccount(username, password) { export async function createAccount(username, password) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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", { method: 'POST', headers: headers }) let profile = await fetchWithTimeout("/account/profile", { method: 'POST', headers: headers })

View File

@ -1,4 +1,6 @@
export function getAccountImageUrl(server, token, accountId) { export function getAccountImageUrl(server, token, accountId) {
return `https://${server}/admin/accounts/${accountId}/image?token=${token}` const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
return `${protocol}://${server}/admin/accounts/${accountId}/image?token=${token}`
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getAccountStatus(server, token) { export async function getAccountStatus(server, token) {
let status = await fetchWithTimeout(`https://${server}/account/status?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let status = await fetchWithTimeout(`${protocol}://${server}/account/status?agent=${token}`, { method: 'GET' });
checkResponse(status); checkResponse(status);
return await status.json() return await status.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getAvailable(server) { export async function getAvailable(server) {
let available = await fetchWithTimeout(`https://${server}/account/available`, { method: 'GET' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let available = await fetchWithTimeout(`${protocol}://${server}/account/available`, { method: 'GET' })
checkResponse(available) checkResponse(available)
return await available.json() return await available.json()
} }

View File

@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCard(server, token, cardId) { export async function getCard(server, token, cardId) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "?agent=" + token let param = "?agent=" + token
let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}${param}`, { method: 'GET' }); let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}${param}`, { method: 'GET' });
checkResponse(card); checkResponse(card);
return await card.json() return await card.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCardCloseMessage(server, token, cardId) { export async function getCardCloseMessage(server, token, cardId) {
let message = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/closeMessage?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let message = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/closeMessage?agent=${token}`, { method: 'GET' });
checkResponse(message); checkResponse(message);
return await message.json(); return await message.json();
} }

View File

@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCardDetail(server, token, cardId) { export async function getCardDetail(server, token, cardId) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "?agent=" + token let param = "?agent=" + token
let detail = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/detail${param}`, { method: 'GET' }); let detail = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/detail${param}`, { method: 'GET' });
checkResponse(detail); checkResponse(detail);
return await detail.json() return await detail.json()
} }

View File

@ -1,4 +1,6 @@
export function getCardImageUrl(server, token, cardId, revision) { export function getCardImageUrl(server, token, cardId, revision) {
return `https://${server}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}` const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
return `${protocol}://${server}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}`
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCardOpenMessage(server, token, cardId) { export async function getCardOpenMessage(server, token, cardId) {
let message = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/openMessage?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let message = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/openMessage?agent=${token}`, { method: 'GET' });
checkResponse(message); checkResponse(message);
return await message.json(); return await message.json();
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCardProfile(server, token, cardId) { export async function getCardProfile(server, token, cardId) {
let profile = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'GET' });
checkResponse(profile); checkResponse(profile);
return await profile.json() return await profile.json()
} }

View File

@ -1,11 +1,13 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getCards(server, token, revision) { export async function getCards(server, token, revision) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "agent=" + token let param = "agent=" + token
if (revision != null) { if (revision != null) {
param += '&revision=' + revision param += '&revision=' + revision
} }
let cards = await fetchWithTimeout(`https://${server}/contact/cards?${param}`, { method: 'GET' }); let cards = await fetchWithTimeout(`${protocol}://${server}/contact/cards?${param}`, { method: 'GET' });
checkResponse(cards) checkResponse(cards)
return await cards.json() return await cards.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannelDetail(server, token, channelId) { export async function getChannelDetail(server, token, channelId) {
let detail = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/detail?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let detail = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/detail?agent=${token}`, { method: 'GET' });
checkResponse(detail) checkResponse(detail)
return await detail.json() return await detail.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannelNotifications(server, token, channelId) { export async function getChannelNotifications(server, token, channelId) {
const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'GET' });
checkResponse(notify) checkResponse(notify)
return await notify.json() return await notify.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannelSummary(server, token, channelId) { export async function getChannelSummary(server, token, channelId) {
let summary = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/summary?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let summary = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/summary?agent=${token}`, { method: 'GET' });
checkResponse(summary) checkResponse(summary)
return await summary.json() return await summary.json()
} }

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannelTopic(server, token, channelId, topicId) { export async function getChannelTopic(server, token, channelId, topicId) {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`, const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`,
{ method: 'GET' }); { method: 'GET' });
checkResponse(topic) checkResponse(topic)
return await topic.json() return await topic.json()

View File

@ -1,4 +1,6 @@
export function getChannelTopicAssetUrl(server, token, channelId, topicId, assetId) { export function getChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}` const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
return `${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}`
} }

View File

@ -1,6 +1,8 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannelTopics(server, token, channelId, revision, count, begin, end) { export async function getChannelTopics(server, token, channelId, revision, count, begin, end) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let rev = '' let rev = ''
if (revision != null) { if (revision != null) {
@ -18,7 +20,7 @@ export async function getChannelTopics(server, token, channelId, revision, count
if (end != null) { if (end != null) {
edn = `&end=${end}` edn = `&end=${end}`
} }
let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`, let topics = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`,
{ method: 'GET' }); { method: 'GET' });
checkResponse(topics) checkResponse(topics)
return { return {

View File

@ -1,12 +1,14 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getChannels(server, token, revision) { export async function getChannels(server, token, revision) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "?agent=" + token let param = "?agent=" + token
if (revision != null) { if (revision != null) {
param += `&channelRevision=${revision}` param += `&channelRevision=${revision}`
} }
param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`; param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`;
let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' }); let channels = await fetchWithTimeout(`${protocol}://${server}/content/channels${param}`, { method: 'GET' });
checkResponse(channels) checkResponse(channels)
let ret = await channels.json() let ret = await channels.json()
return ret; return ret;

View File

@ -1,9 +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) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let host = ""; let host = "";
if (server) { if (server) {
host = `https://${server}`; host = `${protocol}://${server}`;
} }
let detail = await fetchWithTimeout(`${host}/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' }); let detail = await fetchWithTimeout(`${host}/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' });
checkResponse(detail) checkResponse(detail)

View File

@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelNotifications(server, token, channelId) { export async function getContactChannelNotifications(server, token, channelId) {
const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'GET' });
checkResponse(notify) checkResponse(notify)
return await notify.json() return await notify.json()
} }

View File

@ -1,9 +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) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let host = ""; let host = "";
if (server) { if (server) {
host = `https://${server}`; host = `${protocol}://${server}`;
} }
let summary = await fetchWithTimeout(`${host}/content/channels/${channelId}/summary?contact=${token}`, { method: 'GET' }); let summary = await fetchWithTimeout(`${host}/content/channels/${channelId}/summary?contact=${token}`, { method: 'GET' });
checkResponse(summary) checkResponse(summary)

View File

@ -1,7 +1,9 @@
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}`, const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
{ method: 'GET' }); { method: 'GET' });
checkResponse(topic) checkResponse(topic)
return await topic.json() return await topic.json()

View File

@ -1,4 +1,6 @@
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}` const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
return `${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}`
} }

View File

@ -1,6 +1,8 @@
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) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let rev = '' let rev = ''
if (revision != null) { if (revision != null) {
@ -18,7 +20,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(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`,
{ method: 'GET' }); { method: 'GET' });
checkResponse(topics) checkResponse(topics)

View File

@ -1,6 +1,9 @@
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) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "?contact=" + token let param = "?contact=" + token
if (viewRevision != null) { if (viewRevision != null) {
param += `&viewRevision=${viewRevision}`; param += `&viewRevision=${viewRevision}`;
@ -9,7 +12,7 @@ export async function getContactChannels(server, token, viewRevision, channelRev
param += `&channelRevision=${channelRevision}`; param += `&channelRevision=${channelRevision}`;
} }
param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`; param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`;
let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' }); let channels = await fetchWithTimeout(`${protocol}://${server}/content/channels${param}`, { method: 'GET' });
checkResponse(channels) checkResponse(channels)
return await channels.json() return await channels.json()
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactProfile(server, token) { export async function getContactProfile(server, token) {
let profile = await fetchWithTimeout(`https://${server}/profile/message?contact=${token}`, { method: 'GET', }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/profile/message?contact=${token}`, { method: 'GET', });
checkResponse(profile); checkResponse(profile);
return await profile.json() return await profile.json()
} }

View File

@ -1,11 +1,14 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getGroups(token, revision) { export async function getGroups(server, token, revision) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let param = "agent=" + token let param = "agent=" + token
if (revision != null) { if (revision != null) {
param += '&revision=' + revision param += '&revision=' + revision
} }
let groups = await fetchWithTimeout(`/alias/groups?${param}`, { method: 'GET' }); let groups = await fetchWithTimeout(`${protocol}://server/alias/groups?${param}`, { method: 'GET' });
checkResponse(groups) checkResponse(groups)
return await groups.json() return await groups.json()
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getHandle(server, token, name) { export async function getHandle(server, token, name) {
let available = await fetchWithTimeout(`https://${server}/account/username?agent=${token}&name=${encodeURIComponent(name)}`, { method: 'GET' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let available = await fetchWithTimeout(`${protocol}://${server}/account/username?agent=${token}&name=${encodeURIComponent(name)}`, { method: 'GET' })
checkResponse(available) checkResponse(available)
return await available.json() return await available.json()
} }

View File

@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getListing(server, filter) { export async function getListing(server, filter) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const param = filter ? `?filter=${filter}` : ''; const param = filter ? `?filter=${filter}` : '';
let listing = await fetchWithTimeout(`https://${server}/account/listing${param}`, { method: 'GET' }); let listing = await fetchWithTimeout(`${protocol}://${server}/account/listing${param}`, { method: 'GET' });
checkResponse(listing); checkResponse(listing);
return await listing.json(); return await listing.json();
} }

View File

@ -1,7 +1,10 @@
export function getListingImageUrl(server, guid) { export function getListingImageUrl(server, guid) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let host = ""; let host = "";
if (server) { if (server) {
host = `https://${server}`; host = `${protocol}://${server}`;
} }
return `${host}/account/listing/${guid}/image` return `${host}/account/listing/${guid}/image`

View File

@ -1,7 +1,10 @@
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' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let listing = await fetchWithTimeout(`${protocol}://${server}/account/listing/${guid}/message`, { method: 'GET' });
checkResponse(listing); checkResponse(listing);
return await listing.json(); return await listing.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getNodeAccounts(server, token) { export async function getNodeAccounts(server, token) {
let accounts = await fetchWithTimeout(`https://${server}/admin/accounts?token=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let accounts = await fetchWithTimeout(`${protocol}://${server}/admin/accounts?token=${token}`, { method: 'GET' });
checkResponse(accounts); checkResponse(accounts);
return await accounts.json(); return await accounts.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getNodeConfig(server, token) { export async function getNodeConfig(server, token) {
let config = await fetchWithTimeout(`https://${server}/admin/config?token=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let config = await fetchWithTimeout(`${protocol}://${server}/admin/config?token=${token}`, { method: 'GET' });
checkResponse(config); checkResponse(config);
return await config.json(); return await config.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getNodeStatus(server) { export async function getNodeStatus(server) {
let status = await fetchWithTimeout(`https://${server}/admin/status`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let status = await fetchWithTimeout(`${protocol}://${server}/admin/status`, { method: 'GET' });
checkResponse(status); checkResponse(status);
return await status.json(); return await status.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getProfile(server, token) { export async function getProfile(server, token) {
let profile = await fetchWithTimeout(`https://${server}/profile?agent=${token}`, { method: 'GET' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/profile?agent=${token}`, { method: 'GET' });
checkResponse(profile) checkResponse(profile)
return await profile.json() return await profile.json()
} }

View File

@ -1,4 +1,7 @@
export function getProfileImageUrl(server, token, revision) { export function getProfileImageUrl(server, token, revision) {
return `https://${server}/profile/image?agent=${token}&revision=${revision}`; const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
return `${protocol}://${server}/profile/image?agent=${token}&revision=${revision}`;
} }

View File

@ -1,6 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getUsername(name, server, token) { export async function getUsername(name, server, token) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let query = ""; let query = "";
if (token && name) { if (token && name) {
query = `?name=${encodeURIComponent(name)}&token=${token}`; query = `?name=${encodeURIComponent(name)}&token=${token}`;
@ -12,7 +15,7 @@ export async function getUsername(name, server, token) {
query = `?token=${token}`; query = `?token=${token}`;
} }
let available = await fetchWithTimeout(`https://${server}/account/username${query}`, { method: 'GET' }) let available = await fetchWithTimeout(`${protocol}://${server}/account/username${query}`, { method: 'GET' })
checkResponse(available) checkResponse(available)
return await available.json() return await available.json()
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function keepCall(server, token, callId) { export async function keepCall(server, token, callId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}`, { method: 'PUT' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?agent=${token}`, { method: 'PUT' });
checkResponse(call); checkResponse(call);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeAccount(server, token, accountId) { export async function removeAccount(server, token, accountId) {
let res = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}?token=${token}`, { method: 'DELETE' }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let res = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}?token=${token}`, { method: 'DELETE' })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeCall(server, token, callId) { export async function removeCall(server, token, callId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}`, { method: 'DELETE' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?agent=${token}`, { method: 'DELETE' });
checkResponse(call) checkResponse(call)
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeCard(server, token, cardId) { export async function removeCard(server, token, cardId) {
let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}?agent=${token}`, { method: 'DELETE' } ); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}?agent=${token}`, { method: 'DELETE' } );
checkResponse(card); checkResponse(card);
return await card.json(); return await card.json();
} }

View File

@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeChannel(server, token, channelId) { export async function removeChannel(server, token, channelId) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?agent=${token}`, let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}?agent=${token}`,
{ method: 'DELETE' }); { method: 'DELETE' });
checkResponse(channel); checkResponse(channel);
} }

View File

@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeChannelTopic(server, token, channelId, topicId) { export async function removeChannelTopic(server, token, channelId, topicId) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?agent=${token}`, let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}?agent=${token}`,
{ method: 'DELETE' }); { method: 'DELETE' });
checkResponse(channel); checkResponse(channel);
} }

View File

@ -1,6 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeContactCall(server, token, callId) { export async function removeContactCall(server, token, callId) {
const call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?contact=${token}`, { method: 'DELETE' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?contact=${token}`, { method: 'DELETE' });
checkResponse(call); checkResponse(call);
} }

View File

@ -1,7 +1,10 @@
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 channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?contact=${token}`, const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}?contact=${token}`,
{ method: 'DELETE' }); { method: 'DELETE' });
checkResponse(channel); checkResponse(channel);
} }

View File

@ -1,7 +1,10 @@
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 channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?contact=${token}`, const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}?contact=${token}`,
{ method: 'DELETE' }); { method: 'DELETE' });
checkResponse(channel); checkResponse(channel);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeProfile(server, token) { export async function removeProfile(server, token) {
let profile = await fetchWithTimeout(`https://${server}/profile?agent=${token}`, { method: 'DELETE' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/profile?agent=${token}`, { method: 'DELETE' });
checkResponse(profile) checkResponse(profile)
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountAccess(server, token, appName, appVersion, platform, deviceToken, pushType, notifications) { export async function setAccountAccess(server, token, appName, appVersion, platform, deviceToken, pushType, notifications) {
let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'PUT', body: JSON.stringify(notifications) }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let access = await fetchWithTimeout(`${protocol}://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'PUT', body: JSON.stringify(notifications) })
checkResponse(access) checkResponse(access)
return await access.json() return await access.json()
} }

View File

@ -2,9 +2,12 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64' import base64 from 'react-native-base64'
export async function setAccountLogin(server, token, username, password) { export async function setAccountLogin(server, token, username, password) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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 res = await fetchWithTimeout(`https://${server}/account/login?agent=${token}`, { method: 'PUT', headers }) let res = await fetchWithTimeout(`${protocol}://${server}/account/login?agent=${token}`, { method: 'PUT', headers })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountNotifications(server, token, flag) { export async function setAccountNotifications(server, token, flag) {
let res = await fetchWithTimeout(`https://${server}/account/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let res = await fetchWithTimeout(`${protocol}://${server}/account/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountSeal(server, token, seal) { export async function setAccountSeal(server, token, seal) {
let res = await fetchWithTimeout(`https://${server}/account/seal?agent=${token}`, { method: 'PUT', body: JSON.stringify(seal) }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let res = await fetchWithTimeout(`${protocol}://${server}/account/seal?agent=${token}`, { method: 'PUT', body: JSON.stringify(seal) })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountSearchable(server, token, flag) { export async function setAccountSearchable(server, token, flag) {
let res = await fetchWithTimeout(`https://${server}/account/searchable?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let res = await fetchWithTimeout(`${protocol}://${server}/account/searchable?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountStatus(server, token, accountId, disabled) { export async function setAccountStatus(server, token, accountId, disabled) {
let res = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}/status?token=${token}`, { method: 'PUT', body: JSON.stringify(disabled) }) const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let res = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}/status?token=${token}`, { method: 'PUT', body: JSON.stringify(disabled) })
checkResponse(res); checkResponse(res);
} }

View File

@ -1,7 +1,10 @@
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) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let status = await fetchWithTimeout(`${protocol}://${server}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) });
checkResponse(status); checkResponse(status);
return await status.json(); return await status.json();
} }

View File

@ -1,7 +1,10 @@
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) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let status = await fetchWithTimeout(`${protocol}://${server}/contact/openMessage`, { method: 'PUT', body: JSON.stringify(message) });
checkResponse(status); checkResponse(status);
return await status.json(); return await status.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setCardProfile(server, token, cardId, message) { export async function setCardProfile(server, token, cardId, message) {
let profile = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) });
checkResponse(profile); checkResponse(profile);
return await profile.json() return await profile.json()
} }

View File

@ -1,19 +1,22 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setCardConnecting(server, token, cardId) { export async function setCardConnecting(server, token, cardId) {
let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('connecting') } ); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('connecting') } );
checkResponse(card); checkResponse(card);
return await card.json(); return await card.json();
} }
export async function setCardConnected(server, token, cardId, access, view, article, channel, profile) { export async function setCardConnected(server, token, cardId, access, view, article, channel, profile) {
let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=${view}&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`, { method: 'PUT', body: JSON.stringify('connected') } ); let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=${view}&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`, { method: 'PUT', body: JSON.stringify('connected') } );
checkResponse(card); checkResponse(card);
return await card.json(); return await card.json();
} }
export async function setCardConfirmed(server, token, cardId) { export async function setCardConfirmed(server, token, cardId) {
let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') } ); let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') } );
checkResponse(card); checkResponse(card);
return await card.json(); return await card.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setChannelCard(server, token, channelId, cardId ) { export async function setChannelCard(server, token, channelId, cardId ) {
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'PUT'}); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'PUT'});
checkResponse(channel); checkResponse(channel);
return await channel.json(); return await channel.json();
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setChannelNotifications(server, token, channelId, flag) { export async function setChannelNotifications(server, token, channelId, flag) {
const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) });
checkResponse(notify) checkResponse(notify)
} }

View File

@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setChannelSubject(server, token, channelId, dataType, data ) { export async function setChannelSubject(server, token, channelId, dataType, data ) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let params = { dataType, data: JSON.stringify(data) }; let params = { dataType, data: JSON.stringify(data) };
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} ); let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
checkResponse(channel); checkResponse(channel);
return await channel.json(); return await channel.json();
} }

View File

@ -1,6 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setChannelTopicSubject(token, channelId, topicId, asset) { export async function setChannelTopicSubject(token, channelId, topicId, asset) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
if (asset.image) { if (asset.image) {
const formData = new FormData(); const formData = new FormData();
formData.append('asset', asset.image); formData.append('asset', asset.image);

View File

@ -1,11 +1,14 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setChannelTopicSubject(server, token, channelId, topicId, dataType, data) { export async function setChannelTopicSubject(server, token, channelId, topicId, dataType, data) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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: dataType }; }), datatype: dataType };
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`, let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`,
{ method: 'PUT', body: JSON.stringify(subject) }); { method: 'PUT', body: JSON.stringify(subject) });
checkResponse(channel); checkResponse(channel);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setContactChannelNotifications(server, token, channelId, flag) { export async function setContactChannelNotifications(server, token, channelId, flag) {
const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'PUT', body: JSON.stringify(flag) });
checkResponse(notify) checkResponse(notify)
} }

View File

@ -1,9 +1,12 @@
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) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let host = ""; let host = "";
if (server) { if (server) {
host = `https://${server}`; host = `${protocol}://${server}`;
} }
if (asset.image) { if (asset.image) {

View File

@ -1,11 +1,14 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setContactChannelTopicSubject(server, token, channelId, topicId, dataType, data) { export async function setContactChannelTopicSubject(server, token, channelId, topicId, dataType, data) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
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: dataType }; }), datatype: dataType };
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`, let channel = await fetchWithTimeout(`${protocol}://${server}/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);
} }

View File

@ -2,9 +2,12 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64' import base64 from 'react-native-base64'
export async function setLogin(username, server, password, appName, appVersion, platform, deviceToken, pushType, notifications) { export async function setLogin(username, server, password, appName, appVersion, platform, deviceToken, pushType, notifications) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let headers = new Headers() let headers = new Headers()
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password)); headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));
let login = await fetchWithTimeout(`https://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'POST', body: JSON.stringify(notifications), headers: headers }) let login = await fetchWithTimeout(`${protocol}://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'POST', body: JSON.stringify(notifications), headers: headers })
checkResponse(login) checkResponse(login)
return await login.json() return await login.json()
} }

View File

@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setNodeConfig(server, token, config) { export async function setNodeConfig(server, token, config) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let body = JSON.stringify(config); let body = JSON.stringify(config);
let settings = await fetchWithTimeout(`https://${server}/admin/config?token=${token}`, { method: 'PUT', body }); let settings = await fetchWithTimeout(`${protocol}://${server}/admin/config?token=${token}`, { method: 'PUT', body });
checkResponse(settings); checkResponse(settings);
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setNodeStatus(server, token) { export async function setNodeStatus(server, token) {
let status = await fetchWithTimeout(`https://${server}/admin/status?token=${token}`, { method: 'PUT' }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let status = await fetchWithTimeout(`${protocol}://${server}/admin/status?token=${token}`, { method: 'PUT' });
checkResponse(status); checkResponse(status);
} }

View File

@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setProfileData(server, token, name, location, description) { export async function setProfileData(server, token, name, location, description) {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let data = { name: name, location: location, description: description }; let data = { name: name, location: location, description: description };
let profile = await fetchWithTimeout(`https://${server}/profile/data?agent=${token}`, { method: 'PUT', body: JSON.stringify(data) }); let profile = await fetchWithTimeout(`${protocol}://${server}/profile/data?agent=${token}`, { method: 'PUT', body: JSON.stringify(data) });
checkResponse(profile) checkResponse(profile)
return await profile.json() return await profile.json()
} }

View File

@ -1,7 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil'; import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setProfileImage(server, token, image) { export async function setProfileImage(server, token, image) {
let profile = await fetchWithTimeout(`https://${server}/profile/image?agent=${token}`, { method: 'PUT', body: JSON.stringify(image) }); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
const protocol = insecure ? 'http' : 'https';
let profile = await fetchWithTimeout(`${protocol}://${server}/profile/image?agent=${token}`, { method: 'PUT', body: JSON.stringify(image) });
checkResponse(profile) checkResponse(profile)
return await profile.json() return await profile.json()
} }

View File

@ -25,7 +25,7 @@ export function useAddMember(item, members) {
useEffect(() => { useEffect(() => {
const { cardId, revision, profile } = item; const { cardId, revision, profile } = item;
const { name, handle, node } = profile; const { name, handle, node } = profile;
updateState({ cardId, name, handle: `${handle}@${node}`, updateState({ cardId, name, handle: `${handle}/${node}`,
logo: profile.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar' }); logo: profile.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar' });
}, [card.state]); }, [card.state]);