From 9e6f8630fa241da9d4d017e5253bced8cc320900 Mon Sep 17 00:00:00 2001 From: eiiko6 Date: Tue, 13 Jan 2026 17:32:39 +0100 Subject: [PATCH] fixed and improved profile pictures --- package.json | 1 + src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 15 ++- .../android/app/src/main/AndroidManifest.xml | 1 + src-tauri/src/lib.rs | 1 + src/api/account.ts | 47 +++++--- src/api/client.ts | 2 +- src/authStore.ts | 78 ------------ src/components/ChatWindow.vue | 2 +- src/components/MessageList.vue | 9 +- src/components/UpdateAccountModal.vue | 2 +- src/components/UploadAvatarModal.vue | 66 +++++++---- src/main.ts | 8 +- src/pages/SettingsPage.vue | 14 ++- src/store.ts | 111 ++++++++++++++++-- yarn.lock | 7 ++ 17 files changed, 222 insertions(+), 144 deletions(-) delete mode 100644 src/authStore.ts diff --git a/package.json b/package.json index 6327d70..593871b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@fluent/bundle": "^0.19.1", "@tauri-apps/api": "^2", "@tauri-apps/plugin-dialog": "~2", + "@tauri-apps/plugin-fs": "~2", "@tauri-apps/plugin-http": "~2", "@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-store": "~2", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index fadca11..20aad69 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -444,6 +444,7 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-dialog", + "tauri-plugin-fs", "tauri-plugin-http", "tauri-plugin-opener", "tauri-plugin-store", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8c68dee..a74432d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,4 +27,5 @@ tauri-plugin-http = "2" tauri-plugin-websocket = "2" tauri-plugin-upload = "2" tauri-plugin-dialog = "2" +tauri-plugin-fs = "2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index b71eae2..e0ab2e4 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -15,6 +15,9 @@ { "url": "http://127.0.0.1:*" }, + { + "url": "http://192.168.1.183:*" + }, { "url": "https://alatreon.org/chatapp/*" } @@ -27,6 +30,9 @@ { "url": "ws://127.0.0.1:*" }, + { + "url": "http://192.168.1.183:*" + }, { "url": "wss://alatreon.org/chatapp/*" } @@ -34,7 +40,14 @@ }, "websocket:default", "upload:default", - "dialog:default" + "dialog:default", + "fs:default", + { + "identifier": "fs:scope", + "allow": [ + "*" + ] + } ] } diff --git a/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/src-tauri/gen/android/app/src/main/AndroidManifest.xml index 4f08bc3..afb38fa 100644 --- a/src-tauri/gen/android/app/src/main/AndroidManifest.xml +++ b/src-tauri/gen/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2ce3288..5a3f2b6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -7,6 +7,7 @@ fn greet(name: &str) -> String { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_upload::init()) .plugin(tauri_plugin_websocket::init()) diff --git a/src/api/account.ts b/src/api/account.ts index ff78153..e5e4ec6 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -1,7 +1,7 @@ import { UpdateUserResponse } from '../types'; import { apiFetch } from './client' -import { upload } from '@tauri-apps/plugin-upload'; -import { getAuthData } from '../authStore'; +// import { upload } from '@tauri-apps/plugin-upload'; +import { getAuthData } from '../store'; import { API } from '../main.ts'; export function updateSettings(username: string, email: string, password: string) { @@ -12,24 +12,41 @@ export function updateSettings(username: string, email: string, password: string } export async function uploadAvatar( - filePath: string, + fileData: Uint8Array, onProgress: (progress: number, total: number) => void ) { const auth = await getAuthData(); const url = `${API}/account/upload-avatar`; - const headers = new Map([ - ['Authorization', `Bearer ${auth.token}`], - ['Content-Type', 'application/octet-stream'] - ]); - return upload( - url, - filePath, - ({ progress, total }) => { - onProgress(progress, total); - }, - headers - ); + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open('POST', url); + + xhr.setRequestHeader('Authorization', `Bearer ${auth.token}`); + xhr.setRequestHeader('Content-Type', 'application/octet-stream'); + + // Handle Progress + if (xhr.upload && onProgress) { + xhr.upload.onprogress = (event) => { + if (event.lengthComputable) { + onProgress(event.loaded, event.total); + } + }; + } + + // Handle Response + xhr.onload = () => { + if (xhr.status >= 200 && xhr.status < 300) { + resolve(xhr.response); + } else { + reject(new Error(`Upload failed with status ${xhr.status}: ${xhr.responseText}`)); + } + }; + + xhr.onerror = () => reject(new Error('Network error during upload')); + + xhr.send(fileData); + }); } export function getAvatar(uuid: string): string { diff --git a/src/api/client.ts b/src/api/client.ts index 6c7c2a6..7585653 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -1,5 +1,5 @@ import { fetch } from '@tauri-apps/plugin-http'; -import { getAuthData, clearAuthData } from '../authStore' +import { getAuthData, clearAuthData } from '../store' import { API } from '../main.ts' import router from '../router' diff --git a/src/authStore.ts b/src/authStore.ts deleted file mode 100644 index 2084f77..0000000 --- a/src/authStore.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { load, Store } from '@tauri-apps/plugin-store' -import { UpdateUserResponse, User } from './types' -import { getAvatar } from './api/account' - -let store: Store | null = null - -async function getStore() { - if (!store) store = await load('store.json') - return store -} - -export async function getAuthData() { - const s = await getStore() - const token = await s.get('token') - const user = await s.get('user') - return { token: token || null, user: user || null, isAuthenticated: !!token } -} - -export async function saveAuthData(token: string, user: User) { - const s = await getStore() - await s.set('token', token) - await s.set('user', user) - await s.save() -} - -export async function clearAuthData() { - const s = await getStore() - s.clear() - await s.save() -} - -export async function updateLocalUser(newData: UpdateUserResponse, uuid?: string) { - const updatedUser = { - username: newData.username, - email: newData.email, - uuid, - avatar_url: `${getAvatar(uuid || '')}?t=${Date.now()}` - } - - const s = await getStore() - await s.set('user', updatedUser) - await s.save() -} - -export async function refreshLocalUser() { - const s = await getStore() - const user = await s.get('user') - - if (user) { - user.avatar_url = `${getAvatar(user.uuid)}?t=${Date.now()}` - - await s.set('user', user) - await s.save() - } -} - -export async function setLastRoom(uuid: string) { - if (!uuid || uuid === 'none') return - const s = await getStore() - await s.set('last_room_uuid', uuid) - await s.save() -} - -export async function getLastRoom(): Promise { - const s = await getStore() - return (await s.get('last_room_uuid')) ?? null -} - -export async function saveLocalePreference(locale: string) { - const s = await getStore() - await s.set('language', locale) - await s.save() -} - -export async function getLocalePreference(): Promise { - const s = await getStore() - return (await s.get('language')) ?? null -} diff --git a/src/components/ChatWindow.vue b/src/components/ChatWindow.vue index 889ceba..0c66008 100644 --- a/src/components/ChatWindow.vue +++ b/src/components/ChatWindow.vue @@ -35,7 +35,7 @@ import MessageList from "./MessageList.vue"; import MessageInput from "./MessageInput.vue"; import InvitePeopleModal from './InvitePeopleModal.vue'; import WebSocket from '@tauri-apps/plugin-websocket'; -import { getAuthData } from "../authStore.ts"; +import { getAuthData } from "../store.ts"; import { fetchRoomInfo } from "../api/rooms.ts"; const props = defineProps<{ uuid: string }>(); diff --git a/src/components/MessageList.vue b/src/components/MessageList.vue index 3b92cda..485ebb1 100644 --- a/src/components/MessageList.vue +++ b/src/components/MessageList.vue @@ -2,7 +2,7 @@
  • - +
    {{ m.sender }}
    {{ m.sent_at }}
    @@ -11,13 +11,12 @@
-