Files
rhema-together/web/app/components/PreviewPane.vue
T
vhaudiquet 3b82719d56 feat: add account avatars and a deployable image
Accounts get a profile page with an uploaded picture, shown in the
sidebar, the room bar, and every human message. Pictures live in the
SQLite database and are served through an authenticated route.

Hardening from the security audit: preview hosts expire after 24 hours
and carry no-referrer; removing a member or archiving a room ends their
event feed, presence socket, and terminal within seconds; previews and
the terminal pin the SSH host key; invites are claimed atomically;
missing accounts spend the same argon2 time as wrong passwords;
registration is closed by default; WebSockets check the origin; and the
master key is created with mode 0600.

The Dockerfile builds one image with the static client and the server.
The Helm chart runs a single replica with a SQLite volume, a wildcard
preview ingress, and the proxy settings the event feed and uploads
need. It refuses more than one replica because state is in process.
2026-11-28 02:07:26 +01:00

111 lines
3.4 KiB
Vue

<script setup lang="ts">
import { ref } from 'vue'
import { Maximize2, Minimize2, X } from 'lucide-vue-next'
const props = defineProps<{ roomId: string }>()
const port = ref<number | string>(3000)
const url = ref('')
const loading = ref(false)
const error = ref('')
const fullscreen = ref(false)
async function load() {
const value = Number(port.value)
if (!Number.isInteger(value) || value < 1 || value > 65535) {
error.value = 'Enter a port between 1 and 65535.'
return
}
loading.value = true
error.value = ''
try {
const response = await fetch(`/api/rooms/${encodeURIComponent(props.roomId)}/preview?port=${value}`, {
credentials: 'include',
headers: { Accept: 'application/json' },
})
if (response.status === 401) {
await navigateTo('/login')
return
}
const type = response.headers.get('content-type') ?? ''
if (!type.includes('application/json')) {
throw new Error('The server did not return a preview address.')
}
const body: unknown = await response.json()
if (!response.ok) {
const message = body && typeof body === 'object' && 'error' in body
? String((body as { error: unknown }).error)
: 'The preview could not be opened.'
throw new Error(message)
}
if (!body || typeof body !== 'object' || typeof (body as { url?: unknown }).url !== 'string') {
throw new Error('The server returned no preview address.')
}
url.value = (body as { url: string }).url
} catch (err) {
url.value = ''
error.value = err instanceof Error ? err.message : 'The preview could not be opened.'
} finally {
loading.value = false
}
}
function toggleFullscreen() {
fullscreen.value = !fullscreen.value
}
</script>
<template>
<div class="preview-wrap" :class="{ 'preview-full': fullscreen }">
<div class="preview-bar">
<label class="sr-only" for="preview-port">Port</label>
<input
id="preview-port"
v-model.number="port"
class="input port-field"
type="number"
min="1"
max="65535"
aria-label="Preview port"
>
<button type="button" class="btn btn-sm" :disabled="loading" @click="load">
{{ loading ? 'Opening' : url ? 'Reload' : 'Go' }}
</button>
<div class="room-topbar-spacer" />
<button
type="button"
class="icon-btn"
:aria-label="fullscreen ? 'Exit full screen preview' : 'Full screen preview'"
:title="fullscreen ? 'Exit full screen' : 'Full screen'"
@click="toggleFullscreen"
>
<component :is="fullscreen ? Minimize2 : Maximize2" :size="16" aria-hidden="true" />
</button>
<button
v-if="fullscreen"
type="button"
class="icon-btn"
aria-label="Close full screen preview"
title="Close full screen preview"
@click="fullscreen = false"
>
<X :size="16" aria-hidden="true" />
</button>
</div>
<p v-if="error" class="preview-message form-error" role="alert">{{ error }}</p>
<div v-if="url" class="preview-frame-wrap">
<iframe
class="preview-frame"
:src="url"
:title="`Preview on port ${port}`"
sandbox="allow-scripts allow-same-origin allow-forms allow-popups"
/>
</div>
<p v-else-if="!error" class="preview-message">
Enter the port the room serves and choose Go.
</p>
</div>
</template>