fixed and improved profile pictures

This commit is contained in:
2026-01-13 17:32:39 +01:00
parent 68116e7353
commit 9e6f8630fa
17 changed files with 222 additions and 144 deletions

View File

@@ -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<string, string>([
['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 {

View File

@@ -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'