2024-10-01 02:44:39 +03:00
|
|
|
import type { Cookies } from '@sveltejs/kit'
|
2024-10-01 04:53:50 +03:00
|
|
|
import { WEBSITE_DATA_DIR } from '$env/static/private'
|
2024-10-01 04:34:07 +03:00
|
|
|
import { existsSync, readFileSync } from 'fs'
|
|
|
|
import { writable } from 'svelte/store'
|
2024-10-01 02:44:39 +03:00
|
|
|
|
|
|
|
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 })
|
|
|
|
}
|
|
|
|
}
|
2024-10-01 04:34:07 +03:00
|
|
|
}
|
|
|
|
|
2024-10-01 04:53:50 +03:00
|
|
|
export const visitCountFile = `${WEBSITE_DATA_DIR}/visitcount`
|
2024-10-01 04:34:07 +03:00
|
|
|
export const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
|