aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/canaries/Canary.svelte
blob: 913216d7586bbbb0371c635bc6d63c85e1342ce6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<script lang="ts">
  import type { Canary } from './canaries';
  let {
    canary,
  }: {
    canary: Canary;
  } = $props();
  let rawText = $state(null as string | null);
  let failedFetch = $state(false);
  let url = $state(
    null as {
      stripped: string;
      signed: string;
    } | null,
  );
  let status = $derived(
    url !== null
      ? ('ok' as const)
      : failedFetch
        ? ('failed_fetch' as const)
        : rawText === null
          ? ('fetching' as const)
          : ('failed_sigcheck' as const),
  );
  $effect(() => {
    (async (canary) => {
      rawText = await canary.getRawText();
    })(canary).catch((e) => {
      failedFetch = true;
    });
  });
  $effect(() => {
    (async (canary) => {
      url = await canary.getUrl();
    })(canary);
  });
</script>

<div
  class={{
    'canary p-4 flex-1 max-w-[1024px] min-w-[min(100%,500px)] overflow-x-auto flex flex-col justify-between rounded-2xl': true,
    'bg-white/10': status === 'ok',
    'bg-blue-500/10': status === 'fetching',
    'bg-red-500/10': status === 'failed_sigcheck',
    'bg-red-800/10': status === 'failed_fetch',
  }}
>
  <div class="top">
    <small class="opacity-50">{canary.signer}'s canary for</small>
    <h2 class="canary-name text-lg">{canary.name}</h2>
    <p class="opacity-80 text-white font-normal mt-1">
      {#if status === 'ok'}
        {canary.description}
      {:else if status === 'fetching'}
        Fetching Canary...
      {:else if status === 'failed_sigcheck'}
        Failed Signature Check!<br />
        Either the upstream key changed, or the canary is fucked!
      {:else if status === 'failed_fetch'}
        Failed to fetch canary!
      {/if}
    </p>
  </div>
  <div class="bottom">
    <div class="mt-2">
      <span class="opacity-70">Get Canary:</span>
      {#if canary.upstream}
        <a
          class="opacity-90 hover:underline text-blue-400 hover:text-blue-300"
          href={canary.upstream}
        >
          Upstream
        </a>
      {/if}
      {#if status !== 'failed_sigcheck' && status !== 'failed_fetch'}
        <a
          class="opacity-90 hover:underline text-blue-400 hover:text-blue-300"
          href={url?.signed ?? canary.url}
        >
          Signed
        </a>
      {:else}
        <a
          class="opacity-90 hover:underline text-red-400 hover:text-red-300"
          href={url?.signed ?? canary.url}
        >
          Signed, {status === 'failed_sigcheck'
            ? 'bad signature'
            : 'unreachable'}
        </a>
      {/if}
      {#if url}
        <a
          class="opacity-90 hover:underline text-blue-400 hover:text-blue-300"
          href={url.stripped}
        >
          Stripped
        </a>
      {:else}
        <span class="opacity-70 text-blue-400 grayscale cursor-not-allowed">
          Stripped
        </span>
      {/if}
    </div>
  </div>
</div>