show image preview + single file downloads

This commit is contained in:
2025-08-10 23:16:18 +02:00
parent bfe73eefb9
commit c8b52a5b3b
13 changed files with 174 additions and 26 deletions

View File

@@ -32,12 +32,12 @@ export async function loginUser(
const token = data.value.data.token;
const { user, expiresAt } = data.value.data;
useAuthSession().value = {
setAuthSession({
type: 'WarrenAuth',
id: token,
user,
expiresAt,
};
});
toast.success('Login', {
description: `Successfully logged in`,

View File

@@ -1,5 +1,5 @@
export async function logout() {
useAuthSession().value = null;
clearAuthSession();
useAdminStore().$reset();
useWarrenStore().$reset();
await navigateTo({

View File

@@ -57,12 +57,12 @@ export async function oidcLoginUser(
const token = data.value.data.token;
const { user, expiresAt } = data.value.data;
useAuthSession().value = {
setAuthSession({
type: 'WarrenAuth',
id: token,
user,
expiresAt,
};
});
toast.success('OpenID Connect', {
description: `Successfully logged in`,

View File

@@ -9,7 +9,9 @@ export function getAuthHeader(): ['authorization', string] | null {
export function getApiHeaders(
includeAuth: boolean = true
): Record<string, string> {
const headers: Record<string, string> = {};
const headers: Record<string, string> = {
cookie: document.cookie,
};
if (includeAuth) {
const header = getAuthHeader();

View File

@@ -301,6 +301,40 @@ export async function fetchFile(
};
}
export async function fetchFileStream(
warrenId: string,
path: string,
fileName: string
): Promise<
{ success: true; stream: ReadableStream<Uint8Array> } | { success: false }
> {
if (!path.endsWith('/')) {
path += '/';
}
path += fileName;
const { data, error } = await useFetch<ReadableStream<Uint8Array>>(
getApiUrl(`warrens/files/cat?warrenId=${warrenId}&path=${path}`),
{
method: 'GET',
headers: getApiHeaders(),
responseType: 'stream',
cache: 'default',
}
);
if (data.value == null || error.value != null) {
return {
success: false,
};
}
return {
success: true,
stream: data.value,
};
}
export async function moveFile(
warrenId: string,
currentPath: string,