mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
first commit :D
This commit is contained in:
parent
40b7eabefe
commit
ed5c91435d
41 changed files with 724 additions and 907 deletions
15
functions/database.ts
Normal file
15
functions/database.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import * as SecureStore from "expo-secure-store";
|
||||
|
||||
export function set(key: string, value: string) {
|
||||
SecureStore.setItem(key, value);
|
||||
}
|
||||
|
||||
export function get(key: string) {
|
||||
const result = SecureStore.getItem(key);
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
79
functions/zipline.ts
Normal file
79
functions/zipline.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
import * as db from "@/functions/database";
|
||||
import type { APIRecentFiles, APIStats, APIUser } from "@/types/zipline";
|
||||
import axios from "axios";
|
||||
|
||||
export async function getUser() {
|
||||
const token = db.get("token")
|
||||
const url = db.get("url")
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user`, {
|
||||
headers: {
|
||||
Authorization: token
|
||||
}
|
||||
})
|
||||
|
||||
return res.data.user as APIUser;
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRecentFiles() {
|
||||
const token = db.get("token")
|
||||
const url = db.get("url")
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user/recent`, {
|
||||
headers: {
|
||||
Authorization: token
|
||||
}
|
||||
})
|
||||
|
||||
return res.data as APIRecentFiles;
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStats() {
|
||||
const token = db.get("token")
|
||||
const url = db.get("url")
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user/stats`, {
|
||||
headers: {
|
||||
Authorization: token
|
||||
}
|
||||
})
|
||||
|
||||
return res.data as APIStats;
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserAvatar() {
|
||||
const token = db.get("token")
|
||||
const url = db.get("url")
|
||||
|
||||
if (!url || !token) return null;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${url}/api/user/avatar`, {
|
||||
headers: {
|
||||
Authorization: token
|
||||
}
|
||||
})
|
||||
|
||||
return res.data as string;
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue