mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
add some other functions to manage zipline & slightly change some types
This commit is contained in:
parent
370194a486
commit
3aeb0d2816
18 changed files with 370 additions and 125 deletions
|
@ -1,5 +1,6 @@
|
|||
import mimetypesJSON from "@/assets/mimetypes.json";
|
||||
import type { Mimetypes } from "@/types/mimetypes";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
|
||||
const mimetypes = mimetypesJSON as Mimetypes;
|
||||
|
||||
|
@ -33,3 +34,13 @@ export function convertToBlob(data: string): Blob {
|
|||
|
||||
return blob;
|
||||
}
|
||||
|
||||
export async function getFileDataURI(filePath: string): Promise<string | null> {
|
||||
const base64Data = await FileSystem.readAsStringAsync(filePath, {
|
||||
encoding: FileSystem.EncodingType.Base64,
|
||||
});
|
||||
|
||||
const dataURI = `data:image/jpg;base64,${base64Data}`;
|
||||
|
||||
return dataURI;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import * as db from "@/functions/database";
|
|||
import type { APIExports } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
|
||||
// GET /api/user/export
|
||||
export async function getUserExports(): Promise<APIExports | null> {
|
||||
const token = db.get("token");
|
||||
|
@ -44,7 +43,9 @@ export async function createUserExport(): Promise<{ running: boolean } | null> {
|
|||
}
|
||||
|
||||
// DELETE /api/user/export?id=[id]
|
||||
export async function deleteUserExport(id: string): Promise<{ deleted: boolean } | null> {
|
||||
export async function deleteUserExport(
|
||||
id: string,
|
||||
): Promise<{ deleted: boolean } | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
|
@ -62,4 +63,3 @@ export async function deleteUserExport(id: string): Promise<{ deleted: boolean }
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as db from "@/functions/database";
|
|||
import type { APIFile, APIFiles, APISettings } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
import { getSettings } from "@/functions/zipline/settings";
|
||||
import bytesFn, { BytesOptions } from "bytes";
|
||||
import bytesFn from "bytes";
|
||||
import { convertToBlob, generateRandomString, guessMimetype } from "../util";
|
||||
import type { Mimetypes } from "@/types/mimetypes";
|
||||
|
||||
|
@ -154,7 +154,7 @@ interface UploadFileOptions {
|
|||
expiresAt?: Date;
|
||||
}
|
||||
// POST /api/upload
|
||||
export async function uploadToZipline(
|
||||
export async function uploadFile(
|
||||
file: string,
|
||||
options: UploadFileOptions = {},
|
||||
) {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APIFoldersNoIncl,
|
||||
APIFolders,
|
||||
APIFolder,
|
||||
} from "@/types/zipline";
|
||||
import type { APIFoldersNoIncl, APIFolders, APIFolder } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/user/folders
|
||||
|
@ -32,18 +28,15 @@ export async function getFolders<T extends boolean | undefined = undefined>(
|
|||
}
|
||||
}
|
||||
|
||||
// POST /api/user/folders
|
||||
export async function createFolder(name: string, isPublic = false): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
// GET /api/user/folders/[id]
|
||||
export async function getFolder(id: string): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.post(`${url}/api/user/folders`, {
|
||||
name,
|
||||
isPublic
|
||||
}, {
|
||||
const res = await axios.get(`${url}/api/user/folders/${id}`, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
|
@ -55,21 +48,58 @@ export async function createFolder(name: string, isPublic = false): Promise<APIF
|
|||
}
|
||||
}
|
||||
|
||||
// PATCH /api/user/folders/[id]
|
||||
export async function editFolder(id: string, isPublic: boolean): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
// POST /api/user/folders
|
||||
export async function createFolder(
|
||||
name: string,
|
||||
isPublic = false,
|
||||
): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.patch(`${url}/api/user/folders/${id}`, {
|
||||
isPublic
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
const res = await axios.post(
|
||||
`${url}/api/user/folders`,
|
||||
{
|
||||
name,
|
||||
isPublic,
|
||||
},
|
||||
});
|
||||
{
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/user/folders/[id]
|
||||
export async function editFolder(
|
||||
id: string,
|
||||
isPublic: boolean,
|
||||
): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.patch(
|
||||
`${url}/api/user/folders/${id}`,
|
||||
{
|
||||
isPublic,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
|
@ -79,7 +109,7 @@ export async function editFolder(id: string, isPublic: boolean): Promise<APIFold
|
|||
|
||||
// DELETE /api/user/folders/[id]
|
||||
export async function deleteFolder(id: string): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
@ -89,9 +119,9 @@ export async function deleteFolder(id: string): Promise<APIFolder | null> {
|
|||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
data: {
|
||||
delete: "folder"
|
||||
}
|
||||
data: {
|
||||
delete: "folder",
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
|
@ -101,8 +131,11 @@ export async function deleteFolder(id: string): Promise<APIFolder | null> {
|
|||
}
|
||||
|
||||
// DELETE /api/user/folders/[folderId]
|
||||
export async function removeFileFromFolder(folderId: string, fileId: string): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
export async function removeFileFromFolder(
|
||||
folderId: string,
|
||||
fileId: string,
|
||||
): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
@ -112,10 +145,10 @@ export async function removeFileFromFolder(folderId: string, fileId: string): Pr
|
|||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
data: {
|
||||
delete: "file",
|
||||
id: fileId
|
||||
}
|
||||
data: {
|
||||
delete: "file",
|
||||
id: fileId,
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
|
@ -125,23 +158,30 @@ export async function removeFileFromFolder(folderId: string, fileId: string): Pr
|
|||
}
|
||||
|
||||
// POST /api/user/folders/[folderId]
|
||||
export async function addFileToFolder(folderId: string, fileId: string): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
export async function addFileToFolder(
|
||||
folderId: string,
|
||||
fileId: string,
|
||||
): Promise<APIFolder | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.post(`${url}/api/user/folders/${folderId}`, {
|
||||
id: fileId
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
}
|
||||
});
|
||||
const res = await axios.post(
|
||||
`${url}/api/user/folders/${folderId}`,
|
||||
{
|
||||
id: fileId,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APIInvites,
|
||||
} from "@/types/zipline";
|
||||
import type { APIInvites } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/auth/invites
|
||||
|
@ -22,4 +20,4 @@ export async function getInvites(): Promise<APIInvites | null> {
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APISettings,
|
||||
} from "@/types/zipline";
|
||||
import type { APISettings } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/server/settings
|
||||
|
@ -44,4 +42,4 @@ export async function updateSettings(
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APIUserStats,
|
||||
APIStats,
|
||||
} from "@/types/zipline";
|
||||
import type { APIUserStats, APIStats } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/stats
|
||||
|
@ -51,4 +48,4 @@ export async function getUserStats(): Promise<APIUserStats | null> {
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
103
functions/zipline/tags.ts
Normal file
103
functions/zipline/tags.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type { APITag, APITags } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/user/tags
|
||||
export async function getTags(): Promise<APITags | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user/tags`, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/user/tags
|
||||
export async function createTag(
|
||||
name: string,
|
||||
color: string,
|
||||
): Promise<APITag | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.post(
|
||||
`${url}/api/user/tags`,
|
||||
{
|
||||
name,
|
||||
color,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/user/tags/[id]
|
||||
export async function deleteTag(id: string): Promise<APITag | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.delete(`${url}/api/user/tags/${id}`, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
interface EditTagOptions {
|
||||
color?: string;
|
||||
name?: string;
|
||||
}
|
||||
// PATCH /api/user/tags/[id]
|
||||
export async function editTag(id: string, options: EditTagOptions = {}) {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.patch(
|
||||
`${url}/api/user/tags/${id}`,
|
||||
{
|
||||
...options,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APIURLs,
|
||||
APIURL,
|
||||
} from "@/types/zipline";
|
||||
import type { APIURLs, APIURL } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /user/urls
|
||||
|
@ -25,6 +22,26 @@ export async function getURLs(): Promise<APIURLs | null> {
|
|||
}
|
||||
}
|
||||
|
||||
// GET /user/urls/[id]
|
||||
export async function getURL(id: string): Promise<APIURL | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user/urls/${id}`, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
interface CreateURLParams {
|
||||
destination: string;
|
||||
vanity?: string;
|
||||
|
@ -114,4 +131,4 @@ export async function editURL(
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type {
|
||||
APIRecentFiles,
|
||||
APISelfUser,
|
||||
} from "@/types/zipline";
|
||||
import type { APIRecentFiles, APISelfUser } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
// GET /api/user
|
||||
export async function getUser(): Promise<APISelfUser | null> {
|
||||
export async function getCurrentUser(): Promise<APISelfUser | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
|
@ -46,7 +43,7 @@ export async function getRecentFiles(): Promise<APIRecentFiles | null> {
|
|||
}
|
||||
|
||||
// GET /api/user/avatar
|
||||
export async function getUserAvatar(): Promise<string | null> {
|
||||
export async function getCurrentUserAvatar(): Promise<string | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
|
@ -63,4 +60,25 @@ export async function getUserAvatar(): Promise<string | null> {
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type EditCurrentUserOptions = Partial<
|
||||
Omit<
|
||||
APISelfUser,
|
||||
| "role"
|
||||
| "id"
|
||||
| "createdAt"
|
||||
| "updatedAt"
|
||||
| "oauthProviders"
|
||||
| "totpSecret"
|
||||
| "passkeys"
|
||||
| "quota"
|
||||
| "sessions"
|
||||
| "view"
|
||||
> & {
|
||||
view?: Partial<APISelfUser["view"]>;
|
||||
avatar?: string;
|
||||
password?: string;
|
||||
}
|
||||
>;
|
||||
export async function editCurrentUser(options: EditCurrentUserOptions = {}) {}
|
||||
|
|
|
@ -33,6 +33,25 @@ export async function getUsers<T extends boolean | undefined = undefined>(
|
|||
}
|
||||
}
|
||||
|
||||
export async function getUser(id: string): Promise<APIUser | null> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/users/${id}`, {
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/users
|
||||
export async function createUser(
|
||||
username: string,
|
||||
|
@ -93,36 +112,38 @@ export async function deleteUser(
|
|||
}
|
||||
}
|
||||
|
||||
type EditUserOptions = Partial<
|
||||
Omit<
|
||||
APIUser,
|
||||
| "id"
|
||||
| "createdAt"
|
||||
| "updatedAt"
|
||||
| "role"
|
||||
| "view"
|
||||
| "oauthProviders"
|
||||
| "totpSecret"
|
||||
| "passkeys"
|
||||
| "sessions"
|
||||
| "quota"
|
||||
> & {
|
||||
role?: Exclude<APIUser["role"], "SUPERADMIN">;
|
||||
quota?: Partial<
|
||||
Omit<
|
||||
APIUserQuota,
|
||||
"id" | "createdAt" | "updatedAt" | "filesQuota" | "userId"
|
||||
> & {
|
||||
filesType?: APIUserQuota["filesQuota"] | "NONE";
|
||||
}
|
||||
>;
|
||||
password: string;
|
||||
}
|
||||
>;
|
||||
// PATCH /api/users/[id]
|
||||
export async function editUser(
|
||||
id: string,
|
||||
options: Partial<
|
||||
Omit<
|
||||
APIUser,
|
||||
| "id"
|
||||
| "createdAt"
|
||||
| "updatedAt"
|
||||
| "role"
|
||||
| "view"
|
||||
| "oauthProviders"
|
||||
| "totpSecret"
|
||||
| "passkeys"
|
||||
| "sessions"
|
||||
| "quota"
|
||||
> & {
|
||||
role?: Exclude<APIUser["role"], "SUPERADMIN">;
|
||||
quota?: Partial<
|
||||
Omit<
|
||||
APIUserQuota,
|
||||
"id" | "createdAt" | "updatedAt" | "filesQuota" | "userId"
|
||||
> & {
|
||||
filesType?: APIUserQuota["filesQuota"];
|
||||
}
|
||||
>;
|
||||
}
|
||||
> = {},
|
||||
options: EditUserOptions = {},
|
||||
): Promise<APIUser | null> {
|
||||
const token = db.get("token");
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
@ -138,4 +159,4 @@ export async function editUser(
|
|||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue