chore: remove dead code flagged by knip
Local Build and Deploy / deploy (push) Successful in 1m7s

Remove 19 unused source files (no importers anywhere in src/):
- src/actions/admin-permissions.ts, admin-radio.ts, admin-user-edit.ts,
  admin-users.ts (functionality lives in @/actions/users and
  @/actions/permissions)
- src/components/admin/confirm-action.tsx, page-header.tsx
- src/components/motion-elements.tsx
- src/lib/format-date.ts
- src/lib/catalog-categories/* (incl. re-export barrel)
- src/lib/foundation/{index,database,middleware,validation}.ts (errors/action
  kept, still imported directly)
- src/lib/services/imager/{avatar-renderer,memory-cache}.ts
- src/lib/services/nitro-assets.ts

Update admin-operations-contract test to drop the two removed action-file
gates (their permission coverage already exists in users.ts/permissions.ts).

Add knip.json for repeatable dead-code audits.

Verified: tsc --noEmit clean, next build succeeds, full test suite green
(301/301).
This commit is contained in:
openhands committed 2026-07-18 19:08:17 +02:00
1 parent 60eb45be73
commit 3c9c1311ec
23 files changed
+586 -2158

No files matched your search

-135
View File
@@ -1,135 +0,0 @@
"use server";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { requirePermission } from "@/lib/admin/guard";
import { PERMS } from "@/lib/permissions";
import { formPositiveBigInt } from "@/lib/form-data";
import { prisma } from "@/lib/prisma";
import { logServerError } from "@/lib/server-log";
import { logStaffActivity } from "@/lib/services/staff-activity";
// website_permissions (model WebsitePermissions) is the CMS-owned permission ->
// minimum-rank mapping. Editable columns are exactly: permission (unique name),
// min_rank (lowest rank that may use it), description. id is BigInt and
// created_at/updated_at are managed here.
function parseMinRank(formData: FormData): number {
const n = Number(
String(formData.get("minRank") ?? "")
.normalize("NFC")
.trim(),
);
return Number.isInteger(n) && n >= 0 ? n : 1;
}
export async function createPermission(formData: FormData): Promise<void> {
const staff = await requirePermission(PERMS.PERMISSIONS_MANAGE);
const permission = String(formData.get("permission") ?? "")
.normalize("NFC")
.trim()
.slice(0, 255);
const minRank = parseMinRank(formData);
const description =
String(formData.get("description") ?? "")
.normalize("NFC")
.trim() || null;
if (!permission) return;
const now = new Date();
try {
await prisma.websitePermissions.upsert({
where: { permission },
update: { minRank, description, updatedAt: now },
create: {
permission,
minRank,
description,
createdAt: now,
updatedAt: now,
},
});
await logStaffActivity({
staffId: staff.id,
action: "permission_create",
description: `Saved permission "${permission}" (min rank ${minRank})`,
targetType: "permission",
});
} catch (error) {
logServerError("admin.permission_create_failed", error, {
staffId: staff.id,
permission,
});
redirect("/admin/permissions?error=save");
// ignore (e.g. constraint failure) — page re-renders current state
}
revalidatePath("/admin/permissions");
redirect("/admin/permissions?saved=1");
}
export async function updatePermission(formData: FormData): Promise<void> {
const staff = await requirePermission(PERMS.PERMISSIONS_MANAGE);
const raw = String(formData.get("id") ?? "").normalize("NFC");
if (!raw) return;
const id = BigInt(raw);
const permission = String(formData.get("permission") ?? "")
.normalize("NFC")
.trim()
.slice(0, 255);
const minRank = parseMinRank(formData);
const description =
String(formData.get("description") ?? "")
.normalize("NFC")
.trim() || null;
if (!permission) return;
try {
await prisma.websitePermissions.update({
where: { id },
data: { permission, minRank, description, updatedAt: new Date() },
});
await logStaffActivity({
staffId: staff.id,
action: "permission_update",
description: `Updated permission #${id} ("${permission}" min rank ${minRank})`,
targetType: "permission",
});
} catch (error) {
logServerError("admin.permission_update_failed", error, {
staffId: staff.id,
permissionId: String(id),
});
redirect("/admin/permissions?error=save");
// ignore (e.g. duplicate) — page re-renders current state
}
revalidatePath("/admin/permissions");
redirect("/admin/permissions?saved=1");
}
export async function deletePermission(formData: FormData): Promise<void> {
const staff = await requirePermission(PERMS.PERMISSIONS_MANAGE);
const id = formPositiveBigInt(formData, "id");
if (!id) return;
try {
const deleted = await prisma.websitePermissions.delete({
where: { id },
select: { permission: true },
});
await logStaffActivity({
staffId: staff.id,
action: "permission_delete",
description: `Deleted permission #${id} ("${deleted.permission}")`,
targetType: "permission",
});
} catch (error) {
logServerError("admin.permission_delete_failed", error, {
staffId: staff.id,
permissionId: String(id),
});
redirect("/admin/permissions?error=delete");
// ignore (e.g. already removed)
}
revalidatePath("/admin/permissions");
redirect("/admin/permissions?saved=1");
}
-1
View File
@@ -1 +0,0 @@
"use server";
-101
View File
@@ -1,101 +0,0 @@
"use server";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { requirePermission } from "@/lib/admin/guard";
import { PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
import { logStaffActivity } from "@/lib/services/staff-activity";
// users_currency.type values for the non-credits currencies (mirror send-currency.ts).
// Credits live on users.credits; pixels/points live on the users row too;
// duckets/diamonds live in users_currency keyed by (user_id, type).
const DUCKETS_TYPE = 0;
const DIAMONDS_TYPE = 5;
function toInt(value: FormDataEntryValue | null, min = 0): number | null {
if (value == null) return null;
const raw = String(value).trim();
if (raw === "") return null;
const n = Number(raw);
if (!Number.isFinite(n)) return null;
const i = Math.trunc(n);
return i < min ? min : i;
}
/**
* Edit the SAFE website-managed fields of a users row (and the duckets/diamonds
* balances in users_currency). Never touches the password. Re-reads the staff
* user from the session and logs the action. emulator-owned users.id is Int.
*/
export async function updateUser(formData: FormData): Promise<void> {
// Never trust the client: re-check USERS_EDIT inside the action.
const staff = await requirePermission(PERMS.USERS_EDIT);
const userId = Number(formData.get("id"));
if (!Number.isInteger(userId) || userId <= 0) return;
const existing = await prisma.user.findUnique({
where: { id: userId },
select: { id: true },
});
if (!existing) return;
// users row — only existing, safe columns.
const mailRaw = String(formData.get("mail") ?? "")
.normalize("NFC")
.trim();
const motto = String(formData.get("motto") ?? "")
.normalize("NFC")
.slice(0, 127);
const look = String(formData.get("look") ?? "")
.normalize("NFC")
.slice(0, 256);
const rank = toInt(formData.get("rank"), 1);
const credits = toInt(formData.get("credits"), 0);
const pixels = toInt(formData.get("pixels"), 0);
const points = toInt(formData.get("points"), 0);
await prisma.user.update({
where: { id: userId },
data: {
mail: mailRaw === "" ? null : mailRaw.slice(0, 500),
motto,
look,
...(rank != null ? { rank } : {}),
...(credits != null ? { credits } : {}),
...(pixels != null ? { pixels } : {}),
...(points != null ? { points } : {}),
},
});
// users_currency — set exact balances for duckets / diamonds.
const duckets = toInt(formData.get("duckets"), 0);
const diamonds = toInt(formData.get("diamonds"), 0);
if (duckets != null) {
await prisma.usersCurrency.upsert({
where: { userId_type: { userId, type: DUCKETS_TYPE } },
update: { amount: duckets },
create: { userId, type: DUCKETS_TYPE, amount: duckets },
});
}
if (diamonds != null) {
await prisma.usersCurrency.upsert({
where: { userId_type: { userId, type: DIAMONDS_TYPE } },
update: { amount: diamonds },
create: { userId, type: DIAMONDS_TYPE, amount: diamonds },
});
}
await logStaffActivity({
staffId: staff.id,
action: "user_edit",
description: `Edited account fields of user #${userId}`,
targetType: "user",
targetId: userId,
});
revalidatePath(`/admin/users/${userId}`);
revalidatePath(`/admin/users/edit/${userId}`);
redirect(`/admin/users/show/${userId}`);
}
-86
View File
@@ -1,86 +0,0 @@
"use server";
import { revalidatePath } from "next/cache";
import { requirePermission, requirePermissionRateLimited } from "@/lib/admin/guard";
import { PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
import { rcon } from "@/lib/services/rcon";
import { type CurrencyName, sendCurrency } from "@/lib/services/send-currency";
import { logStaffActivity } from "@/lib/services/staff-activity";
const CURRENCIES: ReadonlySet<string> = new Set([
"credits",
"duckets",
"diamonds",
"points",
]);
export async function giveCurrency(formData: FormData): Promise<void> {
const staff = await requirePermissionRateLimited(PERMS.USERS_EDIT);
const userId = Number(formData.get("userId"));
const type = String(formData.get("type"));
const amount = Number(formData.get("amount"));
if (userId > 0 && amount > 0 && CURRENCIES.has(type)) {
await sendCurrency(
{ rcon, db: prisma },
userId,
type as CurrencyName,
amount,
);
await logStaffActivity({
staffId: staff.id,
action: "give_currency",
description: `Gave ${amount} ${type} to user #${userId}`,
targetType: "user",
targetId: userId,
});
}
revalidatePath(`/admin/users/${userId}`);
}
export async function setMotto(formData: FormData): Promise<void> {
await requirePermission(PERMS.USERS_EDIT);
const userId = Number(formData.get("userId"));
const motto = String(formData.get("motto") ?? "")
.normalize("NFC")
.slice(0, 127);
if (userId > 0) {
await prisma.user.update({ where: { id: userId }, data: { motto } });
await rcon.setMotto(userId, motto);
}
revalidatePath(`/admin/users/${userId}`);
}
export async function setRank(formData: FormData): Promise<void> {
const staff = await requirePermissionRateLimited(PERMS.USERS_EDIT);
const userId = Number(formData.get("userId"));
const rank = Number(formData.get("rank"));
if (userId > 0 && rank > 0) {
await prisma.user.update({ where: { id: userId }, data: { rank } });
await rcon.setRank(userId, rank);
await logStaffActivity({
staffId: staff.id,
action: "rank_change",
description: `Set rank of user #${userId} to ${rank}`,
targetType: "user",
targetId: userId,
});
}
revalidatePath(`/admin/users/${userId}`);
}
export async function alertUser(formData: FormData): Promise<void> {
await requirePermission(PERMS.USERS_EDIT);
const userId = Number(formData.get("userId"));
const message = String(formData.get("message") ?? "")
.normalize("NFC")
.trim();
if (userId > 0 && message) await rcon.alertUser(userId, message);
}
export async function disconnectUser(formData: FormData): Promise<void> {
await requirePermission(PERMS.USERS_EDIT);
const userId = Number(formData.get("userId"));
const username = String(formData.get("username") ?? "").normalize("NFC");
if (userId > 0) await rcon.disconnectUser(userId, username);
}