修复md导入问题

This commit is contained in:
2026-03-03 14:07:56 +08:00
parent 911c669d81
commit 7ea9bd7599
23 changed files with 896 additions and 526 deletions
+1 -27
View File
@@ -2,33 +2,7 @@
import { prisma } from '@/lib/prisma';
import { requireApiAuth } from '@/lib/api-auth';
import { cleanupAccidentalStandaloneInlineCode, markdownToImportHtml } from '@/lib/markdown-import';
const MAX_TITLE_LENGTH = 200;
const MAX_TAGS = 20;
const MAX_TAG_LENGTH = 50;
function safeParseTags(tags: string | null): string[] {
if (!tags) return [];
try {
const parsed = JSON.parse(tags);
return Array.isArray(parsed) ? parsed.filter((t): t is string => typeof t === 'string') : [];
} catch {
return [];
}
}
function normalizeTags(input: unknown): string[] {
if (!Array.isArray(input)) return [];
const unique = new Set<string>();
for (const raw of input) {
if (typeof raw !== 'string') continue;
const normalized = raw.trim();
if (!normalized || normalized.length > MAX_TAG_LENGTH) continue;
unique.add(normalized);
if (unique.size >= MAX_TAGS) break;
}
return Array.from(unique);
}
import { MAX_TITLE_LENGTH, safeParseTags, normalizeTags } from '@/lib/page-utils';
export async function GET() {
const authError = await requireApiAuth();