adding shovel decorators to messages.js

This commit is contained in:
Martina 2021-09-13 15:41:08 -07:00
parent d99e5d7d28
commit d95046e951
5 changed files with 58 additions and 15 deletions

View File

@ -235,4 +235,25 @@ export const error = {
SERVER_SUPPORT_NO_USERNAME_PROVIDED: "Please include a username", SERVER_SUPPORT_NO_USERNAME_PROVIDED: "Please include a username",
UNITY_ZIP_DOWNLOAD_FAILED: UNITY_ZIP_DOWNLOAD_FAILED:
"We're having trouble downloading your Unity game file. Please try again later", "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",
}; };

View File

@ -283,7 +283,7 @@ export const isUnityFile = async (file) => {
}; };
export const isNFTLink = (file) => { export const isNFTLink = (file) => {
let domain = file?.data?.link?.domain; let domain = file?.linkDomain;
if (!domain) return false; if (!domain) return false;
domain = domain.toLowerCase(); domain = domain.toLowerCase();
return Constants.NFTDomains.includes(domain); return Constants.NFTDomains.includes(domain);

View File

@ -104,15 +104,15 @@ const STYLES_SOURCE_LOGO = css`
`; `;
export default function LinkCard({ file, isNFTLink }) { export default function LinkCard({ file, isNFTLink }) {
const { url, linkImage, linkName, linkBody } = file; const { url, linkImage, linkName, linkBody, linkFavicon, linkSource } = file;
if (isNFTLink) { if (isNFTLink) {
const faviconImgState = useImage({ src: link.logo }); const faviconImgState = useImage({ src: linkFavicon });
const tag = ( const tag = (
<a <a
css={STYLES_LINK} css={STYLES_LINK}
href={file.url} href={url}
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
style={{ position: "relative", zIndex: 2 }} style={{ position: "relative", zIndex: 2 }}
@ -123,14 +123,14 @@ export default function LinkCard({ file, isNFTLink }) {
<SVG.Link height={12} width={12} style={{ marginRight: 4 }} /> <SVG.Link height={12} width={12} style={{ marginRight: 4 }} />
) : ( ) : (
<img <img
src={link.logo} src={linkFavicon}
alt="Link source logo" alt="Link source logo"
style={{ marginRight: 4 }} style={{ marginRight: 4 }}
css={STYLES_SOURCE_LOGO} css={STYLES_SOURCE_LOGO}
/> />
)} )}
<P3 css={STYLES_SOURCE} as="small" color="textGray" nbrOflines={1}> <P3 css={STYLES_SOURCE} as="small" color="textGray" nbrOflines={1}>
{link.source} {linkSource}
</P3> </P3>
<SVG.ExternalLink <SVG.ExternalLink
className="link_external_link" className="link_external_link"
@ -152,7 +152,11 @@ export default function LinkCard({ file, isNFTLink }) {
> >
<div css={[Styles.VERTICAL_CONTAINER, STYLES_FREEFORM_CARD]}> <div css={[Styles.VERTICAL_CONTAINER, STYLES_FREEFORM_CARD]}>
<div css={STYLES_IMAGE_CONTAINER}> <div css={STYLES_IMAGE_CONTAINER}>
<img src={image} css={Styles.IMAGE_FILL} style={{ maxHeight: "calc(100vh - 200px)" }} /> <img
src={linkImage}
css={Styles.IMAGE_FILL}
style={{ maxHeight: "calc(100vh - 200px)" }}
/>
</div> </div>
<div css={[STYLES_TEXT_BOX]}>{tag}</div> <div css={[STYLES_TEXT_BOX]}>{tag}</div>
{/* <div css={[Styles.VERTICAL_CONTAINER, STYLES_TEXT_BOX]}> {/* <div css={[Styles.VERTICAL_CONTAINER, STYLES_TEXT_BOX]}>

View File

@ -5,7 +5,8 @@ import * as Utilities from "~/node_common/utilities";
export const checkAuthorizationInternal = async (req, res) => { export const checkAuthorizationInternal = async (req, res) => {
const id = Utilities.getIdFromCookie(req); const id = Utilities.getIdFromCookie(req);
if (!id) { 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({ const user = await Data.getUserById({
@ -13,17 +14,19 @@ export const checkAuthorizationInternal = async (req, res) => {
}); });
if (!user) { if (!user) {
return res.status(404).send({ res.status(404).send({
decorator: "SERVER_USER_NOT_FOUND", decorator: "SERVER_USER_NOT_FOUND",
error: true, error: true,
}); });
return;
} }
if (user.error) { if (user.error) {
return res.status(500).send({ res.status(500).send({
decorator: "SERVER_USER_NOT_FOUND", decorator: "SERVER_USER_NOT_FOUND",
error: true, error: true,
}); });
return;
} }
return { id, user }; return { id, user };
@ -31,10 +34,11 @@ export const checkAuthorizationInternal = async (req, res) => {
export const checkAuthorizationExternal = async (req, res) => { export const checkAuthorizationExternal = async (req, res) => {
if (Strings.isEmpty(req.headers.authorization)) { if (Strings.isEmpty(req.headers.authorization)) {
return res.status(404).send({ res.status(404).send({
decorator: "NO_API_KEY_PROVIDED", decorator: "NO_API_KEY_PROVIDED",
error: true, error: true,
}); });
return;
} }
const parsed = Strings.getKey(req.headers.authorization); const parsed = Strings.getKey(req.headers.authorization);
@ -44,19 +48,21 @@ export const checkAuthorizationExternal = async (req, res) => {
}); });
if (!key) { if (!key) {
return res.status(403).send({ res.status(403).send({
decorator: "NO_MATCHING_API_KEY_FOUND", decorator: "NO_MATCHING_API_KEY_FOUND",
message: "We could not find that API key in our records", message: "We could not find that API key in our records",
error: true, error: true,
}); });
return;
} }
if (key.error) { if (key.error) {
return res.status(500).send({ res.status(500).send({
decorator: "ERROR_WHILE_VERIFYING_API_KEY", decorator: "ERROR_WHILE_VERIFYING_API_KEY",
message: "We ran into an error while verifying that API key. Please try again", message: "We ran into an error while verifying that API key. Please try again",
error: true, error: true,
}); });
return;
} }
const user = await Data.getUserById({ const user = await Data.getUserById({
@ -64,20 +70,22 @@ export const checkAuthorizationExternal = async (req, res) => {
}); });
if (!user) { if (!user) {
return res.status(404).send({ res.status(404).send({
decorator: "API_KEY_OWNER_NOT_FOUND", decorator: "API_KEY_OWNER_NOT_FOUND",
message: "We were unable to find the owner of that API key", message: "We were unable to find the owner of that API key",
error: true, error: true,
}); });
return;
} }
if (user.error) { if (user.error) {
return res.status(500).send({ res.status(500).send({
decorator: "ERROR_WHILE_LOCATING_API_KEY_OWNER", decorator: "ERROR_WHILE_LOCATING_API_KEY_OWNER",
message: message:
"We ran into an error while trying to find the owner of that API key. Please try again", "We ran into an error while trying to find the owner of that API key. Please try again",
error: true, error: true,
}); });
return;
} }
return { id: user.id, key, user }; return { id: user.id, key, user };

View File

@ -81,6 +81,16 @@ export const getIdFromCookie = (req) => {
return id; 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) => { export const encryptWithSecret = async (text, secret) => {
const cipher = crypto.createCipheriv(ENCRYPTION_ALGORITHM, secret, ENCRYPTION_IV); const cipher = crypto.createCipheriv(ENCRYPTION_ALGORITHM, secret, ENCRYPTION_IV);
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);