File size: 1,692 Bytes
71174bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import { localStorageGetItem, localStorageRemoveItem, localStorageSetItem } from "@/Core/LocalStorage";
/**
* Removes the stat-collection cookie.
*/
export async function removeStatCollectionCookie() {
await localStorageRemoveItem("statcollection");
}
/**
* Enables stat collection.
*/
export async function enableStats() {
await removeStatCollectionCookie();
await localStorageSetItem("statcollection", true);
// Cookies.set("statcollection", "true", {
// // Note that there is a max value you can use. Seems to be around
// // 400. Good to use 365.
// expires: 365,
// sameSite: "strict",
// });
}
/**
* Disables stat collection.
*/
export async function disableStats() {
await removeStatCollectionCookie();
// NOTE: Below is intentionally commented out. NAR doesn't want any cookies
// set if used doesn't explicitly authorize.
// Cookies.set("statcollection", "false", {
// expires: 3,
// sameSite: "strict",
// });
}
/**
* Checks if stat-collection is enabled.
*
* @returns {Promise<boolean>} A promise that resolves whether stat collection
* is enabled.
*/
export async function isStatCollectionEnabled(): Promise<boolean> {
return await localStorageGetItem("statcollection", false);
}
/**
* Checks if stat-collection status is set (whether true or false).
*
* @returns {Promise<boolean>} A promise that resolves whether stat collection
* is set.
*/
export async function isStatStatusSet(): Promise<boolean> {
const status = await localStorageGetItem("statcollection", null);
return status !== null;
}
|