This repository has been archived by the owner on Nov 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from recoskyler/recoskyler-dev
Fixes and simple stats panel
- Loading branch information
Showing
14 changed files
with
386 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<script lang="ts"> | ||
import { | ||
AccordionItem, | ||
SlideToggle, | ||
} from "@skeletonlabs/skeleton"; | ||
import type { PageData } from "../../routes/app/profile/$types"; | ||
import Fa from "svelte-fa"; | ||
import { | ||
faChartSimple, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { getCookie, setCookie } from "$lib/functions/helper"; | ||
import { onMount } from "svelte"; | ||
import { browser } from "$app/environment"; | ||
import { DO_NOT_TRACK_COOKIE_NAME } from "$lib/constants"; | ||
let analyticsEnabled = false; | ||
const toggleAnalytics = () => { | ||
if (!browser) { | ||
console.error("Not a browser. Cannot save settings"); | ||
return; | ||
} | ||
setCookie( | ||
DO_NOT_TRACK_COOKIE_NAME, | ||
analyticsEnabled ? "false" : "true", | ||
365, | ||
); | ||
console.info(`${analyticsEnabled ? "Enabled" : "Disabled"} analytics`); | ||
}; | ||
onMount(() => { | ||
const cookieVal = getCookie(DO_NOT_TRACK_COOKIE_NAME); | ||
analyticsEnabled = cookieVal === "false" || cookieVal === "" ? true : false; | ||
}); | ||
</script> | ||
|
||
<AccordionItem> | ||
<svelte:fragment slot="lead"> | ||
<Fa fw icon={faChartSimple} /> | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="summary">Analytics</svelte:fragment> | ||
|
||
<svelte:fragment slot="content"> | ||
<p> | ||
<span class="text-orange-600 dark:text-orange-400" | ||
><strong>WARNING: </strong></span | ||
> | ||
<!-- eslint-disable-next-line max-len --> | ||
This setting is stored in a cookie. When you sign out, clear the browser cookies, | ||
or block cookies it will be reset to its default state (<strong | ||
>Disabled</strong | ||
>) | ||
</p> | ||
|
||
<SlideToggle | ||
name="enabled" | ||
bind:checked={analyticsEnabled} | ||
on:change={toggleAnalytics} | ||
bgDark="bg-surface-400" | ||
class="my-3" | ||
> | ||
Enable analytics? | ||
</SlideToggle> | ||
|
||
<p> | ||
<strong>Please refresh the page after changing this option</strong> | ||
</p> | ||
</svelte:fragment> | ||
</AccordionItem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import { db } from "$lib/server/drizzle"; | ||
import { error, redirect } from "@sveltejs/kit"; | ||
import type { LayoutServerLoad } from "./$types"; | ||
import { EMAIL_VERIFICATION } from "$lib/constants"; | ||
import { eq } from "drizzle-orm"; | ||
import { user } from "$lib/db/schema"; | ||
|
||
export const load: LayoutServerLoad = async ({ locals }) => { | ||
const session = await locals.auth.validate(); | ||
|
||
if (!session || (EMAIL_VERIFICATION && !session.user.verified)) { | ||
throw redirect(302, "/login"); | ||
} | ||
|
||
const dbUser = await db.query.user.findFirst({ | ||
with: { | ||
accounts: true, | ||
chats: true, | ||
config: { with: { defaultAccount: true } }, | ||
}, | ||
where: eq(user.id, session.user.userId), | ||
}); | ||
|
||
if (!dbUser) throw error(404, "User not found"); | ||
|
||
if (!dbUser.config) throw redirect(302, "/app/setup"); | ||
|
||
return { user: dbUser }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { error, redirect } from "@sveltejs/kit"; | ||
import type { PageServerLoad } from "./$types"; | ||
import { db } from "$lib/server/drizzle"; | ||
import { | ||
account, chat, user, | ||
} from "$lib/db/schema"; | ||
import { eq, sql } from "drizzle-orm"; | ||
import { EMAIL_VERIFICATION } from "$lib/constants"; | ||
|
||
export const load: PageServerLoad = async ({ locals }) => { | ||
const session = await locals.auth.validate(); | ||
|
||
if (!session || (EMAIL_VERIFICATION && !session.user.verified)) { | ||
throw redirect(302, "/login"); | ||
} | ||
|
||
const dbUser = await db.query.user.findFirst({ | ||
with: { | ||
chats: true, | ||
accounts: true, | ||
config: { with: { defaultAccount: true } }, | ||
}, | ||
where: eq(user.id, session.user.userId), | ||
}); | ||
|
||
if (!dbUser) throw error(404, "User not found"); | ||
|
||
if (dbUser.config === null) throw redirect(302, "/app/setup"); | ||
|
||
if (dbUser.config.userRole !== "admin") { | ||
throw redirect(302, "/app"); | ||
} | ||
|
||
const userCount = await db.select({ count: sql<number>`cast(count(${user.id}) as int)` }) | ||
.from(user).execute(); | ||
|
||
const chatsCount = await db.select({ count: sql<number>`cast(count(${chat.id}) as int)` }) | ||
.from(chat).execute(); | ||
|
||
const accountsCount = await db.select({ count: sql<number>`cast(count(${account.id}) as int)` }) | ||
.from(account).execute(); | ||
|
||
return { | ||
user: dbUser, | ||
stats: { | ||
userCount: userCount[0].count, | ||
chatsCount: chatsCount[0].count, | ||
accountsCount: accountsCount[0].count, | ||
}, | ||
}; | ||
}; | ||
|
Oops, something went wrong.