chore(env): remove EXTERNAL_RESOURCES and use new envs

This commit is contained in:
Aminejv 2021-08-04 18:59:25 +01:00
parent ed1888d5b1
commit edbd3b5e5a
18 changed files with 45 additions and 105 deletions

View File

@ -6,6 +6,7 @@ import * as Events from "~/common/custom-events";
import * as Websockets from "~/common/browser-websockets";
import * as Strings from "~/common/strings";
import * as Credentials from "~/common/credentials";
import * as Environment from "~/common/environment";
//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)
@ -48,15 +49,15 @@ const returnJSON = async (route, options) => {
}
};
export const createZipToken = async ({ files, resourceURI }) => {
return await returnJSON(`${resourceURI}/api/download/create-zip-token`, {
export const createZipToken = async (files) => {
return await returnJSON(`${Environment.URI_SHOVEL}/api/download/create-zip-token`, {
...CORS_OPTIONS,
body: JSON.stringify({ files }),
});
};
export const downloadZip = ({ token, name, resourceURI }) =>
`${resourceURI}/api/download/download-by-token?downloadId=${token}&name=${name}`;
export const downloadZip = ({ token, name }) =>
`${Environment.URI_SHOVEL}/api/download/download-by-token?downloadId=${token}&name=${name}`;
export const health = async (data = {}) => {
await Websockets.checkWebsocket();
@ -209,10 +210,7 @@ export const search = async (data) => {
return { decorator: "NO_SERVER_TRIP", data: { results: [] } };
}
if (Strings.isEmpty(data.resourceURI)) {
return { decorator: "NO_RESOURCE_URI", data: { results: [] } };
}
return await returnJSON(`${data.resourceURI}/search`, {
return await returnJSON(`${Environment.URI_LENS}/search`, {
...CORS_OPTIONS,
body: JSON.stringify({ data }),
});

View File

@ -1,15 +1,15 @@
import * as Actions from "~/common/actions";
import * as Store from "~/common/store";
import * as Constants from "~/common/constants";
import * as Credentials from "~/common/credentials";
import * as Strings from "~/common/strings";
import * as Validations from "~/common/validations";
import * as Events from "~/common/custom-events";
import * as Logging from "~/common/logging";
import * as UserBehaviors from "~/common/user-behaviors";
import * as Environment from "~/common/environment";
import * as Window from "~/common/window";
import { encode } from "blurhash";
import { v4 as uuid } from "uuid";
const STAGING_DEAL_BUCKET = "stage-deal";
@ -158,7 +158,7 @@ export const upload = async ({ file, context, bucketName }) => {
}
const _privateUploadMethod = (path, file) =>
new Promise((resolve, reject) => {
new Promise((resolve) => {
const XHR = new XMLHttpRequest();
window.addEventListener(`cancel-${currentFileKey}`, () => {
@ -211,12 +211,10 @@ export const upload = async ({ file, context, bucketName }) => {
};
XHR.send(formData);
});
const resources = context.props.resources;
const storageDealRoute = resources?.storageDealUpload
? `${resources.storageDealUpload}/api/deal/`
: null;
const generalRoute = resources?.upload ? `${resources.upload}/api/data/` : null;
const zipUploadRoute = resources?.uploadZip ? `${resources.uploadZip}/api/data/zip/` : null;
const storageDealRoute = `${Environment.URI_SHOVEL}/api/deal/`;
const generalRoute = `${Environment.URI_SHOVEL}/api/data/`;
const zipUploadRoute = `${Environment.URI_SHOVEL}/api/data/zip/`;
if (!storageDealRoute || !generalRoute || !zipUploadRoute) {
Events.dispatchMessage({ message: "We could not find our upload server." });
@ -302,9 +300,7 @@ export const formatDroppedFiles = async ({ dataTransfer }) => {
file = data.getAsFile();
} else if (data.kind == "string" && data.type == "text/uri-list") {
try {
const dataAsString = new Promise((resolve, reject) =>
data.getAsString((d) => resolve(d))
);
const dataAsString = new Promise((resolve) => data.getAsString((d) => resolve(d)));
const resp = await fetch(await dataAsString);
const blob = resp.blob();

View File

@ -4,14 +4,12 @@ import * as Actions from "~/common/actions";
import * as Window from "~/common/window";
import * as Validations from "~/common/validations";
import * as Strings from "~/common/strings";
import * as Store from "~/common/store";
import * as FileUtilities from "~/common/file-utilities";
import * as Events from "~/common/custom-events";
import Cookies from "universal-cookie";
import JSZip from "jszip";
import { v4 as uuid } from "uuid";
import { saveAs } from "file-saver";
//NOTE(martina): this file is for utility *API-calling* functions
@ -137,7 +135,7 @@ export const hydrate = async () => {
return JSON.parse(JSON.stringify(response.data));
};
export const uploadImage = async (file, resources) => {
export const uploadImage = async (file) => {
if (!file) {
Events.dispatchMessage({ message: "Something went wrong with the upload. Please try again" });
return;
@ -148,7 +146,7 @@ export const uploadImage = async (file, resources) => {
return;
}
const response = await FileUtilities.upload({ file, routes: resources });
const response = await FileUtilities.upload({ file });
if (Events.hasError(response)) {
return false;
@ -267,12 +265,12 @@ const _nativeDownload = ({ url, onError }) => {
}
};
window.addEventListener("message", handleIframeErrors);
iframe.onload = (e) => window.removeEventListener("message", handleIframeErrors);
iframe.onload = () => window.removeEventListener("message", handleIframeErrors);
document.body.appendChild(iframe);
};
export const compressAndDownloadFiles = async ({ files, name = "slate.zip", resourceURI }) => {
export const compressAndDownloadFiles = async ({ files, name = "slate.zip" }) => {
const errorMessage = "Something went wrong with the download. Please try again";
try {
if (!files || files.length == 0) {
@ -307,11 +305,11 @@ export const compressAndDownloadFiles = async ({ files, name = "slate.zip", reso
}
Actions.createDownloadActivity({ files });
const res = await Actions.createZipToken({ files: downloadFiles, resourceURI });
const downloadLink = Actions.downloadZip({ token: res.data.token, name, resourceURI });
const res = await Actions.createZipToken(downloadFiles);
const downloadLink = Actions.downloadZip({ token: res.data.token, name });
await _nativeDownload({
url: downloadLink,
onError: (err) =>
onError: () =>
Events.dispatchMessage({
message: errorMessage,
}),

View File

@ -173,7 +173,6 @@ export default class ApplicationPage extends React.Component {
files: toUpload,
slate,
keys: Object.keys(fileLoading),
resources: this.props.resources,
context: this,
});
};
@ -244,18 +243,16 @@ export default class ApplicationPage extends React.Component {
await Websockets.deleteClient();
wsclient = null;
}
if (this.props.resources && !Strings.isEmpty(this.props.resources.pubsub)) {
if (!this.state.viewer) {
Logging.error("WEBSOCKET: NOT AUTHENTICATED");
return;
}
wsclient = Websockets.init({
resource: this.props.resources.pubsub,
viewer: this.state.viewer,
onUpdate: this._handleUpdateViewer,
onNewActiveUser: this._handleNewActiveUser,
});
if (!this.state.viewer) {
Logging.error("WEBSOCKET: NOT AUTHENTICATED");
return;
}
wsclient = Websockets.init({
resource: Environment.URI_FIJI,
viewer: this.state.viewer,
onUpdate: this._handleUpdateViewer,
onNewActiveUser: this._handleNewActiveUser,
});
if (!wsclient) {
Events.dispatchMessage({
message:
@ -316,7 +313,6 @@ export default class ApplicationPage extends React.Component {
slate,
keys: Object.keys(fileLoading),
numFailed,
resources: this.props.resources,
context: this,
});
};
@ -330,7 +326,6 @@ export default class ApplicationPage extends React.Component {
slate,
keys: Object.keys(fileLoading),
numFailed,
resources: this.props.resources,
context: this,
});
};
@ -593,7 +588,6 @@ export default class ApplicationPage extends React.Component {
onUpload: this._handleUploadFiles,
isMobile: this.state.isMobile,
isMac: this.props.isMac,
resources: this.props.resources,
activeUsers: this.state.activeUsers,
userBucketCID: this.state.userBucketCID,
external: !!!this.state.viewer,
@ -612,7 +606,6 @@ export default class ApplicationPage extends React.Component {
onCancel: this._handleDismissSidebar,
onUpload: this._handleUploadFiles,
onAction: this._handleAction,
resources: this.props.resources,
});
}
@ -669,7 +662,6 @@ export default class ApplicationPage extends React.Component {
viewer={this.state.viewer}
onAction={this._handleAction}
isMobile={this.props.isMobile}
resourceURI={this.props.resources.search}
/>
<CTATransition onAction={this._handleAction} />
{/* {!this.state.loaded ? (

View File

@ -399,7 +399,7 @@ class CarouselSidebar extends React.Component {
this.setState({ isUploading: false });
return;
}
let file = await UserBehaviors.uploadImage(e.target.files[0], this.props.resources, true);
let file = await UserBehaviors.uploadImage(e.target.files[0]);
if (!file) {
this.setState({ isUploading: false });
return;

View File

@ -463,7 +463,6 @@ export default class DataView extends React.Component {
const selectedFiles = this.props.items.filter((_, i) => this.state.checked[i]);
UserBehaviors.compressAndDownloadFiles({
files: selectedFiles,
resourceURI: this.props.resources.download,
});
this.setState({ checked: {} });
};

View File

@ -105,12 +105,10 @@ const STYLES_DESCRIPTION = css`
max-width: 100%;
overflow-wrap: break-word;
white-space: pre-wrap;
ul,
ol {
white-space: normal;
}
@media (max-width: ${Constants.sizes.mobile}px) {
margin-top: 24px;
}
@ -132,7 +130,6 @@ const STYLES_STAT = css`
const STYLES_BUTTON = css`
margin-bottom: 32px;
@media (max-width: ${Constants.sizes.mobile}px) {
margin-bottom: 16px;
}
@ -289,7 +286,7 @@ export default class Profile extends React.Component {
render() {
let tab = this.props.page.params?.tab;
let { user, isOwner } = this.props;
let fileCount = user.library?.length || 0;
// let fileCount = user.library?.length || 0;
const showStatusIndicator = this.props.isAuthenticated;

View File

@ -717,7 +717,6 @@ export class SearchModal extends React.Component {
let res;
if (!refilter) {
let response = await Actions.search({
resourceURI: this.props.resourceURI,
query: this.state.inputValue,
type: this.state.typeFilter,
});

View File

@ -781,7 +781,6 @@ export class SlateLayout extends React.Component {
const selectedFiles = this.props.items.filter((_, i) => this.state.checked[i]);
UserBehaviors.compressAndDownloadFiles({
files: selectedFiles,
resourceURI: this.props.resources.download,
});
this.setState({ checked: {} });
};

View File

@ -82,7 +82,7 @@ export const uploadScreenshot = async (file, user) => {
targetId: file.id,
};
try {
const request = await fetch(`${Environment.RESOURCE_URI_UPLOAD}/api/data/url`, {
const request = await fetch(`${Environment.}/api/data/url`, {
method: "POST",
credentials: "omit",
headers: {

View File

@ -11,11 +11,11 @@ export const create = () => {
return;
}
if (Strings.isEmpty(Environment.RESOURCE_URI_PUBSUB)) {
if (Strings.isEmpty(Environment.URI_FIJI)) {
return;
}
ws = new WebSocket(Environment.RESOURCE_URI_PUBSUB, {
ws = new WebSocket(Environment.URI_FIJI, {
perMessageDeflate: false,
});

View File

@ -8,7 +8,6 @@ export const getServerSideProps = async ({ query }) => {
// viewer: query.viewer,
// isMobile: query.isMobile,
// isMac: query.isMac,
// resources: query.resources,
// page: query.page,
// data: query.data,
// },
@ -26,7 +25,6 @@ export default class ApplicationPage extends React.Component {
// viewer={this.props.viewer}
// isMobile={this.props.isMobile}
// isMac={this.props.isMac}
// resources={this.props.resources}
// page={this.props.page}
// data={this.props.data}
/>

View File

@ -212,7 +212,6 @@ export default class SlatePage extends React.Component {
UserBehaviors.compressAndDownloadFiles({
files: slateFiles,
name: `${slateName}.zip`,
resourceURI: this.props.resources.download,
});
};

View File

@ -50,8 +50,8 @@ export default class SceneEditAccount extends React.Component {
photo: this.props.viewer.data.photo,
name: this.props.viewer.data.name,
deleting: false,
allow_filecoin_directory_listing: this.props.viewer.data.settings
?.allow_filecoin_directory_listing,
allow_filecoin_directory_listing:
this.props.viewer.data.settings?.allow_filecoin_directory_listing,
allow_automatic_data_storage: this.props.viewer.data.settings?.allow_automatic_data_storage,
allow_encrypted_data_storage: this.props.viewer.data.settings?.allow_encrypted_data_storage,
changingPassword: false,
@ -64,7 +64,7 @@ export default class SceneEditAccount extends React.Component {
_handleUpload = async (e) => {
this.setState({ changingAvatar: true });
let file = await UserBehaviors.uploadImage(e.target.files[0], this.props.resources, true);
let file = await UserBehaviors.uploadImage(e.target.files[0]);
if (!file) {
this.setState({ changingAvatar: false });
return;
@ -198,10 +198,7 @@ export default class SceneEditAccount extends React.Component {
<div>
<div css={STYLES_HEADER}>Your Avatar</div>
<ProfilePhoto
user={this.props.viewer}
size={256}
/>
<ProfilePhoto user={this.props.viewer} size={256} />
<div style={{ marginTop: 24 }}>
<input

View File

@ -248,7 +248,6 @@ export default class SceneFilesFolder extends React.Component {
<ScenePage>
<GlobalCarousel
carouselType="DATA"
resources={this.props.resources}
viewer={this.props.viewer}
objects={files}
onAction={this.props.onAction}
@ -472,7 +471,6 @@ export default class SceneFilesFolder extends React.Component {
user={this.props.viewer}
items={files}
view={tab}
resources={this.props.resources}
isOwner={true}
page={this.props.page}
/>

View File

@ -111,7 +111,6 @@ export default class SceneMakeFilecoinDeal extends React.Component {
const response = await FileUtilities.upload({
bucketName: STAGING_DEAL_BUCKET,
routes: this.props.resources,
file,
});
}

View File

@ -402,7 +402,6 @@ class SlatePage extends React.Component {
UserBehaviors.compressAndDownloadFiles({
files: slateFiles,
name: `${slateName}.zip`,
resourceURI: this.props.resources.download,
});
};
@ -527,7 +526,6 @@ class SlatePage extends React.Component {
preview={preview}
onSavePreview={this._handleSavePreview}
items={objects}
resources={this.props.resources}
onSelect={this._handleSelect}
defaultLayout={layouts && layouts.ver === "2.0" ? layouts.defaultLayout : true}
onAction={this.props.onAction}

View File

@ -1,7 +1,6 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Serializers from "~/node_common/serializers";
import * as ViewerManager from "~/node_common/managers/viewer";
import * as Websocket from "~/node_common/nodejs-websocket";
import * as Logging from "~/common/logging";
@ -18,7 +17,7 @@ import cors from "cors";
import morgan from "morgan";
import path from "path";
import { FilecoinNumber, Converter } from "@glif/filecoin-number";
import { FilecoinNumber } from "@glif/filecoin-number";
const app = next({
dev: !Environment.IS_PRODUCTION,
@ -48,23 +47,6 @@ const loginLimiter = limit({
const handler = app.getRequestHandler();
const EXTERNAL_RESOURCES = {
storageDealUpload: Strings.isEmpty(Environment.RESOURCE_URI_STORAGE_UPLOAD)
? null
: Environment.RESOURCE_URI_STORAGE_UPLOAD,
upload: Strings.isEmpty(Environment.RESOURCE_URI_UPLOAD)
? null
: Environment.RESOURCE_URI_STORAGE_UPLOAD,
uploadZip: Strings.isEmpty(Environment.RESOURCE_URI_UPLOAD)
? null
: Environment.RESOURCE_URI_STORAGE_UPLOAD,
download: Strings.isEmpty(Environment.RESOURCE_URI_UPLOAD)
? null
: Environment.RESOURCE_URI_STORAGE_UPLOAD,
pubsub: Strings.isEmpty(Environment.RESOURCE_URI_PUBSUB) ? null : Environment.RESOURCE_URI_PUBSUB,
search: Strings.isEmpty(Environment.RESOURCE_URI_SEARCH) ? null : Environment.RESOURCE_URI_SEARCH,
};
app.prepare().then(async () => {
const server = express();
@ -83,19 +65,19 @@ app.prepare().then(async () => {
server.get("/system/:c", async (r, s) => s.redirect(`/_/system/${r.params.c}`));
server.get("/experiences/:m", async (r, s) => s.redirect(`/_/experiences/${r.params.m}`));
server.all("/api/users/create", createLimiter, async (r, s, next) => {
server.all("/api/users/create", createLimiter, async (r, s) => {
return handler(r, s, r.url);
});
server.all("/api/sign-in", loginLimiter, async (r, s, next) => {
server.all("/api/sign-in", loginLimiter, async (r, s) => {
return handler(r, s, r.url);
});
server.all("/api/:a", async (r, s, next) => {
server.all("/api/:a", async (r, s) => {
return handler(r, s, r.url);
});
server.all("/api/:a/:b", async (r, s, next) => {
server.all("/api/:a/:b", async (r, s) => {
return handler(r, s, r.url);
});
@ -137,7 +119,6 @@ app.prepare().then(async () => {
// isMac,
// page,
// data: null,
// resources: EXTERNAL_RESOURCES,
// });
});
@ -165,7 +146,6 @@ app.prepare().then(async () => {
if (!page) {
return handler(req, res, req.url, {
isMobile,
resources: EXTERNAL_RESOURCES,
});
}
@ -175,7 +155,6 @@ app.prepare().then(async () => {
viewer,
page,
data: null,
resources: EXTERNAL_RESOURCES,
});
});
@ -249,7 +228,6 @@ app.prepare().then(async () => {
if (!Validations.userRoute(username)) {
return handler(req, res, req.url, {
isMobile,
resources: EXTERNAL_RESOURCES,
});
}
@ -296,7 +274,6 @@ app.prepare().then(async () => {
isMac,
data: user,
page,
resources: EXTERNAL_RESOURCES,
});
});
@ -354,7 +331,6 @@ app.prepare().then(async () => {
// isMac,
// page,
// data: user,
// resources: EXTERNAL_RESOURCES,
// });
// });
@ -369,7 +345,6 @@ app.prepare().then(async () => {
if (!Validations.userRoute(username)) {
return handler(req, res, req.url, {
isMobile,
resources: EXTERNAL_RESOURCES,
});
}
@ -419,7 +394,6 @@ app.prepare().then(async () => {
isMac,
data: slate,
page,
resources: EXTERNAL_RESOURCES,
});
});
@ -484,13 +458,12 @@ app.prepare().then(async () => {
// isMac,
// data: slate,
// page,
// resources: EXTERNAL_RESOURCES,
// });
// });
server.all("*", async (r, s) => handler(r, s, r.url));
const listenServer = server.listen(Environment.PORT, async (e) => {
server.listen(Environment.PORT, async (e) => {
if (e) throw e;
Websocket.create();