mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 01:23:08 +03:00
converted file.data.type -> file.type
This commit is contained in:
parent
e0a044fcac
commit
44820c388a
@ -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);
|
||||
|
@ -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)}/`),
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ export default function ViewMoreContent({ items, children, ...props }) {
|
||||
<div css={Styles.HORIZONTAL_CONTAINER_CENTERED}>
|
||||
{items?.slice(0, 3).map((file) => {
|
||||
const isImageFile =
|
||||
Validations.isPreviewableImage(file?.data?.type) || file?.data?.coverImage;
|
||||
Validations.isPreviewableImage(file?.type) || file?.data?.coverImage;
|
||||
return (
|
||||
<div
|
||||
key={file.id}
|
||||
|
@ -518,8 +518,8 @@ class CarouselSidebar extends React.Component {
|
||||
render() {
|
||||
const isPublic = this.props.file.isPublic;
|
||||
const file = this.props.file;
|
||||
const { size } = file;
|
||||
const { coverImage, type } = file.data;
|
||||
const { size, type } = file;
|
||||
const { coverImage } = file.data;
|
||||
const editingAllowed = this.props.isOwner && !this.props.isRepost && !this.props.external;
|
||||
|
||||
const isUnityGame = Validations.isUnityType(type);
|
||||
|
@ -340,7 +340,7 @@ const getObjectToPreview = (objects = []) => {
|
||||
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;
|
||||
});
|
||||
|
@ -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}
|
||||
>
|
||||
<FilePreviewBubble cid={cid} type={each.data.type}>
|
||||
<FilePreviewBubble cid={cid} type={each.type}>
|
||||
<Link
|
||||
redirect
|
||||
params={{ ...this.props.page.params, cid: each.cid }}
|
||||
|
@ -3,7 +3,7 @@ import * as SVG from "~/common/svg";
|
||||
import * as Validations from "~/common/validations";
|
||||
|
||||
export function FileTypeIcon({ file, ...props }) {
|
||||
const type = file.data.type;
|
||||
const type = file.type;
|
||||
const isLink = file.isLink;
|
||||
|
||||
if (isLink) {
|
||||
|
@ -63,7 +63,7 @@ export default function ImageObjectPreview({
|
||||
ref: previewerRef,
|
||||
});
|
||||
|
||||
const { type, coverImage } = file.data;
|
||||
const { type, coverImage } = file;
|
||||
const imgTag = type.split("/")[1];
|
||||
|
||||
const blurhash = React.useMemo(() => {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 <LinkPlaceholder ratio={ratio} />;
|
||||
@ -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;
|
||||
|
@ -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 <SlateLinkObject {...this.props} />;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
) : (
|
||||
<FileTypeDefaultPreview type={object.data.type} />
|
||||
|
@ -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 || "",
|
||||
|
@ -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
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user