MCPcopy Create free account
hub / github.com/esmBot/esmBot / parseThreshold

Function parseThreshold

src/utils/tempimages.ts:123–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121}
122
123export async function parseThreshold() {
124 if (!process.env.THRESHOLD || process.env.THRESHOLD === "") return;
125 if (!process.env.TEMPDIR || process.env.TEMPDIR === "") return;
126 const matched = process.env.THRESHOLD.match(/(\d+)([KMGT])/);
127 const sizes = {
128 K: 1024,
129 M: 1048576,
130 G: 1073741824,
131 T: 1099511627776,
132 };
133 if (matched?.[1] && matched[2]) {
134 threshold = Number(matched[1]) * sizes[matched[2] as SizeSuffix];
135 } else {
136 logger.error("Invalid THRESHOLD config.");
137 threshold = undefined;
138 }
139 const dirstat = (await readdir(process.env.TEMPDIR)).map((file) => {
140 return stat(`${process.env.TEMPDIR}/${file}`).then((stats) => stats.size);
141 });
142 const size = await Promise.all(dirstat);
143 const reduced = size.reduce((a, b) => {
144 return a + b;
145 }, 0);
146 dirSizeCache = reduced;
147}

Callers 1

app.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected