refactor: move visit count to lib
All checks were successful
create archive with lfs / tag (push) Successful in 8s

This commit is contained in:
dusk 2024-10-01 04:34:07 +03:00
parent 3ba07e7b93
commit d62b71db61
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 9 additions and 7 deletions

View File

@ -1,4 +1,6 @@
import type { Cookies } from '@sveltejs/kit'
import { existsSync, readFileSync } from 'fs'
import { writable } from 'svelte/store'
export const scopeCookies = (cookies: Cookies, path: string) => {
return {
@ -13,3 +15,6 @@ export const scopeCookies = (cookies: Cookies, path: string) => {
}
}
}
export const visitCountFile = 'visitcount'
export const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));

View File

@ -1,15 +1,12 @@
import { scopeCookies } from '$lib';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { get, writable } from 'svelte/store';
import { scopeCookies, visitCount, visitCountFile } from '$lib';
import { writeFileSync } from 'fs';
import { get } from 'svelte/store';
export const csr = true;
export const ssr = true;
export const prerender = true;
export const trailingSlash = 'always';
const visitCountFile = 'visitcount'
const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
export async function load({ cookies, url, setHeaders }) {
setHeaders({ 'Cache-Control': 'no-cache' })
const scopedCookies = scopeCookies(cookies, '/')