Add metadata (hash, ramUsage) to be returns

Allows for better dirty checking and integrations
This commit is contained in:
Xi-Lin Yeh 2022-01-21 20:49:12 -08:00
parent 935f4718e0
commit cf8908fbc8

@ -4,6 +4,7 @@ import { Terminal } from "./Terminal";
import { SnackbarEvents } from "./ui/React/Snackbar"; import { SnackbarEvents } from "./ui/React/Snackbar";
import { IMap, IReturnStatus } from "./types"; import { IMap, IReturnStatus } from "./types";
import { GetServer } from "./Server/AllServers"; import { GetServer } from "./Server/AllServers";
import { resolve } from "cypress/types/bluebird";
export function initElectron(): void { export function initElectron(): void {
const userAgent = navigator.userAgent.toLowerCase(); const userAgent = navigator.userAgent.toLowerCase();
@ -43,7 +44,9 @@ function initWebserver(): void {
data: { data: {
files: home.scripts.map((script) => ({ files: home.scripts.map((script) => ({
filename: script.filename, filename: script.filename,
code: script.code code: script.code,
hash: script.hash(),
ramUsage: script.ramUsage
})) }))
} }
} }
@ -72,12 +75,17 @@ function initWebserver(): void {
msg: "Home server does not exist." msg: "Home server does not exist."
} }
} }
const result = home.writeToScriptFile(Player, filename, code); const {success, overwritten} = home.writeToScriptFile(Player, filename, code);
let script;
if (success) {
script = home.getScript(filename);
}
return { return {
res: result.success, res: success,
data: { data: {
overwritten: result.overwritten overwritten,
hash: script?.hash() || undefined,
ramUsage: script?.ramUsage
} }
}; };
}; };