website/src/lib/index.ts
dusk 5d466eb196
All checks were successful
create archive with lfs / tag (push) Successful in 8s
fix: pull env vars from dynamic
2024-10-01 04:59:41 +03:00

21 lines
847 B
TypeScript

import type { Cookies } from '@sveltejs/kit'
import { env } from '$env/dynamic/private'
import { existsSync, readFileSync } from 'fs'
import { writable } from 'svelte/store'
export const scopeCookies = (cookies: Cookies, path: string) => {
return {
get: (key: string) => {
return cookies.get(key)
},
set: (key: string, value: string, props: import('cookie').CookieSerializeOptions = {}) => {
cookies.set(key, value, { ...props, path })
},
delete: (key: string, props: import('cookie').CookieSerializeOptions = {}) => {
cookies.delete(key, { ...props, path })
}
}
}
export const visitCountFile = `${env.WEBSITE_DATA_DIR}/visitcount`
export const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));