Lint and format with Biome, and retire used share codes
Biome formats and lints the TypeScript, the Vue templates and the CSS: pnpm lint checks, pnpm format fixes. It keeps the existing style, single quotes and 120 columns, and leaves the vendored logo alone. Besides its recommended rules it looks for promises nobody awaits. Rules that only flagged deliberate code are off: non-null assertions that state what the code guarantees, CSS order where no two rules set the same property, and fieldset for role="group". The one-time formatting pass mostly splits long chains. Promises that are deliberately not awaited are marked with void, none of them can reject today. Buttons say type="button", the any for peer messages and the checkbox switch keep their reasons in ignore comments. The sender's code also counts as no longer valid once a transfer started: that closes the trackers, so another receiver would wait for nothing, yet the card still offered the code with Copy. The tracker transfer tests check it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2167b528b2
commit
b6b6e7c29b
9 files changed
+371
-122
No files matched your search
+57
-25
@@ -2,17 +2,17 @@
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
import {
|
||||
answerOffer,
|
||||
type Check,
|
||||
settings as coreSettings,
|
||||
createOffer,
|
||||
DEFAULT_STUN_SERVERS,
|
||||
DEFAULT_TRACKERS,
|
||||
receiveViaTracker,
|
||||
sendViaTracker,
|
||||
settings as coreSettings,
|
||||
TRACKER_WAIT,
|
||||
type Check,
|
||||
type Events,
|
||||
type Incoming,
|
||||
type ReceiveEvents,
|
||||
receiveViaTracker,
|
||||
sendViaTracker,
|
||||
TRACKER_WAIT,
|
||||
} from './core';
|
||||
|
||||
const SETTINGS_KEY = 'hellcon:settings';
|
||||
@@ -61,7 +61,12 @@ const isTracker = (url: string) =>
|
||||
// A textarea with one URL per line for the list at settings[key], invalid lines are listed and skipped.
|
||||
function serverList(key: 'stunServers' | 'trackers', valid: (url: string) => boolean) {
|
||||
const text = ref(settings[key].join('\n'));
|
||||
const lines = computed(() => text.value.split('\n').map((line) => line.trim()).filter(Boolean));
|
||||
const lines = computed(() =>
|
||||
text.value
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
const invalid = computed(() => lines.value.filter((line) => !valid(line)));
|
||||
// Immediate, a saved list may hold lines this browser rejects.
|
||||
watch(lines, (lines) => (settings[key] = lines.filter(valid)), { immediate: true });
|
||||
@@ -236,8 +241,9 @@ async function onShare() {
|
||||
sendTimer = window.setTimeout(() => (sendExpired.value = true), TRACKER_WAIT);
|
||||
}
|
||||
|
||||
// Also once the share failed, every error on the tracker ends it.
|
||||
const codeGone = computed(() => sendExpired.value || !!error.value);
|
||||
// Also once the transfer started, which closes the trackers, and once the share failed: every error on
|
||||
// the tracker ends it.
|
||||
const codeGone = computed(() => sendExpired.value || !!sent.value || !!error.value);
|
||||
|
||||
function onReceive() {
|
||||
const signal = begin('receive');
|
||||
@@ -250,6 +256,7 @@ function onReceive() {
|
||||
<img src="/HellNet_alt.png" alt="" width="40" height="40" />
|
||||
<h1>HellCon</h1>
|
||||
<label>
|
||||
<!-- biome-ignore lint/a11y/useAriaPropsForRole: a checkbox reports its own state, aria-checked on it is not allowed -->
|
||||
<input id="stun" v-model="settings.stun" type="checkbox" role="switch" />
|
||||
Use STUN
|
||||
</label>
|
||||
@@ -258,8 +265,8 @@ function onReceive() {
|
||||
<main>
|
||||
<aside v-if="check" role="alert">
|
||||
<p>
|
||||
Security check: the other side must show the same two codes, swapped. Both sides confirm, nothing is
|
||||
transferred before.
|
||||
Security check: the other side must show the same two codes, swapped. Both sides confirm, nothing is transferred
|
||||
before.
|
||||
</p>
|
||||
<dl>
|
||||
<dt>You</dt>
|
||||
@@ -268,8 +275,8 @@ function onReceive() {
|
||||
<dd><output id="check-remote">{{ check.remote }}</output></dd>
|
||||
</dl>
|
||||
<div v-if="!confirmed">
|
||||
<button id="confirm" @click="onConfirm">Codes match</button>
|
||||
<button id="reject" @click="check.reject()">Codes don't match</button>
|
||||
<button id="confirm" type="button" @click="onConfirm">Codes match</button>
|
||||
<button id="reject" type="button" @click="check.reject()">Codes don't match</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -296,13 +303,15 @@ function onReceive() {
|
||||
|
||||
<section>
|
||||
<h3>Tracker</h3>
|
||||
<button id="share" :disabled="!file || !settings.trackers.length" @click="onShare">Share via tracker</button>
|
||||
<button id="share" type="button" :disabled="!file || !settings.trackers.length" @click="onShare">
|
||||
Share via tracker
|
||||
</button>
|
||||
<template v-if="sendCode">
|
||||
<label v-if="codeGone" for="send-code">Code, no longer valid:</label>
|
||||
<label v-else for="send-code">Code, give this to the receiver, valid until {{ sendUntil }}:</label>
|
||||
<div role="group">
|
||||
<output id="send-code" :data-expired="codeGone || undefined">{{ sendCode }}</output>
|
||||
<button id="copy-send-code" data-copy :disabled="codeGone" @click="onCopy(sendCode)">
|
||||
<button id="copy-send-code" type="button" data-copy :disabled="codeGone" @click="onCopy(sendCode)">
|
||||
{{ copied === sendCode ? 'Copied' : 'Copy' }}
|
||||
</button>
|
||||
</div>
|
||||
@@ -312,14 +321,18 @@ function onReceive() {
|
||||
<details id="send-manual">
|
||||
<summary>Manual</summary>
|
||||
<section>
|
||||
<button id="create-offer" :disabled="!file" @click="onCreateOffer">Create offer</button>
|
||||
<button id="create-offer" type="button" :disabled="!file" @click="onCreateOffer">Create offer</button>
|
||||
<template v-if="offer">
|
||||
<label for="offer">Offer, send this to the receiver:</label>
|
||||
<textarea id="offer" readonly :value="offer"></textarea>
|
||||
<button id="copy-offer" data-copy @click="onCopy(offer)">{{ copied === offer ? 'Copied' : 'Copy' }}</button>
|
||||
<button id="copy-offer" type="button" data-copy @click="onCopy(offer)">
|
||||
{{ copied === offer ? 'Copied' : 'Copy' }}
|
||||
</button>
|
||||
<label for="answer-input">Answer from the receiver:</label>
|
||||
<textarea id="answer-input" v-model="answerInput"></textarea>
|
||||
<button id="accept-answer" :disabled="!answerInput.trim()" @click="onAcceptAnswer">Connect</button>
|
||||
<button id="accept-answer" type="button" :disabled="!answerInput.trim()" @click="onAcceptAnswer">
|
||||
Connect
|
||||
</button>
|
||||
</template>
|
||||
</section>
|
||||
</details>
|
||||
@@ -331,7 +344,7 @@ function onReceive() {
|
||||
<template v-if="incoming">
|
||||
<strong>{{ incoming.name }}</strong>
|
||||
{{ formatSize(incoming.size) }}
|
||||
<button v-if="!received" id="download" @click="incoming.download()">Download</button>
|
||||
<button v-if="!received" id="download" type="button" @click="incoming.download()">Download</button>
|
||||
</template>
|
||||
<template v-else>The sender's file shows up here after the security check</template>
|
||||
</div>
|
||||
@@ -353,7 +366,14 @@ function onReceive() {
|
||||
autocorrect="off"
|
||||
spellcheck="false"
|
||||
/>
|
||||
<button id="receive" :disabled="!settings.trackers.length || !receiveCode.trim()" @click="onReceive">Receive</button>
|
||||
<button
|
||||
id="receive"
|
||||
type="button"
|
||||
:disabled="!settings.trackers.length || !receiveCode.trim()"
|
||||
@click="onReceive"
|
||||
>
|
||||
Receive
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -362,11 +382,15 @@ function onReceive() {
|
||||
<section>
|
||||
<label for="offer-input">Offer from the sender:</label>
|
||||
<textarea id="offer-input" v-model="offerInput"></textarea>
|
||||
<button id="create-answer" :disabled="!offerInput.trim()" @click="onCreateAnswer">Create answer</button>
|
||||
<button id="create-answer" type="button" :disabled="!offerInput.trim()" @click="onCreateAnswer">
|
||||
Create answer
|
||||
</button>
|
||||
<template v-if="answer">
|
||||
<label for="answer">Answer, send this back to the sender:</label>
|
||||
<textarea id="answer" readonly :value="answer"></textarea>
|
||||
<button id="copy-answer" data-copy @click="onCopy(answer)">{{ copied === answer ? 'Copied' : 'Copy' }}</button>
|
||||
<button id="copy-answer" type="button" data-copy @click="onCopy(answer)">
|
||||
{{ copied === answer ? 'Copied' : 'Copy' }}
|
||||
</button>
|
||||
</template>
|
||||
</section>
|
||||
</details>
|
||||
@@ -378,16 +402,24 @@ function onReceive() {
|
||||
<section>
|
||||
<h3>STUN</h3>
|
||||
<label for="stun-servers">Tell each side its public address, one URL per line:</label>
|
||||
<textarea id="stun-servers" v-model="stunServers.text" :aria-invalid="!!stunServers.invalid.length"></textarea>
|
||||
<p v-if="stunServers.invalid.length">Skipped, not a STUN URL this browser accepts: {{ stunServers.invalid.join(', ') }}</p>
|
||||
<textarea
|
||||
id="stun-servers"
|
||||
v-model="stunServers.text"
|
||||
:aria-invalid="!!stunServers.invalid.length"
|
||||
></textarea>
|
||||
<p v-if="stunServers.invalid.length">
|
||||
Skipped, not a STUN URL this browser accepts: {{ stunServers.invalid.join(', ') }}
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Trackers</h3>
|
||||
<label for="trackers">WebTorrent trackers for the code exchange, one URL per line:</label>
|
||||
<textarea id="trackers" v-model="trackers.text" :aria-invalid="!!trackers.invalid.length"></textarea>
|
||||
<p v-if="trackers.invalid.length">Skipped, not a ws: or wss: URL without #: {{ trackers.invalid.join(', ') }}</p>
|
||||
<p v-if="trackers.invalid.length">
|
||||
Skipped, not a ws: or wss: URL without #: {{ trackers.invalid.join(', ') }}
|
||||
</p>
|
||||
</section>
|
||||
<button id="reset-servers" @click="onResetServers">Reset to defaults</button>
|
||||
<button id="reset-servers" type="button" @click="onResetServers">Reset to defaults</button>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
|
||||
Reference in new issue
Block a user