remove useless styles, format with biomejs

This commit is contained in:
Stef-00012 2025-02-08 21:36:49 +01:00
parent 626f025e2c
commit 4ff541d05f
No known key found for this signature in database
GPG key ID: 28BE9A9E4EF0E6BF
89 changed files with 4810 additions and 5168 deletions

View file

@ -179,14 +179,14 @@ export function isLightColor(color: string, luminanceThreshold = 0.179) {
export function rgbaToHex(r: number, g: number, b: number, a = 1) {
r = Math.min(255, Math.max(0, r));
g = Math.min(255, Math.max(0, g));
b = Math.min(255, Math.max(0, b));
a = Math.min(1, Math.max(0, a));
const alpha = a << 24
const red = r << 16
const green = g << 8
const blue = b
g = Math.min(255, Math.max(0, g));
b = Math.min(255, Math.max(0, b));
a = Math.min(1, Math.max(0, a));
return `#${(alpha + red + green + blue).toString(16).slice(1).toUpperCase()}`;
}
const alpha = a << 24;
const red = r << 16;
const green = g << 8;
const blue = b;
return `#${(alpha + red + green + blue).toString(16).slice(1).toUpperCase()}`;
}

View file

@ -17,9 +17,9 @@ export function get(key: string): string | null {
export async function del(key: string): Promise<boolean> {
try {
await SecureStore.deleteItemAsync(key);
return true;
} catch(e) {
} catch (e) {
return false;
}
}

View file

@ -1,5 +1,9 @@
import * as db from "@/functions/database";
import type { APILoginResponse, APISelfUser, APITokenResponse } from "@/types/zipline";
import type {
APILoginResponse,
APISelfUser,
APITokenResponse,
} from "@/types/zipline";
import axios, { type AxiosError } from "axios";
export async function isAuthenticated(): Promise<APISelfUser["role"] | false> {
@ -13,7 +17,7 @@ export async function isAuthenticated(): Promise<APISelfUser["role"] | false> {
headers: {
Authorization: token,
},
timeout: 10000
timeout: 10000,
});
const data: APISelfUser = res.data.user;
@ -28,14 +32,21 @@ export async function isAuthenticated(): Promise<APISelfUser["role"] | false> {
}
}
type GetAuthCookieResponse = {
totp: boolean;
data?: undefined;
} | {
data: string;
totp?: undefined;
} | string
export async function getAuthCookie(username: string, password: string, totpCode?: string): Promise<GetAuthCookieResponse> {
type GetAuthCookieResponse =
| {
totp: boolean;
data?: undefined;
}
| {
data: string;
totp?: undefined;
}
| string;
export async function getAuthCookie(
username: string,
password: string,
totpCode?: string,
): Promise<GetAuthCookieResponse> {
const url = db.get("url");
if (!url) return "Missing URL";
@ -44,14 +55,15 @@ export async function getAuthCookie(username: string, password: string, totpCode
const res = await axios.post(`${url}/api/auth/login`, {
username,
password,
code: totpCode
code: totpCode,
});
const data = res.data as APILoginResponse
const data = res.data as APILoginResponse;
if (data.totp) return {
totp: true
}
if (data.totp)
return {
totp: true,
};
const setCookieHeader = res.headers["set-cookie"];
@ -62,19 +74,21 @@ export async function getAuthCookie(username: string, password: string, totpCode
if (!authCookie) return "Something went wrong...";
return {
data: authCookie
data: authCookie,
};
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -86,49 +100,56 @@ export async function getToken(getCookieResponse?: GetAuthCookieResponse) {
if (!getCookieResponse) return "Something went wrong...";
if (typeof getCookieResponse === "string") return getCookieResponse;
if (getCookieResponse.totp) return {
totp: true
};
const cookie = getCookieResponse.data
if (getCookieResponse.totp)
return {
totp: true,
};
const cookie = getCookieResponse.data;
if (!cookie) return "Something went wrong...";
try {
const res = await axios.get(`${url}/api/user/token`, {
headers: {
Cookie: cookie
}
})
Cookie: cookie,
},
});
const data = res.data as APITokenResponse
const data = res.data as APITokenResponse;
if (data.token) {
db.set("token", data.token);
return {
token: data.token
}
token: data.token,
};
}
return "Something went wrong..."
} catch(e) {
return "Something went wrong...";
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
export async function login(username: string, password: string, totpCode?: string) {
const cookieRes = await getAuthCookie(username, password, totpCode)
export async function login(
username: string,
password: string,
totpCode?: string,
) {
const cookieRes = await getAuthCookie(username, password, totpCode);
const token = await getToken(cookieRes)
const token = await getToken(cookieRes);
return token;
}
@ -149,14 +170,16 @@ export async function getTokenWithToken(): Promise<APITokenResponse | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
}

View file

@ -19,20 +19,24 @@ export async function getUserExports(): Promise<APIExports | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
// POST /api/user/export
export async function createUserExport(): Promise<{ running: boolean } | string> {
export async function createUserExport(): Promise<
{ running: boolean } | string
> {
const token = db.get("token");
const url = db.get("url");
@ -50,14 +54,16 @@ export async function createUserExport(): Promise<{ running: boolean } | string>
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
if (data) return data.error
if (data) return data.error;
return "Something went wrong..."
return "Something went wrong...";
}
}
@ -80,14 +86,16 @@ export async function deleteUserExport(
return res.data.user;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -14,7 +14,10 @@ export interface GetFilesOptions {
favorite?: boolean;
}
// GET /api/user/files
export async function getFiles(page: string, options: GetFilesOptions = {}): Promise<APIFiles | string> {
export async function getFiles(
page: string,
options: GetFilesOptions = {},
): Promise<APIFiles | string> {
const token = db.get("token");
const url = db.get("url");
@ -37,15 +40,17 @@ export async function getFiles(page: string, options: GetFilesOptions = {}): Pro
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -66,15 +71,17 @@ export async function getFile(id: string): Promise<APIFile | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -95,15 +102,17 @@ export async function deleteFile(id: string): Promise<APIFile | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -119,7 +128,7 @@ export async function updateFileTags(
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL"
if (!url || !token) return "Invalid token or URL";
try {
const file = await getFile(id);
@ -147,15 +156,17 @@ export async function updateFileTags(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -165,7 +176,7 @@ export interface EditFileOptions {
password?: string | null;
type?: string;
favorite?: boolean;
tags?: Array<APITag["id"]>
tags?: Array<APITag["id"]>;
}
// PATCH /api/user/files/[id]
export async function editFile(
@ -175,7 +186,7 @@ export async function editFile(
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL"
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.patch(`${url}/api/user/files/${id}`, options, {
@ -187,15 +198,17 @@ export async function editFile(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -214,15 +227,15 @@ export interface UploadFileOptions {
// POST /api/upload
export async function uploadFiles(
file: {
uri: string,
mimetype: string
uri: string;
mimetype: string;
},
options: UploadFileOptions = {},
): Promise<Array<APIUploadFile> | string> {
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL"
if (!url || !token) return "Invalid token or URL";
const headers: {
[key: string]: string;
@ -253,19 +266,21 @@ export async function uploadFiles(
httpMethod: "POST",
fieldName: "file",
mimeType: file.mimetype,
})
});
return JSON.parse(res.body)?.files || [];
} catch(e) {
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
}

View file

@ -25,15 +25,17 @@ export async function getFolders<T extends boolean | undefined = undefined>(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -54,15 +56,17 @@ export async function getFolder(id: string): Promise<APIFolder | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -93,15 +97,17 @@ export async function createFolder(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -131,15 +137,17 @@ export async function editFolder(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -163,15 +171,17 @@ export async function deleteFolder(id: string): Promise<APIFolder | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -199,15 +209,17 @@ export async function removeFileFromFolder(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -237,14 +249,16 @@ export async function addFileToFolder(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -19,19 +19,24 @@ export async function getInvites(): Promise<APIInvites | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
export async function createInvite(expiresAt?: string, maxUses?: number): Promise<APIInvite | string> {
export async function createInvite(
expiresAt?: string,
maxUses?: number,
): Promise<APIInvite | string> {
const token = db.get("token");
const url = db.get("url");
@ -48,21 +53,23 @@ export async function createInvite(expiresAt?: string, maxUses?: number): Promis
headers: {
Authorization: token,
},
}
},
);
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -73,26 +80,25 @@ export async function deleteInvite(code: string): Promise<APIInvite | string> {
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.delete(
`${url}/api/auth/invites/${code}`,
{
headers: {
Authorization: token,
},
}
);
const res = await axios.delete(`${url}/api/auth/invites/${code}`, {
headers: {
Authorization: token,
},
});
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
}

View file

@ -2,159 +2,184 @@ import * as db from "@/functions/database";
import type { APIFile, ServerActionResponse } from "@/types/zipline";
import axios, { type AxiosError } from "axios";
export async function clearZeroByteFiles(): Promise<ServerActionResponse | string> {
const token = db.get("token");
const url = db.get("url");
export async function clearZeroByteFiles(): Promise<
ServerActionResponse | string
> {
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL";
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.delete(`${url}/api/server/clear_zeros`, {
headers: {
Authorization: token,
},
});
try {
const res = await axios.delete(`${url}/api/server/clear_zeros`, {
headers: {
Authorization: token,
},
});
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
return res.data;
} catch (e) {
const error = e as AxiosError;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
}
if (data) return data.error;
return "Something went wrong...";
}
}
export async function getZeroByteFiles(): Promise<{
files: Array<{
id: string;
name: string;
}>;
} | string> {
const token = db.get("token");
const url = db.get("url");
export async function getZeroByteFiles(): Promise<
| {
files: Array<{
id: string;
name: string;
}>;
}
| string
> {
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL";
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.get(`${url}/api/server/clear_zeros`, {
headers: {
Authorization: token,
},
});
try {
const res = await axios.get(`${url}/api/server/clear_zeros`, {
headers: {
Authorization: token,
},
});
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
return res.data;
} catch (e) {
const error = e as AxiosError;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
}
if (data) return data.error;
return "Something went wrong...";
}
}
export async function clearTempFiles(): Promise<ServerActionResponse | string> {
const token = db.get("token");
const url = db.get("url");
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL";
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.delete(`${url}/api/server/clear_temp`, {
headers: {
Authorization: token,
},
});
try {
const res = await axios.delete(`${url}/api/server/clear_temp`, {
headers: {
Authorization: token,
},
});
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
return res.data;
} catch (e) {
const error = e as AxiosError;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
}
if (data) return data.error;
return "Something went wrong...";
}
}
interface RequeryOptions {
forceUpdate: boolean;
forceDelete: boolean;
forceUpdate: boolean;
forceDelete: boolean;
}
export async function requeryFileSize({
forceUpdate = false,
forceDelete = false
forceUpdate = false,
forceDelete = false,
}: RequeryOptions): Promise<ServerActionResponse | string> {
const token = db.get("token");
const url = db.get("url");
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL";
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.post(`${url}/api/server/requery_size`, {
forceDelete,
forceUpdate
}, {
headers: {
Authorization: token,
},
});
try {
const res = await axios.post(
`${url}/api/server/requery_size`,
{
forceDelete,
forceUpdate,
},
{
headers: {
Authorization: token,
},
},
);
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
return res.data;
} catch (e) {
const error = e as AxiosError;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
}
if (data) return data.error;
return "Something went wrong...";
}
}
export async function generateThumbnails(rerun = false): Promise<ServerActionResponse | string> {
const token = db.get("token");
const url = db.get("url");
export async function generateThumbnails(
rerun = false,
): Promise<ServerActionResponse | string> {
const token = db.get("token");
const url = db.get("url");
if (!url || !token) return "Invalid token or URL";
if (!url || !token) return "Invalid token or URL";
try {
const res = await axios.post(`${url}/api/server/thumbnails`, {
rerun
}, {
headers: {
Authorization: token,
},
});
try {
const res = await axios.post(
`${url}/api/server/thumbnails`,
{
rerun,
},
{
headers: {
Authorization: token,
},
},
);
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
return res.data;
} catch (e) {
const error = e as AxiosError;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
}
}
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -20,22 +20,24 @@ export async function getSettings(): Promise<APISettings | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
interface APIIssue {
code: string;
message: string;
path: Array<string>
path: Array<string>;
}
// PATCH /api/server/settings
export async function updateSettings(
@ -56,14 +58,20 @@ export async function updateSettings(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
issues: Array<APIIssue>;
statusCode: number;
} | undefined;
if (data) return data.issues.map(issue => `${settingNames[issue.path.join(".") as keyof typeof settingNames] || issue.path.join(".")} - ${issue.message}`)
const data = error.response?.data as
| {
issues: Array<APIIssue>;
statusCode: number;
}
| undefined;
return ["Something went wrong..."]
if (data)
return data.issues.map(
(issue) =>
`${settingNames[issue.path.join(".") as keyof typeof settingNames] || issue.path.join(".")} - ${issue.message}`,
);
return ["Something went wrong..."];
}
}

View file

@ -3,16 +3,16 @@ import * as db from "@/functions/database";
import axios, { type AxiosError } from "axios";
export interface StatsProps {
from?: string,
to?: string,
all?: boolean
from?: string;
to?: string;
all?: boolean;
}
// GET /api/stats
export async function getStats({
from,
to,
all = false
all = false,
}: StatsProps): Promise<APIStats | string> {
const token = db.get("token");
const url = db.get("url");
@ -35,15 +35,17 @@ export async function getStats({
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -64,21 +66,21 @@ export async function getUserStats(): Promise<APIUserStats | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
export function getChartFiles(stats: APIStats) {
}
export function getChartFiles(stats: APIStats) {}
export function filterStats(data: APIStats, amount = 100) {
data.sort(

View file

@ -19,15 +19,17 @@ export async function getTags(): Promise<APITags | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -58,15 +60,17 @@ export async function createTag(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -87,15 +91,17 @@ export async function deleteTag(id: string): Promise<APITag | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -126,14 +132,16 @@ export async function editTag(id: string, options: EditTagOptions = {}) {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -19,15 +19,17 @@ export async function getURLs(): Promise<APIURLs | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -48,15 +50,17 @@ export async function getURL(id: string): Promise<APIURL | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -73,10 +77,13 @@ export async function createURL({
vanity,
maxViews,
password,
enabled = true
}: CreateURLParams): Promise<{
url: string;
} | string> {
enabled = true,
}: CreateURLParams): Promise<
| {
url: string;
}
| string
> {
const token = db.get("token");
const url = db.get("url");
@ -93,7 +100,7 @@ export async function createURL({
{
destination,
vanity,
enabled
enabled,
},
{
headers: {
@ -106,15 +113,17 @@ export async function createURL({
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -135,15 +144,17 @@ export async function deleteURL(id: string): Promise<APIURL | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -174,14 +185,16 @@ export async function editURL(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -19,15 +19,17 @@ export async function getCurrentUser(): Promise<APISelfUser | string> {
return res.data.user;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -48,15 +50,17 @@ export async function getRecentFiles(): Promise<APIRecentFiles | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -115,14 +119,16 @@ export async function editCurrentUser(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}

View file

@ -30,15 +30,17 @@ export async function getUsers<T extends boolean | undefined = undefined>(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -58,15 +60,17 @@ export async function getUser(id: string): Promise<APIUser | string> {
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -101,15 +105,17 @@ export async function createUser(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -136,15 +142,17 @@ export async function deleteUser(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}
@ -194,14 +202,16 @@ export async function editUser(
return res.data;
} catch (e) {
const error = e as AxiosError;
const data = error.response?.data as {
error: string;
statusCode: number;
} | undefined;
if (data) return data.error
const data = error.response?.data as
| {
error: string;
statusCode: number;
}
| undefined;
return "Something went wrong..."
if (data) return data.error;
return "Something went wrong...";
}
}