changes
This commit is contained in:
1 parent
a99af426db
commit
8886aa8640
91 files changed
+2823
-773
No files matched your search
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* Capture full-page screenshots of public + admin routes for visual review.
|
||||
* Usage: node scripts/capture-page-screenshots.mjs
|
||||
* Requires: local next dev on BASE_URL, and npx playwright chromium installed.
|
||||
*/
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { chromium } from "playwright";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(__dirname, "..");
|
||||
const outDir = path.join(root, "docs", "review", "screenshots");
|
||||
const BASE = process.env.BASE_URL || "http://localhost:3000";
|
||||
const ADMIN_EMAIL = process.env.SMOKE_ADMIN_EMAIL || "admin@aut.ac.ir";
|
||||
const ADMIN_PASSWORD = process.env.SMOKE_ADMIN_PASSWORD || "admin123";
|
||||
|
||||
const publicPages = [
|
||||
{ id: "01-home", url: "/", title: "صفحه اصلی (/)" },
|
||||
{ id: "02-professional", url: "/professional", title: "لندینگ حرفهای (/professional)" },
|
||||
{ id: "03-about", url: "/about", title: "درباره ما (/about)" },
|
||||
{ id: "04-values", url: "/values", title: "ارزشها (/values)" },
|
||||
{ id: "05-contact", url: "/contact", title: "تماس (/contact)" },
|
||||
{ id: "06-alumni", url: "/alumni", title: "دانشآموختگان (/alumni)" },
|
||||
{ id: "07-events", url: "/events", title: "فهرست رویدادها (/events)" },
|
||||
{ id: "08-event-detail", url: "/events/evt-1", title: "جزئیات رویداد (/events/evt-1)" },
|
||||
{ id: "09-insights", url: "/insights", title: "فهرست بینشها (/insights)" },
|
||||
{ id: "10-insight-detail", url: "/insights/art-1", title: "جزئیات مقاله (/insights/art-1)" },
|
||||
{ id: "11-programs", url: "/programs", title: "فهرست برنامهها (/programs)" },
|
||||
{
|
||||
id: "12-program-detail",
|
||||
url: "/programs/management-core",
|
||||
title: "جزئیات برنامه (/programs/management-core)",
|
||||
},
|
||||
{
|
||||
id: "13-topic-detail",
|
||||
url: "/topics/ai-organizational-transformation",
|
||||
title: "موضوع (/topics/ai-organizational-transformation)",
|
||||
},
|
||||
{
|
||||
id: "14-register",
|
||||
url: "/register/ai-fluency",
|
||||
title: "ثبتنام/علاقه (/register/ai-fluency)",
|
||||
},
|
||||
{ id: "15-privacy", url: "/privacy", title: "حریم خصوصی (/privacy)" },
|
||||
{ id: "16-accessibility", url: "/accessibility", title: "دسترسیپذیری (/accessibility)" },
|
||||
{ id: "17-press", url: "/press", title: "روابط عمومی (/press)" },
|
||||
{ id: "18-careers", url: "/careers", title: "همکاری با ما (/careers)" },
|
||||
{ id: "19-faculty-redirect", url: "/faculty", title: "اساتید (/faculty → ریدایرکت خارجی)" },
|
||||
];
|
||||
|
||||
const adminPages = [
|
||||
{ id: "20-admin-login", url: "/admin/login", title: "ورود ادمین (/admin/login)", login: false },
|
||||
{ id: "21-admin-dashboard", url: "/admin", title: "داشبورد ادمین (/admin)", login: true },
|
||||
{ id: "22-admin-courses", url: "/admin/courses", title: "لیست دورهها (/admin/courses)", login: true },
|
||||
{
|
||||
id: "23-admin-course-new",
|
||||
url: "/admin/courses/new",
|
||||
title: "ایجاد دوره — فیلد آپلود تصویر (/admin/courses/new)",
|
||||
login: true,
|
||||
},
|
||||
{
|
||||
id: "24-admin-articles",
|
||||
url: "/admin/articles",
|
||||
title: "لیست مقالات (/admin/articles)",
|
||||
login: true,
|
||||
},
|
||||
{
|
||||
id: "25-admin-articles-new",
|
||||
url: "/admin/articles/new",
|
||||
title: "ایجاد مقاله — فیلد آپلود (/admin/articles/new)",
|
||||
login: true,
|
||||
},
|
||||
{
|
||||
id: "26-admin-registrations",
|
||||
url: "/admin/registrations",
|
||||
title: "ثبتنامها (/admin/registrations)",
|
||||
login: true,
|
||||
},
|
||||
];
|
||||
|
||||
async function capture(page, item) {
|
||||
const result = {
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
url: item.url,
|
||||
finalUrl: "",
|
||||
status: "ok",
|
||||
note: "",
|
||||
file: `${item.id}.png`,
|
||||
};
|
||||
try {
|
||||
const response = await page.goto(new URL(item.url, BASE).toString(), {
|
||||
waitUntil: "domcontentloaded",
|
||||
timeout: 60000,
|
||||
});
|
||||
await page.waitForTimeout(1200);
|
||||
result.finalUrl = page.url();
|
||||
result.httpStatus = response?.status() ?? null;
|
||||
if (item.id === "19-faculty-redirect") {
|
||||
result.note =
|
||||
"این مسیر در next.config به سایت خارجی mst.aut.ac.ir ریدایرکت دائمی میشود؛ صفحه داخلی ندارد.";
|
||||
if (!result.finalUrl.includes("localhost")) {
|
||||
result.status = "redirect-external";
|
||||
}
|
||||
}
|
||||
const dest = path.join(outDir, result.file);
|
||||
await page.screenshot({ path: dest, fullPage: true });
|
||||
if (result.httpStatus && result.httpStatus >= 400) {
|
||||
result.status = "http-error";
|
||||
result.note = `HTTP ${result.httpStatus}`;
|
||||
}
|
||||
} catch (err) {
|
||||
result.status = "failed";
|
||||
result.note = err instanceof Error ? err.message : String(err);
|
||||
try {
|
||||
await page.screenshot({
|
||||
path: path.join(outDir, result.file),
|
||||
fullPage: true,
|
||||
});
|
||||
} catch {
|
||||
result.file = "";
|
||||
}
|
||||
}
|
||||
console.log(`${result.status.padEnd(18)} ${item.id} → ${result.finalUrl || item.url}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function loginAdmin(page, context) {
|
||||
// Prefer API login so cookie is set reliably (UI uses client fetch + router.push).
|
||||
const res = await page.request.post(new URL("/api/admin/login", BASE).toString(), {
|
||||
data: { email: ADMIN_EMAIL, password: ADMIN_PASSWORD },
|
||||
});
|
||||
if (!res.ok()) {
|
||||
throw new Error(`admin login API ${res.status()}: ${await res.text()}`);
|
||||
}
|
||||
await page.goto(new URL("/admin", BASE).toString(), {
|
||||
waitUntil: "domcontentloaded",
|
||||
timeout: 60000,
|
||||
});
|
||||
await page.waitForTimeout(800);
|
||||
return page.url();
|
||||
}
|
||||
|
||||
const report = [];
|
||||
await mkdir(outDir, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 900 },
|
||||
locale: "fa-IR",
|
||||
});
|
||||
const page = await context.newPage();
|
||||
|
||||
for (const item of publicPages) {
|
||||
report.push(await capture(page, item));
|
||||
}
|
||||
|
||||
let loggedIn = false;
|
||||
for (const item of adminPages) {
|
||||
if (item.login && !loggedIn) {
|
||||
try {
|
||||
const after = await loginAdmin(page, context);
|
||||
loggedIn = after.includes("/admin") && !after.includes("/login");
|
||||
if (!loggedIn) {
|
||||
report.push({
|
||||
id: "login-blocker",
|
||||
title: "ورود ادمین",
|
||||
url: "/admin/login",
|
||||
finalUrl: after,
|
||||
status: "blocked",
|
||||
note: "لاگین ادمین موفق نشد؛ صفحات محافظتشده اسکرین نشدند. احتمالاً cookie Secure روی http یا رمز اشتباه.",
|
||||
file: "",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
report.push({
|
||||
id: "login-blocker",
|
||||
title: "ورود ادمین",
|
||||
url: "/admin/login",
|
||||
finalUrl: "",
|
||||
status: "blocked",
|
||||
note: err instanceof Error ? err.message : String(err),
|
||||
file: "",
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
report.push(await capture(page, item));
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
const md = [];
|
||||
md.push("# بازبینی صفحات سایت — اسکرینشات");
|
||||
md.push("");
|
||||
md.push(`تاریخ: ${new Date().toISOString()}`);
|
||||
md.push(`پایه: \`${BASE}\``);
|
||||
md.push("");
|
||||
md.push("هر ردیف یک مسیر واقعی است. تصویر full-page در پوشهٔ `screenshots/` است.");
|
||||
md.push("");
|
||||
|
||||
for (const r of report) {
|
||||
md.push(`## ${r.title}`);
|
||||
md.push("");
|
||||
md.push(`- مسیر: \`${r.url}\``);
|
||||
if (r.finalUrl) md.push(`- URL نهایی: \`${r.finalUrl}\``);
|
||||
if (r.httpStatus != null) md.push(`- HTTP: ${r.httpStatus}`);
|
||||
md.push(`- وضعیت: **${r.status}**`);
|
||||
if (r.note) md.push(`- توضیح: ${r.note}`);
|
||||
if (r.file) {
|
||||
md.push("");
|
||||
md.push(``);
|
||||
}
|
||||
md.push("");
|
||||
}
|
||||
|
||||
md.push("## نکات کلی برای بررسی");
|
||||
md.push("");
|
||||
md.push("- viewport دسکتاپ ۱۴۴۰×۹۰۰؛ اسکرین full-page است.");
|
||||
md.push("- `/faculty` عمداً ریدایرکت خارجی است (صفحهٔ داخلی ندارد).");
|
||||
md.push("- جزئیات همهٔ دورهها/برنامهها/رویدادها تکرار نشد؛ از هر نوع یک نمونه گرفته شد.");
|
||||
md.push("- صفحات ادمین edit برای همهٔ entityها تکراریاند؛ نمونهٔ دوره و مقاله کافی است.");
|
||||
md.push("");
|
||||
|
||||
const reportPath = path.join(root, "docs", "review", "PAGE-AUDIT.md");
|
||||
await writeFile(reportPath, md.join("\n"), "utf8");
|
||||
await writeFile(path.join(outDir, "report.json"), JSON.stringify(report, null, 2), "utf8");
|
||||
console.log("Wrote", reportPath);
|
||||
console.log("Screenshots:", outDir);
|
||||
@@ -8,17 +8,20 @@ flock 9
|
||||
ENV_FILE=/etc/edu-production.env
|
||||
CONTAINER=aut-management-faculty
|
||||
NETWORK=shared_web_network
|
||||
UPLOAD_VOLUME=edu-uploads
|
||||
REVISION=$(git rev-parse HEAD)
|
||||
IMAGE="aut-management-faculty:$REVISION"
|
||||
|
||||
test -s "$ENV_FILE" || { echo "Missing protected production environment: $ENV_FILE" >&2; exit 1; }
|
||||
docker network inspect "$NETWORK" >/dev/null
|
||||
docker inspect insaight-postgres --format '{{json .NetworkSettings.Networks}}' | grep -q '"shared_web_network"'
|
||||
docker volume create "$UPLOAD_VOLUME" >/dev/null
|
||||
|
||||
# Keep the current app running throughout the build.
|
||||
docker build --build-arg NEXT_PUBLIC_SITE_URL=https://edu.mstaut.ir -t "$IMAGE" .
|
||||
|
||||
# Back up before applying the repository's transactional, versioned migrations.
|
||||
# Migrations are forward-only and idempotent (schema_migrations); dump is the safety net.
|
||||
install -d -m 700 /opt/backups/edu
|
||||
BACKUP="/opt/backups/edu/database-$(date -u +%Y%m%dT%H%M%SZ).dump"
|
||||
docker exec insaight-postgres sh -c 'pg_dump -U "$POSTGRES_USER" -d ManagmentWebSite_Db -Fc' > "$BACKUP"
|
||||
@@ -29,7 +32,10 @@ docker run --rm --network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
|
||||
# Check the database and rendered pages before switching the public upstream.
|
||||
CANDIDATE="edu-candidate-${REVISION:0:12}"
|
||||
docker run -d --name "$CANDIDATE" --network "$NETWORK" --env-file "$ENV_FILE" "$IMAGE"
|
||||
docker run -d --name "$CANDIDATE" --network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
-e UPLOAD_DIR=/app/public/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/public/uploads" \
|
||||
"$IMAGE"
|
||||
cleanup_candidate() { docker rm -f "$CANDIDATE" >/dev/null 2>&1 || true; }
|
||||
trap cleanup_candidate EXIT
|
||||
READY=false
|
||||
@@ -73,7 +79,10 @@ rollback() {
|
||||
}
|
||||
trap rollback ERR
|
||||
docker run -d --name "$CONTAINER" --restart unless-stopped \
|
||||
--network "$NETWORK" --env-file "$ENV_FILE" -p 127.0.0.1:3000:3000 "$IMAGE"
|
||||
--network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
-e UPLOAD_DIR=/app/public/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/public/uploads" \
|
||||
-p 127.0.0.1:3000:3000 "$IMAGE"
|
||||
READY=false
|
||||
for attempt in $(seq 1 30); do
|
||||
if curl -fsS --max-time 5 --resolve edu.mstaut.ir:443:127.0.0.1 https://edu.mstaut.ir/ >/dev/null; then
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
// Usage: node scripts/test-db-connection.mjs
|
||||
// Reads DATABASE_URL from the environment or .env.local (never hardcode hosts/passwords).
|
||||
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import pg from "pg";
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
const client = new Client({
|
||||
host: "185.36.145.12",
|
||||
port: 5432,
|
||||
database: "ManagmentWebSite_Db",
|
||||
user: "managment_web",
|
||||
password: process.env.DB_PASSWORD,
|
||||
if (!process.env.DATABASE_URL) {
|
||||
const envPath = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
"..",
|
||||
".env.local",
|
||||
);
|
||||
if (existsSync(envPath)) {
|
||||
for (const line of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (match && !(match[1] in process.env)) {
|
||||
process.env[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connectionTimeoutMillis: 20000,
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error("CONNECTION_FAIL");
|
||||
console.error("DATABASE_URL is not set. Copy .env.example → .env.local and fill it in.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
connectionTimeoutMillis: 10000,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -26,6 +49,14 @@ try {
|
||||
console.log("CONNECTION_OK");
|
||||
console.log(JSON.stringify(info.rows[0], null, 2));
|
||||
|
||||
const migrations = await client.query(
|
||||
"SELECT version, applied_at FROM schema_migrations ORDER BY version",
|
||||
).catch(() => ({ rows: [] }));
|
||||
console.log("migrations_applied:", migrations.rows.length);
|
||||
if (migrations.rows.length) {
|
||||
console.log(JSON.stringify(migrations.rows.map((r) => r.version), null, 2));
|
||||
}
|
||||
|
||||
const tables = await client.query(`
|
||||
SELECT table_schema, table_name
|
||||
FROM information_schema.tables
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import pg from "pg";
|
||||
import { readFileSync, existsSync } from "fs";
|
||||
|
||||
if (existsSync(".env.local")) {
|
||||
for (const line of readFileSync(".env.local", "utf8").split(/\r?\n/)) {
|
||||
const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (m && !(m[1] in process.env)) process.env[m[1]] = m[2];
|
||||
}
|
||||
}
|
||||
|
||||
const c = new pg.Client({ connectionString: process.env.DATABASE_URL });
|
||||
await c.connect();
|
||||
const r = await c.query(`
|
||||
SELECT c.slug,
|
||||
(SELECT json_agg(json_build_object('id',cat.id,'slug',cat.slug,'label',cat.label)
|
||||
ORDER BY cat.sort_order)
|
||||
FROM course_category_links l
|
||||
JOIN course_categories cat ON cat.id=l.category_id
|
||||
WHERE l.course_id=c.id) AS categories,
|
||||
(SELECT json_agg(json_build_object('id',t.id,'slug',t.slug,'label',t.label)
|
||||
ORDER BY t.sort_order)
|
||||
FROM course_tag_links l
|
||||
JOIN course_tags t ON t.id=l.tag_id
|
||||
WHERE l.course_id=c.id) AS tags
|
||||
FROM courses c
|
||||
LIMIT 2
|
||||
`);
|
||||
console.log(JSON.stringify(r.rows, null, 2));
|
||||
await c.end();
|
||||
Reference in new issue
Block a user