mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 08:30:58 -05:00
parent
18761e2181
commit
009565f0cc
1 changed files with 16 additions and 6 deletions
|
@ -73,18 +73,25 @@ export async function uploadFile(
|
||||||
return res.data.id;
|
return res.data.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var input: HTMLInputElement;
|
||||||
export function grabFiles(
|
export function grabFiles(
|
||||||
maxFileSize: number,
|
maxFileSize: number,
|
||||||
cb: (files: File[]) => void,
|
cb: (files: File[]) => void,
|
||||||
tooLarge: () => void,
|
tooLarge: () => void,
|
||||||
multiple?: boolean,
|
multiple?: boolean,
|
||||||
) {
|
) {
|
||||||
const input = document.createElement("input");
|
if (input) {
|
||||||
input.type = "file";
|
input.remove();
|
||||||
input.accept = "*";
|
}
|
||||||
input.multiple = multiple ?? false;
|
|
||||||
|
|
||||||
input.onchange = async (e) => {
|
input = document.createElement("input");
|
||||||
|
|
||||||
|
input.accept = "*";
|
||||||
|
input.type = "file";
|
||||||
|
input.multiple = multiple ?? false;
|
||||||
|
input.style.display = "none";
|
||||||
|
|
||||||
|
input.addEventListener("change", async (e) => {
|
||||||
const files = (e.currentTarget as HTMLInputElement)?.files;
|
const files = (e.currentTarget as HTMLInputElement)?.files;
|
||||||
if (!files) return;
|
if (!files) return;
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
@ -94,8 +101,11 @@ export function grabFiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
cb(Array.from(files));
|
cb(Array.from(files));
|
||||||
};
|
});
|
||||||
|
|
||||||
|
// iOS requires us to append the file input
|
||||||
|
// to DOM to allow us to add any images
|
||||||
|
document.body.appendChild(input);
|
||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue