2020-06-19 06:57:57 +03:00
|
|
|
import "isomorphic-fetch";
|
2020-02-19 09:30:47 +03:00
|
|
|
|
2021-01-11 06:57:40 +03:00
|
|
|
import * as Websockets from "~/common/browser-websockets";
|
2020-06-19 06:57:57 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-02-19 09:30:47 +03:00
|
|
|
|
2021-01-14 09:30:26 +03:00
|
|
|
//NOTE(martina): call Websockets.checkWebsocket() before any api call that uses websockets to return updates
|
|
|
|
// to make sure that websockets are properly connected (and to reconnect them if they are not)
|
|
|
|
// otherwise updates may not occur properly
|
|
|
|
|
2020-02-19 09:30:47 +03:00
|
|
|
const REQUEST_HEADERS = {
|
2020-06-19 06:57:57 +03:00
|
|
|
Accept: "application/json",
|
|
|
|
"Content-Type": "application/json",
|
2020-02-19 09:30:47 +03:00
|
|
|
};
|
|
|
|
|
2020-08-07 05:17:49 +03:00
|
|
|
const DEFAULT_OPTIONS = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
};
|
|
|
|
|
2020-10-31 02:12:20 +03:00
|
|
|
const CORS_OPTIONS = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "omit",
|
|
|
|
};
|
|
|
|
|
2020-08-07 05:17:49 +03:00
|
|
|
const returnJSON = async (route, options) => {
|
|
|
|
const response = await fetch(route, options);
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2020-08-19 21:17:12 +03:00
|
|
|
export const health = async (data = {}) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-12 11:22:28 +03:00
|
|
|
return await returnJSON(`/api/_`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-08-19 21:17:12 +03:00
|
|
|
body: JSON.stringify({ data: { buckets: data.buckets } }),
|
2020-08-12 11:22:28 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-07-22 09:04:54 +03:00
|
|
|
export const sendFilecoin = async (data) => {
|
2020-04-09 00:29:13 +03:00
|
|
|
if (Strings.isEmpty(data.source)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Strings.isEmpty(data.target)) {
|
|
|
|
return null;
|
2020-02-19 09:30:47 +03:00
|
|
|
}
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
if (!data.amount) {
|
|
|
|
return null;
|
2020-02-19 09:30:47 +03:00
|
|
|
}
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/addresses/send`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-08-27 07:24:49 +03:00
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-02 11:33:39 +03:00
|
|
|
export const checkUsername = async (data) => {
|
|
|
|
return await returnJSON(`/api/users/check`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-23 14:17:56 +03:00
|
|
|
export const archive = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-28 09:57:04 +03:00
|
|
|
return await returnJSON(`/api/data/archive`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-09-23 14:17:56 +03:00
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const removeFromBucket = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-09-23 14:17:56 +03:00
|
|
|
return await returnJSON(`/api/data/bucket-remove`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
2020-08-28 09:57:04 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-28 01:05:20 +03:00
|
|
|
export const getNetworkDirectory = async () => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-28 01:05:20 +03:00
|
|
|
return await returnJSON(`/api/directory`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-03 09:00:02 +03:00
|
|
|
export const getSlateById = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-09-03 09:00:02 +03:00
|
|
|
return await returnJSON(`/api/slates/get`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-22 09:04:54 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-02-19 09:30:47 +03:00
|
|
|
};
|
2020-07-17 13:24:20 +03:00
|
|
|
|
2020-11-17 10:12:35 +03:00
|
|
|
export const getSlatesByIds = async (data) => {
|
2021-01-24 09:20:57 +03:00
|
|
|
return await returnJSON(`/api/slates/get`, {
|
2021-01-24 04:18:04 +03:00
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSocial = async (data) => {
|
2021-01-24 09:20:57 +03:00
|
|
|
return await returnJSON(`/api/users/get-social`, {
|
2020-11-17 10:12:35 +03:00
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-12-14 19:51:14 +03:00
|
|
|
export const deleteTrustRelationship = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-12-14 19:51:14 +03:00
|
|
|
return await returnJSON(`/api/users/trust-delete`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateTrustRelationship = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-12-14 19:51:14 +03:00
|
|
|
return await returnJSON(`/api/users/trust-update`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createTrustRelationship = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-12-14 19:51:14 +03:00
|
|
|
return await returnJSON(`/api/users/trust`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
2020-08-26 06:13:06 +03:00
|
|
|
|
|
|
|
export const createSubscription = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-26 06:13:06 +03:00
|
|
|
return await returnJSON(`/api/subscribe`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-26 04:27:05 +03:00
|
|
|
export const search = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-11-12 00:08:59 +03:00
|
|
|
if (Strings.isEmpty(data.query)) {
|
2020-08-26 06:13:06 +03:00
|
|
|
return { decorator: "NO_SERVER_TRIP", data: { results: [] } };
|
2020-08-26 04:27:05 +03:00
|
|
|
}
|
2020-11-16 11:18:02 +03:00
|
|
|
|
2020-11-12 00:08:59 +03:00
|
|
|
if (Strings.isEmpty(data.resourceURI)) {
|
|
|
|
return { decorator: "NO_RESOURCE_URI", data: { results: [] } };
|
|
|
|
}
|
2020-08-26 04:27:05 +03:00
|
|
|
|
2020-11-11 05:38:22 +03:00
|
|
|
return await returnJSON(`${data.resourceURI}/search`, {
|
2020-10-31 02:12:20 +03:00
|
|
|
...CORS_OPTIONS,
|
2020-11-10 00:20:38 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-26 04:27:05 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
export const createPendingFiles = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-10-05 00:30:28 +03:00
|
|
|
return await returnJSON(`/api/data/create-pending`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-11-28 04:30:40 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-10-05 00:30:28 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-28 04:30:40 +03:00
|
|
|
export const processPendingFiles = async () => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-09-21 06:58:15 +03:00
|
|
|
return await returnJSON(`/api/data/process-pending`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-11-28 04:30:40 +03:00
|
|
|
body: JSON.stringify(),
|
2020-09-21 06:58:15 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-23 23:52:00 +03:00
|
|
|
export const addFileToSlate = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-09-23 23:52:00 +03:00
|
|
|
return await returnJSON(`/api/slates/add-url`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-11-28 04:30:40 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-09-23 23:52:00 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-07-22 07:11:13 +03:00
|
|
|
export const updateViewer = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/users/update`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-11-28 04:30:40 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-22 07:11:13 +03:00
|
|
|
};
|
2020-07-21 14:36:50 +03:00
|
|
|
|
|
|
|
export const signIn = async (data) => {
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/sign-in`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-21 14:36:50 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-21 14:36:50 +03:00
|
|
|
};
|
|
|
|
|
2020-07-22 08:53:29 +03:00
|
|
|
export const hydrateAuthenticatedUser = async () => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/hydrate`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
});
|
2020-07-17 13:24:20 +03:00
|
|
|
};
|
|
|
|
|
2020-07-22 08:53:29 +03:00
|
|
|
export const deleteViewer = async () => {
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/users/delete`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
});
|
2020-07-17 13:24:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const createUser = async (data) => {
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/users/create`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-10-26 00:11:27 +03:00
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:22:17 +03:00
|
|
|
export const updateStatus = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-12-09 07:22:17 +03:00
|
|
|
return await returnJSON(`/api/users/status-update`, {
|
2020-10-26 00:11:27 +03:00
|
|
|
...DEFAULT_OPTIONS,
|
2020-11-10 00:20:38 +03:00
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateSearch = async (data) => {
|
|
|
|
return await returnJSON(`/api/search/update`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-17 13:24:20 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-17 13:24:20 +03:00
|
|
|
};
|
|
|
|
|
2020-07-24 10:45:21 +03:00
|
|
|
export const checkCIDStatus = async (data) => {
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/data/cid-status`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-24 10:45:21 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-24 10:45:21 +03:00
|
|
|
};
|
|
|
|
|
2020-07-25 03:19:12 +03:00
|
|
|
export const createSlate = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/slates/create`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-25 03:19:12 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-25 03:19:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const updateSlate = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/slates/update`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-25 03:19:12 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
|
|
|
};
|
2020-07-25 03:19:12 +03:00
|
|
|
|
2020-08-07 05:17:49 +03:00
|
|
|
export const deleteSlate = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/slates/delete`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
2020-07-25 03:19:12 +03:00
|
|
|
};
|
2020-07-28 09:54:15 +03:00
|
|
|
|
2020-10-24 09:36:52 +03:00
|
|
|
export const removeFileFromSlate = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-10-24 09:36:52 +03:00
|
|
|
return await returnJSON(`/api/slates/remove`, {
|
2020-08-07 05:17:49 +03:00
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
2020-07-28 09:54:15 +03:00
|
|
|
|
2020-08-07 05:17:49 +03:00
|
|
|
export const generateAPIKey = async () => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/keys/generate`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
});
|
2020-07-28 09:54:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteAPIKey = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-08-07 05:17:49 +03:00
|
|
|
return await returnJSON(`/api/keys/delete`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2020-07-28 09:54:15 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-08-07 05:17:49 +03:00
|
|
|
});
|
2020-07-28 09:54:15 +03:00
|
|
|
};
|
2020-08-12 11:22:28 +03:00
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
export const addCIDToData = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-10-05 00:30:28 +03:00
|
|
|
return await returnJSON(`/api/data/add`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-16 03:29:13 +03:00
|
|
|
export const updateData = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-11-16 03:29:13 +03:00
|
|
|
return await returnJSON(`/api/data/update`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
2021-01-09 07:13:00 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleFilePrivacy = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2021-01-09 07:13:00 +03:00
|
|
|
return await returnJSON(`/api/data/toggle-privacy`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
2020-11-16 03:29:13 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-18 06:40:10 +03:00
|
|
|
export const deleteBucketItems = async (data) => {
|
2021-01-11 06:57:40 +03:00
|
|
|
await Websockets.checkWebsocket();
|
2020-10-21 23:06:44 +03:00
|
|
|
return await returnJSON(`/api/data/remove`, {
|
2020-09-18 06:40:10 +03:00
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-03 06:26:56 +03:00
|
|
|
export const getSerializedSlate = async (data) => {
|
|
|
|
return await returnJSON(`/api/slates/get-serialized`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSerializedProfile = async (data) => {
|
|
|
|
return await returnJSON(`/api/users/get-serialized`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
2020-09-17 02:26:15 +03:00
|
|
|
|
|
|
|
export const createSupportMessage = async (data) => {
|
|
|
|
return await returnJSON(`/api/support-message`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
2020-12-04 02:34:19 +03:00
|
|
|
|
2021-01-14 09:30:26 +03:00
|
|
|
export const getActivity = async (data) => {
|
2020-12-04 02:34:19 +03:00
|
|
|
return await returnJSON(`/api/activity/get`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
2021-01-14 09:30:26 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-12-04 02:34:19 +03:00
|
|
|
});
|
|
|
|
};
|
2020-12-25 02:44:47 +03:00
|
|
|
|
2020-12-25 02:52:34 +03:00
|
|
|
export const getZipFilePaths = async (data) => {
|
2020-12-25 02:44:47 +03:00
|
|
|
return await returnJSON(`api/zip/get-paths`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
});
|
|
|
|
};
|
2021-01-21 04:07:40 +03:00
|
|
|
|
|
|
|
export const cleanDatabase = async () => {
|
|
|
|
return await returnJSON(`api/clean-up/users`, {
|
|
|
|
...DEFAULT_OPTIONS,
|
|
|
|
});
|
|
|
|
};
|