bug fix
This commit is contained in:
parent
836360f99d
commit
e39645e135
|
@ -127,39 +127,64 @@ export default function Account() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const importBookmarks = async (
|
const importBookmarks = async (
|
||||||
e: ChangeEvent<HTMLInputElement>,
|
e: React.ChangeEvent<HTMLInputElement>,
|
||||||
format: MigrationFormat
|
format: MigrationFormat
|
||||||
) => {
|
) => {
|
||||||
setSubmitLoader(true);
|
const file: File | null = e.target.files && e.target.files[0];
|
||||||
const file = e.target.files?.[0];
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
var reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsText(file, "UTF-8");
|
reader.readAsText(file, "UTF-8");
|
||||||
reader.onload = async function (e) {
|
reader.onload = async function (e) {
|
||||||
const load = toast.loading(t("importing_bookmarks"));
|
const load = toast.loading("Importing...");
|
||||||
|
|
||||||
const request: string = e.target?.result as string;
|
const request: string = e.target?.result as string;
|
||||||
const body: MigrationRequest = { format, data: request };
|
|
||||||
const response = await fetch("/api/v1/migration", {
|
const body: MigrationRequest = {
|
||||||
method: "POST",
|
format,
|
||||||
body: JSON.stringify(body),
|
data: request,
|
||||||
});
|
};
|
||||||
const data = await response.json();
|
|
||||||
toast.dismiss(load);
|
try {
|
||||||
if (response.ok) {
|
const response = await fetch("/api/v1/migration", {
|
||||||
toast.success(t("import_success"));
|
method: "POST",
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
toast.dismiss(load);
|
||||||
|
|
||||||
|
toast.error(
|
||||||
|
errorData.response ||
|
||||||
|
"Failed to import bookmarks. Please try again."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await response.json();
|
||||||
|
toast.dismiss(load);
|
||||||
|
toast.success("Imported the Bookmarks! Reloading the page...");
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} else {
|
} catch (error) {
|
||||||
toast.error(data.response as string);
|
console.error("Request failed", error);
|
||||||
|
toast.dismiss(load);
|
||||||
|
toast.error(
|
||||||
|
"An error occurred while importing bookmarks. Please check the logs for more info."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.onerror = function (e) {
|
reader.onerror = function (e) {
|
||||||
console.log("Error:", e);
|
console.log("Error reading file:", e);
|
||||||
|
toast.error(
|
||||||
|
"Failed to read the file. Please make sure the file is correct and try again."
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
setSubmitLoader(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState("");
|
const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState("");
|
||||||
|
|
Ŝarĝante…
Reference in New Issue