feat: Allow data imports larger than the standard attachment size (#4449)
* feat: Allow data imports larger than the standard attachment size * Use correct preset for data imports * Cleanup of expired attachments * lint
This commit is contained in:
@@ -8,6 +8,7 @@ import { mergeRefs } from "react-merge-refs";
|
||||
import { Optional } from "utility-types";
|
||||
import insertFiles from "@shared/editor/commands/insertFiles";
|
||||
import { Heading } from "@shared/editor/lib/getHeadings";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { getDataTransferFiles } from "@shared/utils/files";
|
||||
import parseDocumentSlug from "@shared/utils/parseDocumentSlug";
|
||||
import { isInternalUrl } from "@shared/utils/urls";
|
||||
@@ -135,6 +136,7 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
async (file: File) => {
|
||||
const result = await uploadFile(file, {
|
||||
documentId: id,
|
||||
preset: AttachmentPreset.DocumentAttachment,
|
||||
});
|
||||
return result.url;
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as React from "react";
|
||||
import Dropzone from "react-dropzone";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import Flex from "~/components/Flex";
|
||||
import LoadingIndicator from "~/components/LoadingIndicator";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -39,6 +40,7 @@ function DropToImport({ disabled, onSubmit, children, format }: Props) {
|
||||
try {
|
||||
const attachment = await uploadFile(file, {
|
||||
name: file.name,
|
||||
preset: AttachmentPreset.Import,
|
||||
});
|
||||
await collections.import(attachment.id, format);
|
||||
onSubmit();
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as React from "react";
|
||||
import AvatarEditor from "react-avatar-editor";
|
||||
import Dropzone from "react-dropzone";
|
||||
import styled from "styled-components";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { AttachmentValidation } from "@shared/validations";
|
||||
import RootStore from "~/stores/RootStore";
|
||||
import Button from "~/components/Button";
|
||||
@@ -67,7 +68,7 @@ class ImageUpload extends React.Component<RootStore & Props> {
|
||||
});
|
||||
const attachment = await uploadFile(compressed, {
|
||||
name: this.file.name,
|
||||
public: true,
|
||||
preset: AttachmentPreset.Avatar,
|
||||
});
|
||||
this.props.onSuccess(attachment.url);
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import invariant from "invariant";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { client } from "./ApiClient";
|
||||
import Logger from "./Logger";
|
||||
|
||||
@@ -7,8 +8,8 @@ type UploadOptions = {
|
||||
name?: string;
|
||||
/** The document that this file was uploaded in, if any */
|
||||
documentId?: string;
|
||||
/** Whether the file should be public in cloud storage */
|
||||
public?: boolean;
|
||||
/** The preset to use for attachment configuration */
|
||||
preset: AttachmentPreset;
|
||||
/** Callback will be passed a number between 0-1 as upload progresses */
|
||||
onProgress?: (fractionComplete: number) => void;
|
||||
};
|
||||
@@ -17,11 +18,12 @@ export const uploadFile = async (
|
||||
file: File | Blob,
|
||||
options: UploadOptions = {
|
||||
name: "",
|
||||
preset: AttachmentPreset.DocumentAttachment,
|
||||
}
|
||||
) => {
|
||||
const name = file instanceof File ? file.name : options.name;
|
||||
const response = await client.post("/attachments.create", {
|
||||
public: options.public,
|
||||
preset: options.preset,
|
||||
documentId: options.documentId,
|
||||
contentType: file.type,
|
||||
size: file.size,
|
||||
|
||||
Reference in New Issue
Block a user