feat: Initial commit with full deployment architecture and scripts
This commit is contained in:
commit
abb3efe114
96 files changed
+16789
No files matched your search
@@ -0,0 +1,64 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { watch, onMounted } from 'vue';
|
||||
|
||||
const { locale } = useI18n();
|
||||
|
||||
const getAuthHeaders = () => {
|
||||
const stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) return {};
|
||||
const user = JSON.parse(stored) as { id?: number; username: string; role: string };
|
||||
const headers: Record<string, string> = {
|
||||
'X-Username': user.username,
|
||||
'X-Role': user.role,
|
||||
};
|
||||
if (user.id) {
|
||||
headers['X-User-Id'] = String(user.id);
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
|
||||
const updateLanguagePreference = async (lang: string) => {
|
||||
const headers = getAuthHeaders();
|
||||
if (Object.keys(headers).length === 0) return; // Not logged in
|
||||
|
||||
try {
|
||||
await fetch('/api/user/profile', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...headers },
|
||||
body: JSON.stringify({ language: lang })
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to update language preference', e);
|
||||
}
|
||||
};
|
||||
|
||||
watch(locale, (newLang) => {
|
||||
updateLanguagePreference(newLang as string);
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const headers = getAuthHeaders();
|
||||
if (Object.keys(headers).length > 0) {
|
||||
try {
|
||||
// Try to fetch profile to get language, or rely on WorkspaceView to load it?
|
||||
// Since WorkspaceView loads user home which includes language now, we might want to sync from there?
|
||||
// Or just fetch home here quickly.
|
||||
const res = await fetch('/api/user/home', { headers });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.user && data.user.language) {
|
||||
locale.value = data.user.language;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to sync language', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
Reference in new issue
Block a user