From d95046e951be19e15c9f4e509bf1ccbdee6a2bd2 Mon Sep 17 00:00:00 2001 From: Martina Date: Mon, 13 Sep 2021 15:41:08 -0700 Subject: [PATCH] adding shovel decorators to messages.js --- common/messages.js | 21 +++++++++++++++++++++ common/validations.js | 2 +- components/core/Link/LinkCard.js | 16 ++++++++++------ node_common/request-utilities.js | 24 ++++++++++++++++-------- node_common/utilities.js | 10 ++++++++++ 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/common/messages.js b/common/messages.js index 84b99515..da102857 100644 --- a/common/messages.js +++ b/common/messages.js @@ -235,4 +235,25 @@ export const error = { SERVER_SUPPORT_NO_USERNAME_PROVIDED: "Please include a username", UNITY_ZIP_DOWNLOAD_FAILED: "We're having trouble downloading your Unity game file. Please try again later", + + //Shovel + NO_API_KEY_PROVIDED: + "Please refresh the page to make sure you are signed in before trying to upload", + SERVER_FILE_MISSING: "No file to upload was provided", + SERVER_UPLOAD_ERROR: "We ran into an issue while uploading that file", + UPLOAD_NO_BUCKETS: + "We ran into an error where we could not detect your storage bucket while uploading", + UPLOAD_WRITE_TO_DISK_ERROR: "We ran into an error while trying to save that file to disk", + UPLOAD_PUSH_PATH_ERROR: + "We ran into an error while trying to push that file path to our storage provider", + UPLOAD_TEXTILE_RESPONSE_MISSING_DATA: + "We didn't receive the file information back from our storage provider, please try uploading again later", + UPLOAD_READABLE_STREAM_ERROR: + "We ran into an issue while piping the file to our storage provider", + UPLOAD_SIZE_TOO_LARGE: "Upload size too large. Please try again with smaller files", + UPLOAD_BUCKET_CHECK_FAILED: + "We were unable to detect your storage bucket, please try again later", + UPLOAD_NOT_ENOUGH_SPACE_REMAINS: "You do not have enough storage remaining to upload that file", + UPLOAD_FAILURE: "We were unable to upload some of your files", + UPLOAD_VERIFY_FAILURE: "We were unable to verify that some of your files were uploaded", }; diff --git a/common/validations.js b/common/validations.js index 93311fbd..d887381e 100644 --- a/common/validations.js +++ b/common/validations.js @@ -283,7 +283,7 @@ export const isUnityFile = async (file) => { }; export const isNFTLink = (file) => { - let domain = file?.data?.link?.domain; + let domain = file?.linkDomain; if (!domain) return false; domain = domain.toLowerCase(); return Constants.NFTDomains.includes(domain); diff --git a/components/core/Link/LinkCard.js b/components/core/Link/LinkCard.js index 0cd44fbc..270d4ecc 100644 --- a/components/core/Link/LinkCard.js +++ b/components/core/Link/LinkCard.js @@ -104,15 +104,15 @@ const STYLES_SOURCE_LOGO = css` `; export default function LinkCard({ file, isNFTLink }) { - const { url, linkImage, linkName, linkBody } = file; + const { url, linkImage, linkName, linkBody, linkFavicon, linkSource } = file; if (isNFTLink) { - const faviconImgState = useImage({ src: link.logo }); + const faviconImgState = useImage({ src: linkFavicon }); const tag = ( ) : ( Link source logo )} - {link.source} + {linkSource}
- +
{tag}
{/*
diff --git a/node_common/request-utilities.js b/node_common/request-utilities.js index 81989426..81ef84af 100644 --- a/node_common/request-utilities.js +++ b/node_common/request-utilities.js @@ -5,7 +5,8 @@ import * as Utilities from "~/node_common/utilities"; export const checkAuthorizationInternal = async (req, res) => { const id = Utilities.getIdFromCookie(req); if (!id) { - return res.status(401).send({ decorator: "SERVER_NOT_AUTHENTICATED", error: true }); + res.status(403).send({ decorator: "SERVER_NOT_AUTHENTICATED", error: true }); + return; } const user = await Data.getUserById({ @@ -13,17 +14,19 @@ export const checkAuthorizationInternal = async (req, res) => { }); if (!user) { - return res.status(404).send({ + res.status(404).send({ decorator: "SERVER_USER_NOT_FOUND", error: true, }); + return; } if (user.error) { - return res.status(500).send({ + res.status(500).send({ decorator: "SERVER_USER_NOT_FOUND", error: true, }); + return; } return { id, user }; @@ -31,10 +34,11 @@ export const checkAuthorizationInternal = async (req, res) => { export const checkAuthorizationExternal = async (req, res) => { if (Strings.isEmpty(req.headers.authorization)) { - return res.status(404).send({ + res.status(404).send({ decorator: "NO_API_KEY_PROVIDED", error: true, }); + return; } const parsed = Strings.getKey(req.headers.authorization); @@ -44,19 +48,21 @@ export const checkAuthorizationExternal = async (req, res) => { }); if (!key) { - return res.status(403).send({ + res.status(403).send({ decorator: "NO_MATCHING_API_KEY_FOUND", message: "We could not find that API key in our records", error: true, }); + return; } if (key.error) { - return res.status(500).send({ + res.status(500).send({ decorator: "ERROR_WHILE_VERIFYING_API_KEY", message: "We ran into an error while verifying that API key. Please try again", error: true, }); + return; } const user = await Data.getUserById({ @@ -64,20 +70,22 @@ export const checkAuthorizationExternal = async (req, res) => { }); if (!user) { - return res.status(404).send({ + res.status(404).send({ decorator: "API_KEY_OWNER_NOT_FOUND", message: "We were unable to find the owner of that API key", error: true, }); + return; } if (user.error) { - return res.status(500).send({ + res.status(500).send({ decorator: "ERROR_WHILE_LOCATING_API_KEY_OWNER", message: "We ran into an error while trying to find the owner of that API key. Please try again", error: true, }); + return; } return { id: user.id, key, user }; diff --git a/node_common/utilities.js b/node_common/utilities.js index e00720bc..0efe8fc9 100644 --- a/node_common/utilities.js +++ b/node_common/utilities.js @@ -81,6 +81,16 @@ export const getIdFromCookie = (req) => { return id; }; +export const decodeCookieToken = (token) => { + try { + const decoded = JWT.verify(token, Environment.JWT_SECRET); + return decoded.id; + } catch (e) { + Logging.error(SHOVEL, e.message); + return null; + } +}; + export const encryptWithSecret = async (text, secret) => { const cipher = crypto.createCipheriv(ENCRYPTION_ALGORITHM, secret, ENCRYPTION_IV); const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);