mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
185 lines
3.3 KiB
TypeScript
185 lines
3.3 KiB
TypeScript
import type { APIFile, ServerActionResponse } from "@/types/zipline";
|
|
import axios, { type AxiosError } from "axios";
|
|
import * as db from "@/functions/database";
|
|
|
|
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";
|
|
|
|
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;
|
|
|
|
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");
|
|
|
|
if (!url || !token) return "Invalid token or URL";
|
|
|
|
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;
|
|
|
|
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");
|
|
|
|
if (!url || !token) return "Invalid token or URL";
|
|
|
|
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;
|
|
|
|
if (data) return data.error;
|
|
|
|
return "Something went wrong...";
|
|
}
|
|
}
|
|
|
|
interface RequeryOptions {
|
|
forceUpdate: boolean;
|
|
forceDelete: boolean;
|
|
}
|
|
export async function requeryFileSize({
|
|
forceUpdate = false,
|
|
forceDelete = false,
|
|
}: RequeryOptions): Promise<ServerActionResponse | string> {
|
|
const token = db.get("token");
|
|
const url = db.get("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,
|
|
},
|
|
},
|
|
);
|
|
|
|
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;
|
|
|
|
return "Something went wrong...";
|
|
}
|
|
}
|
|
|
|
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";
|
|
|
|
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;
|
|
|
|
if (data) return data.error;
|
|
|
|
return "Something went wrong...";
|
|
}
|
|
}
|