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
@@ -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>
|
||||
Reference in new issue
Block a user