Skip to content

Commit

Permalink
Merge branch 'http' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandosborne committed May 7, 2024
2 parents 380bc0d + 9480095 commit bbcb973
Show file tree
Hide file tree
Showing 90 changed files with 338 additions and 108 deletions.
4 changes: 3 additions & 1 deletion app/mobile/src/api/addAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { checkResponse, fetchWithCustomTimeout } from './fetchUtil';
import base64 from 'react-native-base64'

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 = "";
if (token) {
access = `?token=${token}`
}
let headers = new Headers()
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);
return await profile.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addAccountAccess.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await access.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addAccountCreate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await access.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addCall.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await call.json();
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await card.json();
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addChannel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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 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);
return await channel.json();
}
Expand Down
18 changes: 10 additions & 8 deletions app/mobile/src/api/addChannelTopic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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)) {
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({}) });
checkResponse(topic);
let slot = await topic.json();
Expand All @@ -14,15 +16,15 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
if (value !== null) return value
}), 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) });
checkResponse(topic);
let slot = await topic.json();
return slot.id;
}
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({}) });
checkResponse(topic);
let slot = await topic.json();
Expand All @@ -34,7 +36,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
const formData = new FormData();
formData.append('asset', asset.image);
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&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);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -49,7 +51,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
formData.append('asset', asset.video);
let thumb = 'vthumb;video;' + asset.position;
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);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -64,7 +66,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
const formData = new FormData();
formData.append('asset', asset.audio);
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&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);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -80,11 +82,11 @@ export async function addChannelTopic(server, token, channelId, messageType, mes
if (value !== null) return value
}), 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) });
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') });
checkResponse(confirmed);
return slot.id;
Expand Down
19 changes: 11 additions & 8 deletions app/mobile/src/api/addContactChannelTopic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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)) {
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({}) });
checkResponse(topic);
let slot = await topic.json();
Expand All @@ -13,14 +16,14 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
if (value !== null) return value
}), 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) });
checkResponse(topic);
let slot = await topic.json();
return slot.id;
}
else {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}`,
{ method: 'POST', body: JSON.stringify({}) });
checkResponse(topic);
let slot = await topic.json();
Expand All @@ -32,7 +35,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
const formData = new FormData();
formData.append('asset', asset.image);
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -47,7 +50,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
formData.append('asset', asset.video);
let thumb = "vthumb;video;" + asset.position
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -62,7 +65,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
const formData = new FormData();
formData.append('asset', asset.audio);
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
checkResponse(topicAsset);
let assetEntry = await topicAsset.json();
message.assets.push({
Expand All @@ -78,11 +81,11 @@ export async function addContactChannelTopic(server, token, channelId, messageTy
if (value !== null) return value
}), 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) });
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') });
checkResponse(confirmed);
return slot.id;
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/addContactRing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
}

6 changes: 4 additions & 2 deletions app/mobile/src/api/addFlag.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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) {
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);
}
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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/clearChannelCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await channel.json();
}
4 changes: 3 additions & 1 deletion app/mobile/src/api/clearLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64'

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)
}
2 changes: 2 additions & 0 deletions app/mobile/src/api/createAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
import base64 from 'react-native-base64'

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()
headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password));
let profile = await fetchWithTimeout("/account/profile", { method: 'POST', headers: headers })
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/getAccountImageUrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
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}`
}

4 changes: 3 additions & 1 deletion app/mobile/src/api/getAccountStatus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await status.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/getAvailable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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)
return await available.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/getCard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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 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);
return await card.json()
}
Expand Down
4 changes: 3 additions & 1 deletion app/mobile/src/api/getCardCloseMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

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);
return await message.json();
}
Expand Down
Loading

0 comments on commit bbcb973

Please sign in to comment.