Spaces:
Building
Building
File size: 569 Bytes
f152ae2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import temporaryDirectory from "temp-dir";
function getSearchTokenFilePath() {
return path.resolve(temporaryDirectory, "minisearch-token");
}
export const getSearchToken = () => {
if (!existsSync(getSearchTokenFilePath())) regenerateSearchToken();
return readFileSync(getSearchTokenFilePath(), "utf8");
};
export function regenerateSearchToken() {
const newToken = Math.random().toString(36).substring(2);
writeFileSync(getSearchTokenFilePath(), newToken);
}
|