This commit is contained in:
sbb45
2026-06-02 21:32:45 +05:00
parent b808816099
commit 90ecfc669a
13 changed files with 979 additions and 1163 deletions
+1 -1
View File
@@ -126,7 +126,7 @@ export async function POST(req: NextRequest) {
// Создаем бронирование
const [result] = await bd.query(
`INSERT INTO bookings (type, room, date_time, time_slot, name, game, contact, contact_method, status, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())`,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))`,
[type, room, dateTime, time, name, game || null, contact, contactMethod || null, status || 'pending']
) as any[];
+1 -2
View File
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'
import { bd } from '@/lib/bd'
import { verifyAdminToken } from '@/lib/verifyAdmin'
import type { ResultSetHeader, FieldPacket } from 'mysql2'
// GET — получить все записи
export async function GET(req: NextRequest) {
@@ -22,7 +21,7 @@ export async function POST(req: NextRequest) {
return NextResponse.json({ error: 'Заполните все поля' }, { status: 400 })
}
const [result]: [ResultSetHeader, FieldPacket[]] = await bd.query(
const [result] = await bd.query(
'INSERT INTO faq (title, description) VALUES (?, ?)',
[title, description]
)
+1 -2
View File
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { verifyAdminToken } from '@/lib/verifyAdmin';
import { bd } from '@/lib/bd';
import type { ResultSetHeader } from 'mysql2';
import fs from 'fs/promises';
import path from 'path';
@@ -39,7 +38,7 @@ export async function POST(req: NextRequest) {
// сохраняем файл
await fs.writeFile(filePath, buffer);
const [result] = await bd.query<ResultSetHeader>(
const [result] = await bd.query(
'INSERT INTO games (title, image_url, platform) VALUES (?, ?, ?)',
[title, fileName, platform]
);
+1 -1
View File
@@ -47,7 +47,7 @@ export async function POST(req: NextRequest) {
// Создаем бронирование
const [result] = await bd.query(
`INSERT INTO bookings (type, room, date_time, time_slot, name, game, contact, contact_method, status, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'pending', NOW())`,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'pending', datetime('now'))`,
[type, room, dateTime, time, name, game || null, contact, contactMethod || null]
) as any[];
-15
View File
@@ -3,7 +3,6 @@ import "./globals.css";
import "../styles/reset.css";
import React from "react";
import StartupLoader from "@/components/StartupLoader";
import Script from "next/script";
export const viewport = {
themeColor: "#00ff90",
@@ -61,20 +60,6 @@ export default function RootLayout({
<body>
{children}
<StartupLoader />
<Script
id="binotel-getcall"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
(function(d, w, s) {
var widgetHash = 'j2he8ic2huirt42fsxdj', gcw = d.createElement(s);
gcw.type = 'text/javascript'; gcw.async = true;
gcw.src = '//widgets.binotel.com/getcall/widgets/' + widgetHash + '.js';
var sn = d.getElementsByTagName(s)[0]; sn.parentNode.insertBefore(gcw, sn);
})(document, window, 'script');
`,
}}
/>
</body>
</html>
);
+50 -9
View File
@@ -1,9 +1,50 @@
import mysql from 'mysql2/promise'
export const bd = mysql.createPool({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE,
charset: 'utf8mb4',
})
import Database from 'better-sqlite3';
import fs from 'fs';
import path from 'path';
const DB_PATH = path.join(process.cwd(), 'data', 'strike-arena.db');
const INIT_SQL = path.join(process.cwd(), 'init', 'init.sqlite.sql');
function openDb(): Database.Database {
const dir = path.dirname(DB_PATH);
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
const db = new Database(DB_PATH);
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
// Seed on first run (no tables yet)
const tables = db.prepare("SELECT count(*) as n FROM sqlite_master WHERE type='table'").get() as { n: number };
if (tables.n === 0 && fs.existsSync(INIT_SQL)) {
const sql = fs.readFileSync(INIT_SQL, 'utf-8');
db.exec(sql);
}
return db;
}
// Singleton: reuse across hot-reload in dev
declare global {
// eslint-disable-next-line no-var
var __sqlite_db: Database.Database | undefined;
}
const db: Database.Database = global.__sqlite_db ?? (global.__sqlite_db = openDb());
function isSelect(sql: string) {
return /^\s*(SELECT|PRAGMA|WITH)/i.test(sql.trim());
}
export const bd = {
query: async (sql: string, params: unknown[] = []): Promise<any[]> => {
const stmt = db.prepare(sql);
if (isSelect(sql)) {
return [stmt.all(...(params as any[]))];
}
const info = stmt.run(...(params as any[]));
return [{ insertId: info.lastInsertRowid, affectedRows: info.changes }];
},
execute: async (sql: string, params: unknown[] = []): Promise<any[]> => {
return bd.query(sql, params);
},
};