using axios and global store pinia

This commit is contained in:
2025-11-30 14:07:47 +00:00
parent 57a6134d24
commit 52b182730c
6 changed files with 356 additions and 18 deletions

View File

@@ -14,6 +14,7 @@
<script setup>
import { ref, onMounted } from "vue";
import axios from "axios";
const streamMount = ref("");
const streamUrl = ref("");
@@ -22,15 +23,15 @@ const audio = ref(null);
async function checkStream() {
try {
const res = await fetch("/radio/status-json.xsl"); // Icecast JSON status
const data = await res.json();
const res = await axios.get("/radio/status-json.xsl");
const data = res.data;
streamMount.value = data.icestats.source.listenurl.split("/").pop();
if (streamMount.value) {
streamLive.value = true;
streamUrl.value = "/radio/" + streamMount.value;
if (audio.value) audio.value.load(); // reload audio if it was offline before
if (audio.value) audio.value.load();
}
} catch (err) {
streamLive.value = false;

View File

@@ -1,5 +1,5 @@
<template>
<div v-if="loggedIn">
<div v-if="!loggedIn">
<h1>login</h1>
</div>
</template>
@@ -10,9 +10,11 @@ export default {
name: "api-login",
setup() {
const loggedIn = ref(false);
onMounted(() => {
loggedIn.value = true;
});
return { loggedIn };
},
};

View File

@@ -13,6 +13,7 @@
<script>
import { ref, onMounted } from "vue";
import axios from "axios";
export default {
name: "spotify-listening",
@@ -21,9 +22,8 @@ export default {
async function fetchSpotify() {
try {
const res = await fetch("/api/spotify/listening");
if (!res.ok) throw new Error("Failed to fetch Spotify data");
song.value = await res.json();
const res = await axios.get("/api/spotify/listening");
song.value = res.data;
} catch (err) {
console.error(err);
}

View File

@@ -31,6 +31,7 @@
<script>
import { ref, onMounted } from "vue";
import axios from "axios";
export default {
name: "spotify-recent",
@@ -40,9 +41,8 @@ export default {
async function fetchRecent() {
try {
const res = await fetch("/api/spotify/recent");
if (!res.ok) throw new Error("Failed to fetch Spotify data");
played.value = await res.json();
const res = await axios.get("/api/spotify/recent");
played.value = res.data;
fetched.value = true;
} catch (err) {
console.error(err);