Update to svelte 5
This commit is contained in:
@@ -1,35 +1,40 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { get_endpoint } from "lib/PixeldrainAPI";
|
||||
import { createEventDispatcher, onMount } from "svelte";
|
||||
import { formatDuration } from "util/Formatting";
|
||||
let dispatch = createEventDispatcher()
|
||||
|
||||
export let running_since = ""
|
||||
interface Props {
|
||||
running_since?: string;
|
||||
}
|
||||
|
||||
$: profile_running = running_since != "0001-01-01T00:00:00Z" && running_since != ""
|
||||
let { running_since = "" }: Props = $props();
|
||||
|
||||
let profile_running = $derived(running_since != "0001-01-01T00:00:00Z" && running_since != "")
|
||||
|
||||
const start = async () => {
|
||||
if (!profile_running) {
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/admin/cpu_profile",
|
||||
get_endpoint()+"/admin/cpu_profile",
|
||||
{ method: "POST" }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
} else {
|
||||
window.open(window.api_endpoint+"/admin/cpu_profile")
|
||||
window.open(get_endpoint()+"/admin/cpu_profile")
|
||||
}
|
||||
|
||||
dispatch("refresh")
|
||||
}
|
||||
|
||||
let interval
|
||||
let running_time = "0s"
|
||||
let interval: number
|
||||
let running_time = $state("0s")
|
||||
onMount(() => {
|
||||
interval = setInterval(() => {
|
||||
if (profile_running) {
|
||||
running_time = formatDuration(
|
||||
(new Date()).getTime() - Date.parse(running_since),
|
||||
(new Date()).getTime() - Date.parse(running_since), 3
|
||||
)
|
||||
}
|
||||
}, 1000)
|
||||
@@ -43,7 +48,7 @@ onMount(() => {
|
||||
|
||||
<a class="button" href="/api/admin/call_stack">Call stack</a>
|
||||
<a class="button" href="/api/admin/heap_profile">Heap profile</a>
|
||||
<button on:click={start} class:button_red={profile_running}>
|
||||
<button onclick={start} class:button_red={profile_running}>
|
||||
{#if profile_running}
|
||||
Stop CPU profiling (running for {running_time})
|
||||
{:else}
|
||||
|
Reference in New Issue
Block a user