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.
This commit is contained in:
1 parent
7e7a1d2bb6
commit
3b82719d56
38 files changed
+1307
-106
No files matched your search
@@ -418,6 +418,7 @@ button {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
flex: none;
|
||||
overflow: hidden;
|
||||
border-radius: var(--r-avatar);
|
||||
border: 1px solid color-mix(in srgb, var(--member, var(--muted)) 28%, transparent);
|
||||
background: color-mix(in srgb, var(--member, var(--muted)) 14%, var(--surface));
|
||||
@@ -439,6 +440,19 @@ button {
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.avatar-xl {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
font-size: var(--fs-section);
|
||||
}
|
||||
|
||||
.avatar-img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.avatar-offline {
|
||||
opacity: 0.45;
|
||||
}
|
||||
@@ -651,6 +665,23 @@ button {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sidebar-account-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-2);
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.sidebar-account-link:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sidebar-account-link:hover .sidebar-account-name {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.sidebar-account-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
@@ -800,6 +831,21 @@ button {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.msg-human {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--sp-3);
|
||||
}
|
||||
|
||||
.msg-human > .avatar {
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.msg-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.msg-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
@@ -1443,6 +1489,41 @@ button {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--sp-5);
|
||||
padding: var(--sp-5);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-card);
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.profile-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-1);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
font-size: var(--fs-section);
|
||||
font-weight: 600;
|
||||
line-height: var(--lh-heading);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.profile-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--sp-2);
|
||||
margin-top: var(--sp-3);
|
||||
}
|
||||
|
||||
.file-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.settings-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { initials } from '~/utils/format'
|
||||
import { memberColorVar } from '~/utils/member'
|
||||
|
||||
@@ -7,15 +7,25 @@ const props = withDefaults(
|
||||
defineProps<{
|
||||
name: string
|
||||
color?: string | null
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
size?: 'sm' | 'md' | 'lg' | 'xl'
|
||||
src?: string | null
|
||||
offline?: boolean
|
||||
}>(),
|
||||
{ color: null, size: 'md', offline: false },
|
||||
{ color: null, size: 'md', src: null, offline: false },
|
||||
)
|
||||
|
||||
const failed = ref(false)
|
||||
watch(
|
||||
() => props.src,
|
||||
() => {
|
||||
failed.value = false
|
||||
},
|
||||
)
|
||||
|
||||
const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
||||
const className = computed(() => ({
|
||||
'avatar-lg': props.size === 'lg',
|
||||
'avatar-xl': props.size === 'xl',
|
||||
'avatar-sm': props.size === 'sm',
|
||||
'avatar-offline': props.offline,
|
||||
}))
|
||||
@@ -23,6 +33,7 @@ const className = computed(() => ({
|
||||
|
||||
<template>
|
||||
<span class="avatar" :class="className" :style="style" :title="name" role="img" :aria-label="name">
|
||||
{{ initials(name) }}
|
||||
<img v-if="src && !failed" class="avatar-img" :src="src" alt="" @error="failed = true">
|
||||
<template v-else>{{ initials(name) }}</template>
|
||||
</span>
|
||||
</template>
|
||||
@@ -4,7 +4,7 @@ import type { Message } from '~/types'
|
||||
import { fullTime, relativeTime } from '~/utils/format'
|
||||
import { memberColorVar } from '~/utils/member'
|
||||
|
||||
const props = defineProps<{ message: Message; color?: string | null }>()
|
||||
const props = defineProps<{ message: Message; color?: string | null; avatar?: string | null }>()
|
||||
|
||||
const segments = computed(() => {
|
||||
const parts = props.message.text.split(/(@rhema\b)/gi)
|
||||
@@ -34,16 +34,19 @@ const style = computed(() => ({ '--member': memberColorVar(props.color) }))
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="msg">
|
||||
<div class="msg-head">
|
||||
<span class="msg-author member-name" :style="style">{{ message.author_name }}</span>
|
||||
<span class="msg-time" :title="fullTime(message.created_at)">{{ relativeTime(message.created_at) }}</span>
|
||||
</div>
|
||||
<div class="msg-text">
|
||||
<template v-for="(segment, index) in segments" :key="index">
|
||||
<span v-if="segment.mention" class="mention">{{ segment.text }}</span>
|
||||
<template v-else>{{ segment.text }}</template>
|
||||
</template>
|
||||
<div v-else class="msg msg-human">
|
||||
<AppAvatar :name="message.author_name" :color="color" :src="avatar" size="sm" />
|
||||
<div class="msg-body">
|
||||
<div class="msg-head">
|
||||
<span class="msg-author member-name" :style="style">{{ message.author_name }}</span>
|
||||
<span class="msg-time" :title="fullTime(message.created_at)">{{ relativeTime(message.created_at) }}</span>
|
||||
</div>
|
||||
<div class="msg-text">
|
||||
<template v-for="(segment, index) in segments" :key="index">
|
||||
<span v-if="segment.mention" class="mention">{{ segment.text }}</span>
|
||||
<template v-else>{{ segment.text }}</template>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -96,7 +96,12 @@ function toggleFullscreen() {
|
||||
<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}`" />
|
||||
<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.
|
||||
|
||||
@@ -14,6 +14,11 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{ invite: []; togglePane: []; settings: [] }>()
|
||||
|
||||
const online = computed(() => new Set(props.onlineIds))
|
||||
|
||||
function avatarUrl(member: Member): string | null {
|
||||
if (!member.avatar_updated_at) return null
|
||||
return `/api/avatars/${member.account_id}?v=${member.avatar_updated_at}`
|
||||
}
|
||||
const visible = computed(() => props.members.slice(0, 5))
|
||||
const extra = computed(() => props.members.slice(5))
|
||||
const extraTitle = computed(() => extra.value.map((member) => member.display_name).join(', '))
|
||||
@@ -32,6 +37,7 @@ const extraTitle = computed(() => extra.value.map((member) => member.display_nam
|
||||
:key="member.id"
|
||||
:name="member.display_name"
|
||||
:color="member.color"
|
||||
:src="avatarUrl(member)"
|
||||
:offline="!online.has(member.id)"
|
||||
size="sm"
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,7 @@ interface RequestOptions {
|
||||
method?: ApiMethod
|
||||
body?: unknown
|
||||
query?: Record<string, string | number | boolean | undefined>
|
||||
contentType?: string
|
||||
}
|
||||
|
||||
const PUBLIC_PREFIXES = ['/setup', '/login', '/register', '/join']
|
||||
@@ -22,6 +23,7 @@ export function useApi() {
|
||||
async function request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
||||
const method = options.method ?? 'GET'
|
||||
const headers: Record<string, string> = { Accept: 'application/json' }
|
||||
if (options.contentType) headers['Content-Type'] = options.contentType
|
||||
if (method !== 'GET' && csrf.value) headers['X-CSRF-Token'] = csrf.value
|
||||
try {
|
||||
return await $fetch<T>(path, {
|
||||
@@ -45,6 +47,12 @@ export function useApi() {
|
||||
return {
|
||||
get: <T>(path: string, query?: RequestOptions['query']) => request<T>(path, { query }),
|
||||
post: <T>(path: string, body?: unknown) => request<T>(path, { method: 'POST', body }),
|
||||
upload: <T>(path: string, body: Blob) =>
|
||||
request<T>(path, {
|
||||
method: 'POST',
|
||||
body,
|
||||
contentType: body.type || 'application/octet-stream',
|
||||
}),
|
||||
patch: <T>(path: string, body?: unknown) => request<T>(path, { method: 'PATCH', body }),
|
||||
del: <T>(path: string) => request<T>(path, { method: 'DELETE' }),
|
||||
ApiRequestError,
|
||||
|
||||
@@ -47,6 +47,10 @@ export function useSession() {
|
||||
return inflight
|
||||
}
|
||||
|
||||
function setUser(next: User | null) {
|
||||
state.value = { ...state.value, user: next }
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
try {
|
||||
await api.post('/logout')
|
||||
@@ -61,6 +65,7 @@ export function useSession() {
|
||||
session: state,
|
||||
user: computed(() => state.value.user),
|
||||
load,
|
||||
setUser,
|
||||
signOut,
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, watch } from 'vue'
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import { LogOut, Plus, Settings } from 'lucide-vue-next'
|
||||
|
||||
const { user, signOut, session } = useSession()
|
||||
|
||||
const avatarSrc = computed(() => {
|
||||
if (!user.value?.avatar_updated_at) return null
|
||||
return `/api/avatars/${user.value.id}?v=${user.value.avatar_updated_at}`
|
||||
})
|
||||
const {
|
||||
rooms: roomList,
|
||||
loading: roomsLoading,
|
||||
@@ -70,8 +75,16 @@ async function onSignOut() {
|
||||
<span>Settings</span>
|
||||
</NuxtLink>
|
||||
<div class="sidebar-account">
|
||||
<AppAvatar v-if="user" :name="user.display_name" color="var(--member-1)" size="sm" />
|
||||
<span class="sidebar-account-name" :title="user?.handle">{{ user?.display_name }}</span>
|
||||
<NuxtLink to="/profile" class="sidebar-account-link" title="Open profile">
|
||||
<AppAvatar
|
||||
v-if="user"
|
||||
:name="user.display_name"
|
||||
color="var(--member-1)"
|
||||
:src="avatarSrc"
|
||||
size="sm"
|
||||
/>
|
||||
<span class="sidebar-account-name" :title="user?.handle">{{ user?.display_name }}</span>
|
||||
</NuxtLink>
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { Camera, Trash2 } from 'lucide-vue-next'
|
||||
import type { User } from '~/types'
|
||||
import { apiErrorMessage } from '~/utils/errors'
|
||||
|
||||
useHead({ title: 'Profile · Rhema Together' })
|
||||
|
||||
const api = useApi()
|
||||
const { user, setUser, load } = useSession()
|
||||
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const notice = ref('')
|
||||
|
||||
const avatarSrc = computed(() => {
|
||||
if (!user.value?.avatar_updated_at) return null
|
||||
return `/api/avatars/${user.value.id}?v=${user.value.avatar_updated_at}`
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
if (!user.value) await load(true)
|
||||
})
|
||||
|
||||
function pickFile() {
|
||||
fileInput.value?.click()
|
||||
}
|
||||
|
||||
async function onFile(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
input.value = ''
|
||||
if (!file || busy.value) return
|
||||
if (!['image/png', 'image/jpeg', 'image/gif', 'image/webp'].includes(file.type)) {
|
||||
error.value = 'Choose a PNG, JPEG, GIF, or WebP image.'
|
||||
return
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
error.value = 'The picture must be 2 MB or smaller.'
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
try {
|
||||
const updated = await api.upload<User>('/profile/avatar', file)
|
||||
setUser(updated)
|
||||
notice.value = 'Picture updated.'
|
||||
} catch (err) {
|
||||
error.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removePicture() {
|
||||
if (busy.value || !avatarSrc.value) return
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
try {
|
||||
const updated = await api.del<User>('/profile/avatar')
|
||||
setUser(updated)
|
||||
notice.value = 'Picture removed.'
|
||||
} catch (err) {
|
||||
error.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page-head">
|
||||
<h1 class="page-title">Profile</h1>
|
||||
</div>
|
||||
|
||||
<section class="section">
|
||||
<div v-if="user" class="profile-card">
|
||||
<AppAvatar
|
||||
:name="user.display_name"
|
||||
color="var(--member-1)"
|
||||
:src="avatarSrc"
|
||||
size="xl"
|
||||
/>
|
||||
<div class="profile-body">
|
||||
<div class="profile-name">{{ user.display_name }}</div>
|
||||
<div class="meta">@{{ user.handle }}</div>
|
||||
|
||||
<div class="profile-actions">
|
||||
<button type="button" class="btn btn-primary btn-sm" :disabled="busy" @click="pickFile">
|
||||
<Camera :size="14" aria-hidden="true" />
|
||||
{{ busy ? 'Uploading' : 'Change picture' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="avatarSrc"
|
||||
type="button"
|
||||
class="btn btn-sm btn-quiet"
|
||||
:disabled="busy"
|
||||
@click="removePicture"
|
||||
>
|
||||
<Trash2 :size="14" aria-hidden="true" />
|
||||
Remove picture
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p class="hint">PNG, JPEG, GIF or WebP, up to 2 MB. The picture is shown cropped to a square.</p>
|
||||
<p v-if="error" class="form-error" role="alert">{{ error }}</p>
|
||||
<p v-if="notice" class="meta" role="status">{{ notice }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="meta">Loading profile.</p>
|
||||
|
||||
<input
|
||||
ref="fileInput"
|
||||
class="file-input"
|
||||
type="file"
|
||||
accept="image/png,image/jpeg,image/gif,image/webp"
|
||||
@change="onFile"
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -3,6 +3,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import type {
|
||||
DeltaData,
|
||||
Envelope,
|
||||
Member,
|
||||
Message,
|
||||
MessagePage,
|
||||
NoticeData,
|
||||
@@ -87,7 +88,7 @@ const isOwner = computed(
|
||||
)
|
||||
|
||||
const memberById = computed(() => {
|
||||
const map = new Map<string, { color: string }>()
|
||||
const map = new Map<string, Member>()
|
||||
for (const member of detail.value?.members ?? []) map.set(member.id, member)
|
||||
return map
|
||||
})
|
||||
@@ -450,6 +451,13 @@ function colorFor(message: Message): string | null {
|
||||
return memberById.value.get(message.author_id)?.color ?? null
|
||||
}
|
||||
|
||||
function avatarFor(message: Message): string | null {
|
||||
if (!message.author_id) return null
|
||||
const member = memberById.value.get(message.author_id)
|
||||
if (!member?.avatar_updated_at) return null
|
||||
return `/api/avatars/${member.account_id}?v=${member.avatar_updated_at}`
|
||||
}
|
||||
|
||||
function isNearBottom(element: HTMLElement) {
|
||||
return element.scrollHeight - element.scrollTop - element.clientHeight < 80
|
||||
}
|
||||
@@ -651,6 +659,7 @@ onBeforeUnmount(() => {
|
||||
v-if="entry.kind === 'message'"
|
||||
:message="entry.message"
|
||||
:color="colorFor(entry.message)"
|
||||
:avatar="avatarFor(entry.message)"
|
||||
/>
|
||||
<p
|
||||
v-else-if="entry.kind === 'notice'"
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface User {
|
||||
handle: string
|
||||
display_name: string
|
||||
kind: string
|
||||
avatar_updated_at: number | null
|
||||
}
|
||||
|
||||
export interface BootstrapResponse {
|
||||
@@ -66,6 +67,7 @@ export interface Member {
|
||||
display_name: string
|
||||
role: string
|
||||
color: string
|
||||
avatar_updated_at: number | null
|
||||
online: boolean
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user