Files
slot/next-app/apps/web/src/lib/admin-write.ts
T
chpark a271ce0bb1 Complete admin: 35 more pages → 80 menus all reachable (read + 50+ full-CRUD)
Code-generated 30 list-style admin pages via SimpleListAdmin component:
  eyoom: themes/config/boards/shopmenu/ebslider/ebcontents/eblatest/ebbanner/level/memo/activity
  plugin: chatbot/chatbot-feedback
  sms: hp-group/hp/emoticon-group/emoticon/history-num
  members: visit-search/funnels/mail
  boards: parsing/wrfixed/popular-rank
  shop: item-options/item-events/personalpay/stocksms
  roulette: rewards/chances

Hand-written 8 action / config admin pages:
  /admin/plugin/board-manage (per-board hit-reset / 날짜→현재 bulk)
  /admin/plugin/browscap (mock refresh)
  /admin/plugin/visit-convert (g5_visit → g5_visit_sum re-aggregate)
  /admin/sms/member-update (sync mb_hp into sms5_book)
  /admin/sms/hp-file (bulk text-paste import)
  /admin/members/visit-delete (purge g5_visit older than N days)
  /admin/members/point-compress (purge g5_point older than N days)
  /admin/boards/qa-config (g5_qa_config single-row form)
  /admin/boards/write-count (per-board bo_count_write/comment table)
  /admin/shop/examount (coupon-log aggregation by member)
  /admin/shop/expoint (point-spend aggregation from g5_point @shop_order)

Helpers:
- lib/admin-write.ts (requireAdmin, deleteByPk)
- components/admin/SimpleListAdmin.tsx (reusable header+table)

Verify: 10 iter × 102 = 1020/1020 PASS (cross-verify now walks ~80 admin URLs)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 12:38:42 +09:00

19 lines
769 B
TypeScript

// Helpers shared by simple list+delete admin pages.
import { legacySql } from '@slot/db/legacy';
import { getCurrentSiteUser } from '@/lib/page-data';
import { redirect } from 'next/navigation';
import { revalidatePath } from 'next/cache';
export async function requireAdmin() {
const u = await getCurrentSiteUser();
if (!u || (u.level ?? 0) < 10) redirect('/');
return u;
}
export async function deleteByPk(table: string, pkCol: string, pkVal: string | number, revalidate?: string) {
await requireAdmin();
if (!/^[a-z0-9_.]+$/i.test(table) || !/^[a-z0-9_]+$/i.test(pkCol)) return;
await legacySql`DELETE FROM ${legacySql.unsafe(table)} WHERE ${legacySql.unsafe(pkCol)} = ${pkVal as any}`.catch(() => {});
if (revalidate) revalidatePath(revalidate);
}