mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
24 lines
944 B
TypeScript
24 lines
944 B
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
import { getCsvMetadata, getDeckNames, getNotetypeNames } from "@generated/backend";
|
|
|
|
import { ImportCsvState } from "../lib";
|
|
import type { PageLoad } from "./$types";
|
|
|
|
export const load = (async ({ params }) => {
|
|
try {
|
|
const [notetypes, decks, metadata] = await Promise.all([
|
|
getNotetypeNames({}),
|
|
getDeckNames({
|
|
skipEmptyDefault: false,
|
|
includeFiltered: false,
|
|
}),
|
|
getCsvMetadata({ path: params.path }, { alertOnError: false }),
|
|
]);
|
|
const state = new ImportCsvState(params.path, notetypes, decks, metadata);
|
|
return { state };
|
|
} catch (error: any) {
|
|
const rawMsg = error?.message ?? String(error ?? "");
|
|
return { initialError: new Error(rawMsg) };
|
|
}
|
|
}) satisfies PageLoad;
|