fix: passing reference causes a const object to be incorrectly changed

This commit is contained in:
alikia2x (寒寒) 2025-04-13 22:22:41 +08:00
parent f4d08e944a
commit 7a6892ae8e
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6

View File

@ -3,10 +3,10 @@ import { VERSION } from "./main.ts";
import { createHandlers } from "./utils.ts"; import { createHandlers } from "./utils.ts";
export const rootHandler = createHandlers((c) => { export const rootHandler = createHandlers((c) => {
let singer: Singer | Singer[] | null; let singer: Singer | Singer[];
const shouldShowSpecialSinger = Math.random() < 0.016; const shouldShowSpecialSinger = Math.random() < 0.016;
if (getSingerForBirthday().length !== 0) { if (getSingerForBirthday().length !== 0) {
singer = getSingerForBirthday(); singer = JSON.parse(JSON.stringify(getSingerForBirthday())) as Singer[];
for (const s of singer) { for (const s of singer) {
delete s.birthday; delete s.birthday;
s.message = `${s.name}生日快乐~`; s.message = `${s.name}生日快乐~`;