Compare commits
No commits in common. "5f82c5bef8011bd7cee853bde76433585d93b88b" and "2010cc326019085ca37fcdc8b8dab8445006b6fa" have entirely different histories.
5f82c5bef8
...
2010cc3260
@ -11,22 +11,14 @@ axios.interceptors.response.use(response => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default class Apiclient {
|
export default class Apiclient {
|
||||||
|
|
||||||
/**
|
|
||||||
* API-Getter for the linkylinky api stats endpoint
|
|
||||||
* @returns Current linkylinky stats (url count, total visits)
|
|
||||||
*/
|
|
||||||
static async getStats() {
|
static async getStats() {
|
||||||
return (
|
return (
|
||||||
await axios.get('https://kauft.es/api/stats')
|
await axios.get('https://kauft.es/api/stats')
|
||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API-Getter for the linkylinky api all urls endpoint (needs auth)
|
|
||||||
* @returns All urls with shortcode, target, full url and visits in an array of objects
|
|
||||||
*/
|
|
||||||
static async getUrls() {
|
static async getUrls() {
|
||||||
|
console.log("APICALL")
|
||||||
return (
|
return (
|
||||||
await axios.get('https://kauft.es/api?showVisits=true', {
|
await axios.get('https://kauft.es/api?showVisits=true', {
|
||||||
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
||||||
@ -34,13 +26,7 @@ export default class Apiclient {
|
|||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API-Getter for the linkylinky api url details endpoint (needs auth)
|
|
||||||
* @param {*} shortcode The shortcode of your favourite url
|
|
||||||
* @returns Url shortcode, target, full url and visit count in an object
|
|
||||||
*/
|
|
||||||
static async getUrlDetails(shortcode) {
|
static async getUrlDetails(shortcode) {
|
||||||
//TODO: Handle 404
|
|
||||||
return (
|
return (
|
||||||
await axios.get(`https://kauft.es/api/${shortcode}`, {
|
await axios.get(`https://kauft.es/api/${shortcode}`, {
|
||||||
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
||||||
@ -48,13 +34,7 @@ export default class Apiclient {
|
|||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API-Getter for the linkylinky api url vists endpoint (needs auth)
|
|
||||||
* @param {*} shortcode The shortcode of your favourite url
|
|
||||||
* @returns Url visit details as an object for each visits (r/n they only contain timestamps)
|
|
||||||
*/
|
|
||||||
static async getUrlVisits(shortcode) {
|
static async getUrlVisits(shortcode) {
|
||||||
//TODO: Handle 404
|
|
||||||
return (
|
return (
|
||||||
await axios.get(`https://kauft.es/api/${shortcode}/visits`, {
|
await axios.get(`https://kauft.es/api/${shortcode}/visits`, {
|
||||||
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
||||||
@ -62,11 +42,6 @@ export default class Apiclient {
|
|||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API-Delet for the linkylinky api url deletion endpoint (needs auth)
|
|
||||||
* @param {*} shortcode The shortcode of your most hated url
|
|
||||||
* @returns Just a 204 (no matter if the url got deleted or didn't exist in the first place)
|
|
||||||
*/
|
|
||||||
static async deleteUrl(shortcode) {
|
static async deleteUrl(shortcode) {
|
||||||
return (
|
return (
|
||||||
await axios.delete(`https://kauft.es/api/${shortcode}`, {
|
await axios.delete(`https://kauft.es/api/${shortcode}`, {
|
||||||
@ -75,12 +50,6 @@ export default class Apiclient {
|
|||||||
).status;
|
).status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Login and receive a JWT for future auth.
|
|
||||||
* @param {*} username Your username (cleartext)
|
|
||||||
* @param {*} password Your password (cleartext)
|
|
||||||
* @returns A user login object containing your jwt
|
|
||||||
*/
|
|
||||||
static async login(username, password) {
|
static async login(username, password) {
|
||||||
return (
|
return (
|
||||||
await axios.post(`https://kauft.es/api/auth/login`, {}, {
|
await axios.post(`https://kauft.es/api/auth/login`, {}, {
|
||||||
@ -91,10 +60,6 @@ export default class Apiclient {
|
|||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Log yourself out -> Invalidates your current (and past) JWTs
|
|
||||||
* @returns Done!
|
|
||||||
*/
|
|
||||||
static async logout() {
|
static async logout() {
|
||||||
return (
|
return (
|
||||||
await axios.post(`https://kauft.es/api/auth/logout`, {}, {
|
await axios.post(`https://kauft.es/api/auth/logout`, {}, {
|
||||||
|
@ -5,10 +5,6 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import * as localForage from 'localforage';
|
import * as localForage from 'localforage';
|
||||||
|
|
||||||
/**
|
|
||||||
* Master init for all things userstore, b/c async stuff somethimes does weired shit.
|
|
||||||
* Yes i know this isn't the best way to implement this, but linkylinky dashboard is just a oneshot sideproject r/n.
|
|
||||||
*/
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
UserStore.init();
|
UserStore.init();
|
||||||
localForage.getItem('userdata', (err, value) => {
|
localForage.getItem('userdata', (err, value) => {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
$: urlVisists = [];
|
$: urlVisists = [];
|
||||||
let visitQuery;
|
let visitQuery;
|
||||||
|
|
||||||
// Yes i know this isn't the best way to implement this, but linkylinky dashboard is just a oneshot sideproject r/n.
|
|
||||||
const unsubscribe = UserStore.subscribe((value) => {
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
if (value.isLoggedIn) {
|
if (value.isLoggedIn) {
|
||||||
Apiclient.getUrlDetails(shortcode).then((res) => {
|
Apiclient.getUrlDetails(shortcode).then((res) => {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
$: urls = [];
|
$: urls = [];
|
||||||
let urlQuery;
|
let urlQuery;
|
||||||
|
|
||||||
// Yes i know this isn't the best way to implement this, but linkylinky dashboard is just a oneshot sideproject r/n.
|
|
||||||
const unsubscribe = UserStore.subscribe((value) => {
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
if (value.isLoggedIn) {
|
if (value.isLoggedIn) {
|
||||||
urlQuery = Apiclient.getUrls().then((res) => {
|
urlQuery = Apiclient.getUrls().then((res) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user