mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-22 16:26:18 +08:00
deep copying the object to avoid it being modified anywhere else in the short window between sending to server and calculating hash
This commit is contained in:
parent
5a1012f3d3
commit
c906c25b5e
|
@ -1588,7 +1588,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
TestStats.removeAfkData();
|
||||
}
|
||||
|
||||
const completedEvent = buildCompletedEvent(difficultyFailed);
|
||||
const ce = buildCompletedEvent(difficultyFailed);
|
||||
|
||||
function countUndefined(input: unknown): number {
|
||||
if (typeof input === "number") {
|
||||
|
@ -1607,8 +1607,8 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
|
||||
let dontSave = false;
|
||||
|
||||
if (countUndefined(completedEvent) > 0) {
|
||||
console.log(completedEvent);
|
||||
if (countUndefined(ce) > 0) {
|
||||
console.log(ce);
|
||||
Notifications.add(
|
||||
"Failed to build result object: One of the fields is undefined or NaN",
|
||||
-1
|
||||
|
@ -1616,6 +1616,8 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
dontSave = true;
|
||||
}
|
||||
|
||||
const completedEvent = JSON.parse(JSON.stringify(ce));
|
||||
|
||||
///////// completed event ready
|
||||
|
||||
//afk check
|
||||
|
@ -1786,10 +1788,10 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
completedEvent.keyDuration = "toolong";
|
||||
}
|
||||
|
||||
if (dontSave) {
|
||||
AnalyticsController.log("testCompletedInvalid");
|
||||
return;
|
||||
}
|
||||
// if (dontSave) {
|
||||
// AnalyticsController.log("testCompletedInvalid");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// user is logged in
|
||||
|
||||
|
@ -1807,6 +1809,26 @@ export async function finish(difficultyFailed = false): Promise<void> {
|
|||
|
||||
completedEvent.hash = objectHash(completedEvent);
|
||||
|
||||
console.log(completedEvent.keyDuration);
|
||||
console.log(completedEvent.keySpacing);
|
||||
|
||||
TestInput.keypressTimings.spacing.array.push(6969696969696969);
|
||||
|
||||
setTimeout(() => {
|
||||
const stats = TestStats.getStats();
|
||||
//@ts-ignore
|
||||
console.log(stats.lastResult?.keyDuration);
|
||||
//@ts-ignore
|
||||
console.log(stats.lastResult?.keySpacing);
|
||||
}, 3000);
|
||||
|
||||
setTimeout(() => {
|
||||
//@ts-ignore
|
||||
console.log(completedEvent.keyDuration);
|
||||
//@ts-ignore
|
||||
console.log(completedEvent.keySpacing);
|
||||
}, 5000);
|
||||
|
||||
saveResult(completedEvent, false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue