- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { createError, defineEventHandler, readBody } from "h3";
|
|
|
|
import { requireAdmin } from "@/lib/admin-auth.server";
|
|
import { readContent, sanitizeCinemas, writeContent } from "@/lib/content.server";
|
|
|
|
/**
|
|
* วาง JSON ของโรงหนัง (ออบเจกต์เดียวหรือ array) เพื่อเพิ่ม/ทับรายการเดิม
|
|
* ใช้กับปุ่ม "วาง JSON" ในหน้า admin — ทับเฉพาะ slug ที่ซ้ำกัน
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
requireAdmin(event);
|
|
const body = (await readBody(event)) as { raw?: string };
|
|
const raw = (body?.raw ?? "").trim();
|
|
if (!raw) {
|
|
throw createError({ statusCode: 400, statusMessage: "ยังไม่มีข้อมูลให้วาง" });
|
|
}
|
|
|
|
let parsed: unknown;
|
|
try {
|
|
parsed = JSON.parse(raw);
|
|
} catch (error) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: `JSON ไม่ถูกต้อง: ${error instanceof Error ? error.message : ""}`,
|
|
});
|
|
}
|
|
|
|
const incoming = sanitizeCinemas(Array.isArray(parsed) ? parsed : [parsed]);
|
|
const current = await readContent();
|
|
|
|
const bySlug = new Map(current.cinemas.map((cinema) => [cinema.slug, cinema]));
|
|
for (const cinema of incoming) bySlug.set(cinema.slug, cinema);
|
|
|
|
const next = {
|
|
cinemas: Array.from(bySlug.values()),
|
|
site: current.site,
|
|
about: current.about,
|
|
forCinemas: current.forCinemas,
|
|
forFilmLovers: current.forFilmLovers,
|
|
};
|
|
await writeContent(next);
|
|
return { imported: incoming.length, store: next };
|
|
});
|