From 44820c388ac192420dc1277b6a843e7221e83a8a Mon Sep 17 00:00:00 2001 From: Martina Date: Mon, 30 Aug 2021 15:03:45 -0700 Subject: [PATCH] converted file.data.type -> file.type --- common/file-utilities.js | 2 +- common/user-behaviors.js | 4 ++-- common/utilities.js | 2 +- .../components/ViewMoreContent.js | 2 +- components/core/CarouselSidebar.js | 4 ++-- .../core/CollectionPreviewBlock/index.js | 2 +- components/core/DataView.js | 4 ++-- components/core/FileTypeIcon.js | 2 +- .../core/ObjectPreview/ImageObjectPreview.js | 2 +- components/core/ObjectPreview/index.js | 2 +- .../core/ObjectPreview/placeholders/index.js | 4 ++-- components/core/SlateMediaObject.js | 4 ++-- components/core/SlateMediaObjectPreview.js | 4 ++-- components/core/SlatePreviewBlock.js | 2 +- node_common/managers/viewer.js | 23 +++++++++++-------- node_common/serializers.js | 4 ++-- pages/_/slate[dep].js | 6 ++--- pages/api/data/create-link.js | 2 +- scenes/SceneSlate.js | 4 ++-- 19 files changed, 41 insertions(+), 38 deletions(-) diff --git a/common/file-utilities.js b/common/file-utilities.js index 993f933a..ecb1e021 100644 --- a/common/file-utilities.js +++ b/common/file-utilities.js @@ -254,7 +254,7 @@ export const upload = async ({ file, context, bucketName }) => { } let item = res.data.data; - if (item.data.type.startsWith("image/")) { + if (item.type.startsWith("image/")) { let url = Strings.getURLfromCID(item.cid); try { let blurhash = await encodeImageToBlurhash(url); diff --git a/common/user-behaviors.js b/common/user-behaviors.js index c29be3d4..33119f2e 100644 --- a/common/user-behaviors.js +++ b/common/user-behaviors.js @@ -211,7 +211,7 @@ export const saveCopy = async ({ files, slate }) => { export const download = async (file) => { Actions.createDownloadActivity({ file }); if (file.isLink) return; - if (Validations.isUnityType(file.data.type)) { + if (Validations.isUnityType(file.type)) { return await downloadZip(file); } let uri = Strings.getURLfromCID(file.cid); @@ -281,7 +281,7 @@ export const compressAndDownloadFiles = async ({ files, name = "slate.zip" }) => let downloadFiles = []; for (const file of files) { if (file.isLink) continue; - if (Validations.isUnityType(file.data.type)) { + if (Validations.isUnityType(file.type)) { const { data } = await Actions.getZipFilePaths(file); const unityFiles = data.filesPaths.map((item) => ({ url: item.replace(`/${file.id}/`, `${Strings.getURLfromCID(file.cid)}/`), diff --git a/common/utilities.js b/common/utilities.js index c807b7e4..90401608 100644 --- a/common/utilities.js +++ b/common/utilities.js @@ -23,7 +23,7 @@ export const getImageUrlIfExists = (file, sizeLimit = null) => { } } - if (Validations.isPreviewableImage(file.data.type)) { + if (Validations.isPreviewableImage(file.type)) { if (sizeLimit && file.size > sizeLimit) { return; } diff --git a/components/core/ActivityGroup/components/ViewMoreContent.js b/components/core/ActivityGroup/components/ViewMoreContent.js index 2cd4acda..bb52191e 100644 --- a/components/core/ActivityGroup/components/ViewMoreContent.js +++ b/components/core/ActivityGroup/components/ViewMoreContent.js @@ -42,7 +42,7 @@ export default function ViewMoreContent({ items, children, ...props }) {
{items?.slice(0, 3).map((file) => { const isImageFile = - Validations.isPreviewableImage(file?.data?.type) || file?.data?.coverImage; + Validations.isPreviewableImage(file?.type) || file?.data?.coverImage; return (
{ let isImage = false; objects.some((object, i) => { - const isPreviewableImage = Validations.isPreviewableImage(object.data.type); + const isPreviewableImage = Validations.isPreviewableImage(object.type); if (isPreviewableImage) (objectIdx = i), (isImage = true); return isPreviewableImage; }); diff --git a/components/core/DataView.js b/components/core/DataView.js index c5912f90..876c69bb 100644 --- a/components/core/DataView.js +++ b/components/core/DataView.js @@ -659,7 +659,7 @@ export default class DataView extends React.Component { _handleDragToDesktop = (e, object) => { const url = Strings.getURLfromCID(object.cid); const title = object.filename || object.name; - const type = object.data.type; + const type = object.type; console.log(e.dataTransfer, e.dataTransfer.setData); e.dataTransfer.setData("DownloadURL", `${type}:${title}:${url}`); }; @@ -976,7 +976,7 @@ export default class DataView extends React.Component { }} onDragEnd={this._enableDragAndDropUploadEvent} > - + { diff --git a/components/core/ObjectPreview/index.js b/components/core/ObjectPreview/index.js index b33d4fbf..ae9f4a72 100644 --- a/components/core/ObjectPreview/index.js +++ b/components/core/ObjectPreview/index.js @@ -24,7 +24,7 @@ import LinkObjectPreview from "~/components/core/ObjectPreview/LinkObjectPreview import ObjectPreviewPrimitive from "~/components/core/ObjectPreview/ObjectPreviewPrimitive"; const ObjectPreview = ({ file, ...props }) => { - const { type, link } = file.data; + const { type, link } = file; const url = Strings.getURLfromCID(file.cid); diff --git a/components/core/ObjectPreview/placeholders/index.js b/components/core/ObjectPreview/placeholders/index.js index 2e665ab6..61eb64d3 100644 --- a/components/core/ObjectPreview/placeholders/index.js +++ b/components/core/ObjectPreview/placeholders/index.js @@ -40,7 +40,7 @@ const STYLES_TAG = (theme) => css` `; const PlaceholderPrimitive = ({ file, ratio }) => { - const { type, link } = file.data; + const { type, link } = file; if (link) { return ; @@ -77,7 +77,7 @@ const PlaceholderPrimitive = ({ file, ratio }) => { }; export default function Placeholder({ file, containerCss, ratio, showTag }) { - const { type } = file.data; + const { type } = file; const tag = React.useMemo(() => { if (!showTag) return false; diff --git a/components/core/SlateMediaObject.js b/components/core/SlateMediaObject.js index d82ad5a1..b830e0f4 100644 --- a/components/core/SlateMediaObject.js +++ b/components/core/SlateMediaObject.js @@ -79,7 +79,7 @@ export default class SlateMediaObject extends React.Component { componentDidMount() { const file = this.props.file; if (this.props.isMobile) { - if (file.data.type && file.data.type.startsWith("application/pdf")) { + if (file.type && file.type.startsWith("application/pdf")) { const url = Strings.getURLfromCID(file.cid); this.openLink(url); } @@ -88,7 +88,7 @@ export default class SlateMediaObject extends React.Component { render() { const { file, isMobile } = this.props; - const type = file.data.type || ""; + const type = file.type || ""; if (file.isLink) { return ; diff --git a/components/core/SlateMediaObjectPreview.js b/components/core/SlateMediaObjectPreview.js index a75ab8fa..fdcd571f 100644 --- a/components/core/SlateMediaObjectPreview.js +++ b/components/core/SlateMediaObjectPreview.js @@ -88,7 +88,7 @@ export default class SlateMediaObjectPreview extends React.Component { }; setImage = () => { - let type = this.props.file.data?.type; + let type = this.props.file.type; let coverImage = this.props.file.data?.coverImage; let url; if (type && Validations.isPreviewableImage(type)) { @@ -105,7 +105,7 @@ export default class SlateMediaObjectPreview extends React.Component { render() { const file = this.props.file; - const type = this.props.file.data?.type; + const type = this.props.file.type; const coverImage = this.props.file.data?.coverImage; let url = Utilities.getImageUrlIfExists(file); diff --git a/components/core/SlatePreviewBlock.js b/components/core/SlatePreviewBlock.js index c67e8a8c..64098a97 100644 --- a/components/core/SlatePreviewBlock.js +++ b/components/core/SlatePreviewBlock.js @@ -257,7 +257,7 @@ export class SlatePreviewBlock extends React.Component { if (!objects) { objects = []; for (let file of slate.objects) { - if (Validations.isPreviewableImage(file.data.type)) { + if (Validations.isPreviewableImage(file.type)) { objects.push(file); } if (objects.length >= 4) break; diff --git a/node_common/managers/viewer.js b/node_common/managers/viewer.js index a97ef606..64aa085e 100644 --- a/node_common/managers/viewer.js +++ b/node_common/managers/viewer.js @@ -178,16 +178,19 @@ export const getById = async ({ id }) => { let size = each.size; if (typeof size === "number") { bytes += size; - if (each.data.type && each.data.type.startsWith("image/")) { - imageBytes += size; - } else if (each.data.type && each.data.type.startsWith("video/")) { - videoBytes += size; - } else if (each.data.type && each.data.type.startsWith("audio/")) { - audioBytes += size; - } else if (each.data.type && each.data.type.startsWith("application/epub")) { - epubBytes += size; - } else if (each.data.type && each.data.type.startsWith("application/pdf")) { - pdfBytes += size; + let type = each.type; + if (type) { + if (type.startsWith("image/")) { + imageBytes += size; + } else if (type.startsWith("video/")) { + videoBytes += size; + } else if (type.startsWith("audio/")) { + audioBytes += size; + } else if (type.startsWith("application/epub")) { + epubBytes += size; + } else if (type.startsWith("application/pdf")) { + pdfBytes += size; + } } } diff --git a/node_common/serializers.js b/node_common/serializers.js index e45f0c1d..cdbf7c42 100644 --- a/node_common/serializers.js +++ b/node_common/serializers.js @@ -51,8 +51,8 @@ export const sanitizeFile = (entity) => { createdAt: entity.createdAt, body: entity.body, size: entity.size, + type: entity.type, data: { - type: entity.data?.type, source: entity.data?.source, author: entity.data?.author, blurhash: entity.data?.blurhash, @@ -128,8 +128,8 @@ export const cleanFile = (entity) => { url: entity.url, body: entity.body, size: entity.size, + type: entity.type, // data: { - // type: entity.data?.type, // source: entity.data?.source, // author: entity.data?.author, // blurhash: entity.data?.blurhash, diff --git a/pages/_/slate[dep].js b/pages/_/slate[dep].js index 1562c05b..e2ae4a0e 100644 --- a/pages/_/slate[dep].js +++ b/pages/_/slate[dep].js @@ -220,8 +220,8 @@ export default class SlatePage extends React.Component { if (Strings.isEmpty(image)) { for (let i = 0; i < objects.length; i++) { if ( - objects[i].data.type && - Validations.isPreviewableImage(objects[i].data.type) && + objects[i].type && + Validations.isPreviewableImage(objects[i].type) && objects[i].size && objects[i].size < Constants.linkPreviewSizeLimit ) { @@ -239,7 +239,7 @@ export default class SlatePage extends React.Component { if (object) { title = object.data.name || object.filename; body = !Strings.isEmpty(object.data.body) ? Strings.elide(object.data.body) : ""; - image = object.data.type.includes("image/") ? ( + image = object.type.includes("image/") ? ( Strings.getURLfromCID(object.cid) ) : ( diff --git a/pages/api/data/create-link.js b/pages/api/data/create-link.js index 55a08531..ae5fff49 100644 --- a/pages/api/data/create-link.js +++ b/pages/api/data/create-link.js @@ -71,8 +71,8 @@ export default async (req, res) => { cid: file.cid, isLink: true, url: file.url, + type: "link", data: { - type: "link", name: data.title || "", author: data.author || "", source: data.publisher || "", diff --git a/scenes/SceneSlate.js b/scenes/SceneSlate.js index 75f1a066..049ad387 100644 --- a/scenes/SceneSlate.js +++ b/scenes/SceneSlate.js @@ -234,8 +234,8 @@ export default class SceneSlate extends React.Component { if (!image && objects) { for (let i = 0; i < objects.length; i++) { if ( - objects[i].data.type && - Validations.isPreviewableImage(objects[i].data.type) && + objects[i].type && + Validations.isPreviewableImage(objects[i].type) && objects[i].size && objects[i].size < Constants.linkPreviewSizeLimit ) {