Fix admin-badges: handle non-positive userId, truncate badge code to 32 chars, only revalidate on grant
CI / check (push) Failing after 23s
CI / tests-unit (push) Skipped
CI / tests-integration (push) Skipped
CI / tests-ui (push) Skipped
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Gitea Actions Runner Test / test-job (push) Successful in 3s
Gitea Runner Clean Test / test-job (push) Successful in 2s
CI / check (push) Failing after 23s
CI / tests-unit (push) Skipped
CI / tests-integration (push) Skipped
CI / tests-ui (push) Skipped
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Gitea Actions Runner Test / test-job (push) Successful in 3s
Gitea Runner Clean Test / test-job (push) Successful in 2s
This commit is contained in:
1 parent
f14a0e5fe7
commit
b13c9f47be
1 file changed
+12
-5
@@ -31,14 +31,17 @@ export async function giveBadge(formData: FormData): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process each user/code combination
|
// Process each user/code combination
|
||||||
|
let granted = false;
|
||||||
for (const userId of userIds) {
|
for (const userId of userIds) {
|
||||||
for (const code of codes) {
|
for (const code of codes) {
|
||||||
const cid = String(Number(code) || code);
|
|
||||||
if (!(Number(userId) > 0) || code.length === 0) continue;
|
if (!(Number(userId) > 0) || code.length === 0) continue;
|
||||||
|
|
||||||
|
// Truncate badge code to 32 characters.
|
||||||
|
const truncatedCode = code.slice(0, 32);
|
||||||
|
|
||||||
// Fire the emulator command so the badge appears live for online users.
|
// Fire the emulator command so the badge appears live for online users.
|
||||||
try {
|
try {
|
||||||
await rcon.giveBadge(Number(userId), cid);
|
await rcon.giveBadge(Number(userId), truncatedCode);
|
||||||
} catch {
|
} catch {
|
||||||
// ignore rcon errors per pair
|
// ignore rcon errors per pair
|
||||||
}
|
}
|
||||||
@@ -53,7 +56,7 @@ export async function giveBadge(formData: FormData): Promise<void> {
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(UsersBadges.userId, Number(userId)),
|
eq(UsersBadges.userId, Number(userId)),
|
||||||
eq(UsersBadges.badgeCode, code),
|
eq(UsersBadges.badgeCode, truncatedCode),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -65,13 +68,17 @@ export async function giveBadge(formData: FormData): Promise<void> {
|
|||||||
const slotId = (agg?.maxSlot ?? 0) + 1;
|
const slotId = (agg?.maxSlot ?? 0) + 1;
|
||||||
await db
|
await db
|
||||||
.insert(UsersBadges)
|
.insert(UsersBadges)
|
||||||
.values({ userId: Number(userId), slotId, badgeCode: code });
|
.values({ userId: Number(userId), slotId, badgeCode: truncatedCode });
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Best-effort: the RCON grant already succeeded for online users.
|
// Best-effort: the RCON grant already succeeded for online users.
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
granted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (granted) {
|
||||||
revalidatePath("/admin/badges");
|
revalidatePath("/admin/badges");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user