remove screenshotting from external link api and patch node_env issue

This commit is contained in:
Martina 2021-08-16 19:52:53 -07:00
parent 123c59850a
commit d031162617
4 changed files with 45 additions and 49 deletions

View File

@ -1,30 +1,29 @@
import * as Window from "~/common/window";
import * as Strings from "~/common/strings";
import * as Logging from "~/common/logging";
import * as Environment from "~/common/environment";
let pingTimeout = null;
let client = null;
let savedResource = null;
let savedViewer = null;
let savedOnUpdate = null;
export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => {} }) => {
savedResource = resource;
export const init = ({ viewer, onUpdate, onNewActiveUser = () => {} }) => {
savedViewer = viewer;
savedOnUpdate = onUpdate;
if (!process.browser) {
return null;
}
Logging.log(`${resource}: init`);
Logging.log(`${Environment.URI_FIJI}: init`);
if (client) {
Error.log("ERROR: Already has websocket client");
return client;
}
client = new WebSocket(resource);
client = new WebSocket(Environment.URI_FIJI);
client.addEventListener("open", (e) => {
if (!client) {
@ -40,7 +39,7 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () =>
return null;
}
Logging.log(`${resource}: ping`);
Logging.log(`${Environment.URI_FIJI}: ping`);
clearTimeout(pingTimeout);
pingTimeout = setTimeout(() => {
@ -91,14 +90,14 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () =>
setTimeout(() => {
client = null;
Logging.log("Auto reconnecting dropped websocket");
init({ resource, viewer, onUpdate });
init({ viewer, onUpdate });
}, 1000);
}
if (!client) {
return null;
}
Logging.log(`${resource}: closed`);
Logging.log(`${Environment.URI_FIJI}: closed`);
clearTimeout(pingTimeout);
});
@ -138,12 +137,12 @@ export const checkWebsocket = async () => {
if (client) {
return;
}
if (!savedResource || !savedViewer || !savedOnUpdate) {
if (!savedViewer || !savedOnUpdate) {
Logging.log("No saved resources from previous, so not connecting a websocket");
return;
}
Logging.log("Reconnecting dropped websocket");
init({ resource: savedResource, viewer: savedViewer, onUpdate: savedOnUpdate });
init({ viewer: savedViewer, onUpdate: savedOnUpdate });
await Window.delay(2000);
return;
};

View File

@ -1,4 +1,3 @@
/* eslint-disable prefer-destructuring */
export const NODE_ENV = process.env.NODE_ENV || "development";
export const IS_PRODUCTION = NODE_ENV === "production";
export const PORT = process.env.PORT || 1337;

View File

@ -74,27 +74,27 @@ export const testIframe = async (url) => {
}
};
export const uploadScreenshot = async (file, user) => {
const token = JWT.sign({ id: user.id, username: user.username }, Environment.JWT_SECRET);
const data = {
url: file.data.coverImage.data.url,
updateType: "COVER_IMAGE",
targetId: file.id,
};
try {
const request = await fetch(`${Environment.}/api/data/url`, {
method: "POST",
credentials: "omit",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: token,
},
body: JSON.stringify({ data }),
});
return true;
} catch (e) {
Logging.error(e);
return false;
}
};
// export const uploadScreenshot = async (file, user) => {
// const token = JWT.sign({ id: user.id, username: user.username }, Environment.JWT_SECRET);
// const data = {
// url: file.data.coverImage.data.url,
// updateType: "COVER_IMAGE",
// targetId: file.id,
// };
// try {
// const request = await fetch(`${Environment.}/api/data/url`, {
// method: "POST",
// credentials: "omit",
// headers: {
// Accept: "application/json",
// "Content-Type": "application/json",
// Authorization: token,
// },
// body: JSON.stringify({ data }),
// });
// return true;
// } catch (e) {
// Logging.error(e);
// return false;
// }
// };

View File

@ -78,15 +78,15 @@ export default async (req, res) => {
author: data.author || "",
source: data.publisher || "",
body: data.description || "",
coverImage: data.screenshot
? {
data: {
type: "image/png",
size: data.screenshot.size,
url: data.screenshot.url,
},
}
: null,
// coverImage: data.screenshot
// ? {
// data: {
// type: "image/png",
// size: data.screenshot.size,
// url: data.screenshot.url,
// },
// }
// : null,
link: {
name: data.title || "",
author: data.author || "",
@ -127,11 +127,9 @@ export default async (req, res) => {
}
}
for (let file of createdFiles) {
LinkUtilities.uploadScreenshot(file, user);
}
let added = createdFiles?.length || 0;
// for (let file of createdFiles) {
// LinkUtilities.uploadScreenshot(file, user);
// }
let filesToAddToSlate = createdFiles.concat(duplicateFiles); //NOTE(martina): files that are already owned by the user are included in case they aren't yet in that specific slate
if (slate && filesToAddToSlate.length) {