Change the structure

This commit is contained in:
2025-11-23 21:33:09 +03:00
Unverified
parent 0f4256edad
commit 7d254b5658
36 changed files with 1261 additions and 184 deletions
+37 -33
View File
@@ -1,39 +1,43 @@
import { API_BASE_URL } from "@/core/config";
import { getAuthHeaders } from "./account";
import { getAuthHeaders } from "./user/auth";
/**
* Gets the URL for a normal (unencrypted) file
*/
export function getNormalFileUrl(filename: string): string {
return `${API_BASE_URL}/uploads/files/normal/${filename}`;
}
export const normal = {
/**
* Gets the URL for a normal (unencrypted) file
*/
url(filename: string): string {
return `${API_BASE_URL}/uploads/files/normal/${filename}`;
},
/**
* Gets the URL for an encrypted file
*/
export function getEncryptedFileUrl(filename: string): string {
return `${API_BASE_URL}/uploads/files/encrypted/${filename}`;
}
/**
* Fetches a normal file (unencrypted)
*/
async fetch(filename: string, token: string): Promise<Blob> {
const res = await fetch(this.url(filename), {
headers: getAuthHeaders(token, false)
});
if (!res.ok) throw new Error("Failed to fetch file");
return await res.blob();
}
};
/**
* Fetches a normal file (unencrypted)
*/
export async function fetchNormalFile(filename: string, token: string): Promise<Blob> {
const res = await fetch(getNormalFileUrl(filename), {
headers: getAuthHeaders(token, false)
});
if (!res.ok) throw new Error("Failed to fetch file");
return await res.blob();
}
export const encrypted = {
/**
* Gets the URL for an encrypted file
*/
url(filename: string): string {
return `${API_BASE_URL}/uploads/files/encrypted/${filename}`;
},
/**
* Fetches an encrypted file
*/
export async function fetchEncryptedFile(filename: string, token: string): Promise<Blob> {
const res = await fetch(getEncryptedFileUrl(filename), {
headers: getAuthHeaders(token, false)
});
if (!res.ok) throw new Error("Failed to fetch encrypted file");
return await res.blob();
}
/**
* Fetches an encrypted file
*/
async fetch(filename: string, token: string): Promise<Blob> {
const res = await fetch(this.url(filename), {
headers: getAuthHeaders(token, false)
});
if (!res.ok) throw new Error("Failed to fetch encrypted file");
return await res.blob();
}
};