Krockskydd för mallar, inställningar och markeringar, flera val i kopplingsfält, Word-import av scheman och kartregister, fler namn för äldre år
Mallar, bokinställningar och kartmarkeringar skickar med version och visar en krockruta. Kopplingsfält kan ha flera val. Scheman och kartregister kan importeras från Word, och nya ID hoppar över upptagna. Äldre födelseår får fler namn genom två SCB-tabeller och grannår. Migrering 0008. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86fd435438
commit
1fd1ce78cb
37 files changed
+2274
-149
No files matched your search
@@ -3,10 +3,22 @@
|
||||
import { revalidateBook, str } from "@/lib/form";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { MAX_DOCX_BYTES } from "@/lib/word-docx";
|
||||
import { IMPORT_KINDS, type ImportKind } from "@/lib/word-import";
|
||||
import { MAX_WORD_FILES, MAX_WORD_ITEMS, commitWordImport, previewWordFiles, type CommitItem, type CommitResult, type PreviewDocument } from "@/lib/word-import-db";
|
||||
import { IMPORT_KINDS, SPECIAL_KINDS, type DocKind } from "@/lib/word-import";
|
||||
import {
|
||||
MAX_WORD_FILES,
|
||||
MAX_WORD_ITEMS,
|
||||
commitWordImport,
|
||||
loadScheduleOptions,
|
||||
previewWordFiles,
|
||||
type CommitItem,
|
||||
type CommitMap,
|
||||
type CommitResult,
|
||||
type CommitSchedule,
|
||||
type PreviewDocument,
|
||||
} from "@/lib/word-import-db";
|
||||
|
||||
export type PreviewResponse = { docs: PreviewDocument[] } | { error: "no-files" | "limit" };
|
||||
export type ScheduleOptions = Awaited<ReturnType<typeof loadScheduleOptions>>;
|
||||
export type PreviewResponse = ({ docs: PreviewDocument[] } & ScheduleOptions) | { error: "no-files" | "limit" };
|
||||
|
||||
/** Läser uppladdade Word-filer och visar vad som hittades. Ingenting sparas. */
|
||||
export async function previewWordImport(formData: FormData): Promise<PreviewResponse> {
|
||||
@@ -15,7 +27,8 @@ export async function previewWordImport(formData: FormData): Promise<PreviewResp
|
||||
if (uploads.length === 0) return { error: "no-files" };
|
||||
if (uploads.length > MAX_WORD_FILES) return { error: "limit" };
|
||||
|
||||
const kinds = formData.getAll("kinds").map((k) => (IMPORT_KINDS as string[]).includes(String(k)) ? (String(k) as ImportKind) : null);
|
||||
const allKinds: string[] = [...IMPORT_KINDS, ...SPECIAL_KINDS];
|
||||
const kinds = formData.getAll("kinds").map((k) => (allKinds.includes(String(k)) ? (String(k) as DocKind) : null));
|
||||
const files = await Promise.all(
|
||||
uploads.map(async (file) => ({
|
||||
name: file.name.slice(0, 200),
|
||||
@@ -25,14 +38,24 @@ export async function previewWordImport(formData: FormData): Promise<PreviewResp
|
||||
})),
|
||||
);
|
||||
const docs = await previewWordFiles(book.id, files.map(({ name, bytes }) => ({ name, bytes })), kinds);
|
||||
return { docs: docs.map((doc, i) => (files[i].tooLarge ? { ...doc, error: "too-large" as const } : doc)) };
|
||||
return { docs: docs.map((doc, i) => (files[i].tooLarge ? { ...doc, error: "too-large" as const } : doc)), ...(await loadScheduleOptions(book.id)) };
|
||||
}
|
||||
|
||||
/** Sparar det användaren valt i förhandsgranskningen. Allt kontrolleras igen mot boken innan det sparas. */
|
||||
export async function saveWordImport(input: { bookId: string; items: CommitItem[]; appendUnmatched: boolean }): Promise<CommitResult> {
|
||||
export async function saveWordImport(input: {
|
||||
bookId: string;
|
||||
items: CommitItem[];
|
||||
appendUnmatched: boolean;
|
||||
schedules?: CommitSchedule[];
|
||||
maps?: CommitMap[];
|
||||
}): Promise<CommitResult> {
|
||||
const book = await requireBook(String(input.bookId), "EDITOR");
|
||||
const items = Array.isArray(input.items) ? input.items.slice(0, MAX_WORD_ITEMS) : [];
|
||||
const result = await commitWordImport(book.id, book.userId, items, { appendUnmatched: input.appendUnmatched === true });
|
||||
const result = await commitWordImport(book.id, book.userId, items, {
|
||||
appendUnmatched: input.appendUnmatched === true,
|
||||
schedules: Array.isArray(input.schedules) ? input.schedules : [],
|
||||
maps: Array.isArray(input.maps) ? input.maps : [],
|
||||
});
|
||||
revalidateBook(book.id);
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user