feat (?): add a button for photon instances that enable to let users enable diagnostics
This commit is contained in:
3 files changed
+113
No files matched your search
@@ -723,6 +723,14 @@
|
|||||||
"export": "Export",
|
"export": "Export",
|
||||||
"import": "Import",
|
"import": "Import",
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
|
"usageInfo": {
|
||||||
|
"title": "Send usage info",
|
||||||
|
"body": "You can help the development of Photon by sending information about how you use the app. This is entirely opt-in, and nothing is shared when you don't explicitly ask to.\n\nThe data under 'payload' will be sent to `https://{{hostname}}/api/diagnostic` via `POST`, and such data will be handled by the owner(s) of **{{hostname}}**.",
|
||||||
|
"profiles": "Profile count and instances (no usernames)",
|
||||||
|
"settings": "Your chosen photon settings",
|
||||||
|
"device": "Info about your device",
|
||||||
|
"payload": "Payload"
|
||||||
|
},
|
||||||
"navigation": {
|
"navigation": {
|
||||||
"title": "Navigation",
|
"title": "Navigation",
|
||||||
"dockPos": {
|
"dockPos": {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { RequestHandler } from '@sveltejs/kit'
|
||||||
|
import { env as envPrivate } from '$env/dynamic/private'
|
||||||
|
|
||||||
|
// this is a very rudimentary 'security' system.
|
||||||
|
export const POST: RequestHandler = async ({ request, getClientAddress }) => {
|
||||||
|
const body = await request.json()
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
theme: body.theme,
|
||||||
|
profiles: body.profiles,
|
||||||
|
settings: body.settings,
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetch(envPrivate.PRIVATE_DIAGNOSTICS_URL, {
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers: {
|
||||||
|
Authorization: envPrivate.PRIVATE_DIAGNOSTIC_KEY,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
// so that any upstream diagnostic server can handle abuse
|
||||||
|
'x-forwarded-for': getClientAddress(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(JSON.stringify({ success: true, storedData: payload }))
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
Bars2,
|
Bars2,
|
||||||
Bars3,
|
Bars3,
|
||||||
BarsArrowDown,
|
BarsArrowDown,
|
||||||
|
Beaker,
|
||||||
BookOpen,
|
BookOpen,
|
||||||
BugAnt,
|
BugAnt,
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -69,9 +70,54 @@
|
|||||||
import Section from './Section.svelte'
|
import Section from './Section.svelte'
|
||||||
import Setting from './Setting.svelte'
|
import Setting from './Setting.svelte'
|
||||||
import ToggleSetting from './ToggleSetting.svelte'
|
import ToggleSetting from './ToggleSetting.svelte'
|
||||||
|
import { page } from '$app/state'
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
|
||||||
let importing = $state(false)
|
let importing = $state(false)
|
||||||
let importText = $state('')
|
let importText = $state('')
|
||||||
|
|
||||||
|
let diagnostic = $state({
|
||||||
|
open: false,
|
||||||
|
profile: false,
|
||||||
|
settings: false,
|
||||||
|
device: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
let diagPayload = $derived(calculatePayload(diagnostic))
|
||||||
|
|
||||||
|
function calculatePayload(args: {
|
||||||
|
profile: boolean
|
||||||
|
settings: boolean
|
||||||
|
device: boolean
|
||||||
|
}) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
let payload: Record<string, any> = {}
|
||||||
|
|
||||||
|
if (args.profile) {
|
||||||
|
payload.profiles = {
|
||||||
|
count: profile.meta.profiles.length,
|
||||||
|
instances: [profile.meta.profiles.map(i => i.instance)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.settings) {
|
||||||
|
payload.settings = $state.snapshot(settings)
|
||||||
|
}
|
||||||
|
if (args.device) {
|
||||||
|
payload.device = {
|
||||||
|
userAgent: navigator.userAgent,
|
||||||
|
windowSize: {
|
||||||
|
width: window.innerWidth,
|
||||||
|
height: window.innerHeight,
|
||||||
|
ratio: window.devicePixelRatio,
|
||||||
|
},
|
||||||
|
language: navigator.language,
|
||||||
|
platform: navigator.platform,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
let localeMap: Map<
|
let localeMap: Map<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
@@ -132,6 +178,27 @@
|
|||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if diagnostic.open}
|
||||||
|
<Modal title={$t('settings.usageInfo.title')} bind:open={diagnostic.open}>
|
||||||
|
<Markdown
|
||||||
|
source={$t('settings.usageInfo.body', { hostname: page.url.hostname })}
|
||||||
|
/>
|
||||||
|
<hr class="my-1 border-slate-200 dark:border-zinc-800" />
|
||||||
|
<Switch bind:checked={diagnostic.profile}>
|
||||||
|
{$t('settings.usageInfo.profiles')}
|
||||||
|
</Switch>
|
||||||
|
<Switch bind:checked={diagnostic.settings}>
|
||||||
|
{$t('settings.usageInfo.settings')}
|
||||||
|
</Switch>
|
||||||
|
<Switch bind:checked={diagnostic.device}>
|
||||||
|
{$t('settings.usageInfo.device')}
|
||||||
|
</Switch>
|
||||||
|
<pre class="max-w-full">
|
||||||
|
{JSON.stringify(diagPayload, undefined, 2)}
|
||||||
|
</pre>
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Header pageHeader class="text-3xl font-bold flex justify-between">
|
<Header pageHeader class="text-3xl font-bold flex justify-between">
|
||||||
{$t('settings.title')}
|
{$t('settings.title')}
|
||||||
{#snippet extended()}
|
{#snippet extended()}
|
||||||
@@ -204,6 +271,19 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if env.PUBLIC_DIAGNOSTICS.toLowerCase() == 'true'}
|
||||||
|
<Button
|
||||||
|
onclick={() => (diagnostic.open = !diagnostic.open)}
|
||||||
|
rounding="pill"
|
||||||
|
class="w-max"
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={Beaker} mini size="18" />
|
||||||
|
{/snippet}
|
||||||
|
{$t('settings.usageInfo.title')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-col *:py-2 divide-y divide-slate-200 dark:divide-zinc-800"
|
class="flex flex-col *:py-2 divide-y divide-slate-200 dark:divide-zinc-800"
|
||||||
style="scroll-behavior: smooth;"
|
style="scroll-behavior: smooth;"
|
||||||
|
|||||||
Reference in new issue
Block a user