mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 00:20:57 -05:00
fix: don't paste file anyways if too large
This commit is contained in:
parent
b2f4411850
commit
56f59d132b
1 changed files with 39 additions and 25 deletions
|
@ -23,7 +23,7 @@ type BehaviourType =
|
|||
behaviour: "multi";
|
||||
onChange: (files: File[]) => void;
|
||||
append?: (files: File[]) => void;
|
||||
}
|
||||
};
|
||||
|
||||
type StyleType =
|
||||
| {
|
||||
|
@ -32,7 +32,7 @@ type StyleType =
|
|||
height?: number;
|
||||
previewURL?: string;
|
||||
defaultPreview?: string;
|
||||
desaturateDefault?: boolean
|
||||
desaturateDefault?: boolean;
|
||||
}
|
||||
| {
|
||||
style: "attachment";
|
||||
|
@ -40,13 +40,19 @@ type StyleType =
|
|||
uploading: boolean;
|
||||
cancel: () => void;
|
||||
size?: number;
|
||||
}
|
||||
};
|
||||
|
||||
type Props = BehaviourType & StyleType & {
|
||||
fileType: "backgrounds" | "icons" | "avatars" | "attachments" | "banners";
|
||||
type Props = BehaviourType &
|
||||
StyleType & {
|
||||
fileType:
|
||||
| "backgrounds"
|
||||
| "icons"
|
||||
| "avatars"
|
||||
| "attachments"
|
||||
| "banners";
|
||||
maxFileSize: number;
|
||||
remove: () => Promise<void>;
|
||||
}
|
||||
};
|
||||
|
||||
export async function uploadFile(
|
||||
autumnURL: string,
|
||||
|
@ -80,6 +86,7 @@ export function grabFiles(
|
|||
input.onchange = async (e) => {
|
||||
const files = (e.currentTarget as HTMLInputElement)?.files;
|
||||
if (!files) return;
|
||||
|
||||
for (const file of files) {
|
||||
if (file.size > maxFileSize) {
|
||||
return tooLarge();
|
||||
|
@ -167,6 +174,7 @@ export function FileUploader(props: Props) {
|
|||
id: "error",
|
||||
error: "FileTooLarge",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
files.push(blob);
|
||||
|
@ -195,6 +203,7 @@ export function FileUploader(props: Props) {
|
|||
for (const item of dropped) {
|
||||
if (item.size > props.maxFileSize) {
|
||||
openScreen({ id: "error", error: "FileTooLarge" });
|
||||
continue;
|
||||
}
|
||||
|
||||
files.push(item);
|
||||
|
@ -226,7 +235,12 @@ export function FileUploader(props: Props) {
|
|||
})}
|
||||
data-uploading={uploading}>
|
||||
<div
|
||||
className={classNames(styles.image, props.desaturateDefault && previewURL == null && styles.desaturate)}
|
||||
className={classNames(
|
||||
styles.image,
|
||||
props.desaturateDefault &&
|
||||
previewURL == null &&
|
||||
styles.desaturate,
|
||||
)}
|
||||
style={{
|
||||
backgroundImage:
|
||||
style === "icon"
|
||||
|
|
Loading…
Reference in a new issue