reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { defineEventHandler, getQuery } from "h3";
|
||||
|
||||
import { requireAdmin } from "@/lib/admin-auth.server";
|
||||
import { readEvents, summarize } from "@/lib/analytics.server";
|
||||
|
||||
/** สรุปสถิติการค้นหา — ใช้ในแท็บ "สถิติการค้นหา" ของหลังบ้าน */
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event);
|
||||
const query = getQuery(event);
|
||||
const requested = Number(query.days);
|
||||
const days = [1, 7, 30, 90].includes(requested) ? requested : 7;
|
||||
return summarize(await readEvents(), days);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
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,
|
||||
};
|
||||
await writeContent(next);
|
||||
return { imported: incoming.length, store: next };
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { defineEventHandler } from "h3";
|
||||
|
||||
import { requireAdmin } from "@/lib/admin-auth.server";
|
||||
import { readContent } from "@/lib/content.server";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event);
|
||||
return readContent();
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createError, defineEventHandler, readBody } from "h3";
|
||||
|
||||
import { requireAdmin } from "@/lib/admin-auth.server";
|
||||
import {
|
||||
readContent,
|
||||
sanitizeAbout,
|
||||
sanitizeCinemas,
|
||||
sanitizeSite,
|
||||
writeContent,
|
||||
} from "@/lib/content.server";
|
||||
|
||||
/** บันทึกทั้งชุด: ส่งมาเฉพาะส่วนที่แก้ได้ (cinemas, site และ/หรือ about) */
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event);
|
||||
const body = (await readBody(event)) as {
|
||||
cinemas?: unknown;
|
||||
site?: unknown;
|
||||
about?: unknown;
|
||||
};
|
||||
const current = await readContent();
|
||||
|
||||
try {
|
||||
const next = {
|
||||
cinemas:
|
||||
body?.cinemas === undefined
|
||||
? current.cinemas
|
||||
: sanitizeCinemas(body.cinemas),
|
||||
site: body?.site === undefined ? current.site : sanitizeSite(body.site),
|
||||
about:
|
||||
body?.about === undefined ? current.about : sanitizeAbout(body.about),
|
||||
};
|
||||
await writeContent(next);
|
||||
return next;
|
||||
} catch (error) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage:
|
||||
error instanceof Error ? error.message : "ข้อมูลไม่ถูกต้อง",
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createError, defineEventHandler, readBody } from "h3";
|
||||
|
||||
import { createAdminSession, isValidCredentials } from "@/lib/admin-auth.server";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = (await readBody(event)) as {
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
const username = (body?.username ?? "").trim();
|
||||
const password = body?.password ?? "";
|
||||
|
||||
if (!isValidCredentials(username, password)) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
statusMessage: "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง",
|
||||
});
|
||||
}
|
||||
|
||||
createAdminSession(event);
|
||||
return { ok: true };
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineEventHandler } from "h3";
|
||||
|
||||
import { clearAdminSession, isAdmin } from "@/lib/admin-auth.server";
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
clearAdminSession(event);
|
||||
return { ok: true, authenticated: false, wasAuthenticated: isAdmin(event) };
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { defineEventHandler } from "h3";
|
||||
|
||||
import { isAdmin } from "@/lib/admin-auth.server";
|
||||
|
||||
export default defineEventHandler((event) => ({
|
||||
authenticated: isAdmin(event),
|
||||
}));
|
||||
Reference in new issue
Block a user