A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
Implement services I am not sure how
aminnausina136c2a1ca79
diff --git a/resources/js/service/api.js b/resources/js/service/api.jsnew file mode 100644index 00000000..671cf41d--- /dev/null+++ b/resources/js/service/api.js@@ -0,0 +1,17 @@+import axios from "axios";++const API = axios.create({+ baseURL: "/api",+ headers: {+ "Accept": "application/json",+ "Content-Type": "application/json",+ },+});++export function apiGET(url) {+ return API.get(url);+}++export function apiPost(url, data) {+ return API.post(url, data);+}\ No newline at end of filediff --git a/resources/js/service/serviceRecords.js b/resources/js/service/serviceRecords.jsnew file mode 100644index 00000000..c9699421--- /dev/null+++ b/resources/js/service/serviceRecords.js@@ -0,0 +1,95 @@+import { ref } from 'vue';+import axios from "axios";+++/*+ ACTIONS for record data ?++ Have get, add, and delete actions+ Run and commit to database (store)+*/+export function useRecords() {+ const records = ref([]);++ //GET+ async function getRecords(){+ if(!auth) return;+ fetch(`/api/records${limit ? `?limit=${limit}` : ''}`, {+ method: 'get',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true){+ parseHistory(json.data);+ }+ }).catch((error) => {+ console.log(error);+ });+ }++ //POST+ async function addRecord(videoID){+ const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');++ fetch(`/api/records`, {+ method: 'post',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ },+ body: JSON.stringify({+ 'video_id': videoID,+ })+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true) {+ // toastr['success']('Added to history!');+ // loadHistory();+ parseHistory([json.data], 10, false);+ };+ }).catch((error) => {+ console.log(error);+ });+ }++ //DELETE+ async function deleteRecord(id){+ const CSRF = document.querySelector('meta[name="csrf-token"]').getAttribute('content');+ const RECORDID = parseInt(id);+ if(isNaN(RECORDID)){+ toastr.error(`Invalid Record ID... ${RECORDID}}`);+ return;+ }++ fetch(`/api/records/${RECORDID}`, {+ method: 'delete',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': CSRF+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ if(json.success == true) {+ let newRecordsList = records.value.filter((record) => {+ return record.recordID != RECORDID;+ });+ records.value = newRecordsList;+ toastr.success('Record deleted!');+ };+ }).catch((error) => {+ console.log(error);+ toastr.error('Unable to delete record.');+ });+ }+}\ No newline at end of filediff --git a/resources/js/use/useMedia.js b/resources/js/use/useMedia.jsnew file mode 100644index 00000000..7a243bd0--- /dev/null+++ b/resources/js/use/useMedia.js@@ -0,0 +1,3 @@+export function useMedia() {++}\ No newline at end of filediff --git a/resources/js/use/useRecords.js b/resources/js/use/useRecords.jsnew file mode 100644index 00000000..25c6e6e6--- /dev/null+++ b/resources/js/use/useRecords.js@@ -0,0 +1,98 @@+import { ref } from 'vue';+import axios from "axios";+++/*+ ACTIONS for record data ?++ Have get, add, and delete actions+ Run and commit to database (store)+*/+export function useRecords() {+ const records = ref(null);+ const error = ref(null);++ //GET+ async function getRecords(limit = 10){+ // if(!auth) return;+ fetch(`/api/records${limit ? `?limit=${limit}` : ''}`, {+ method: 'get',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true){+ parseHistory(json.data);+ }+ }).catch((error) => {+ console.log(error);+ });+ }++ //POST+ async function addRecord(videoID){+ const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');++ fetch(`/api/records`, {+ method: 'post',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ },+ body: JSON.stringify({+ 'video_id': videoID,+ })+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true) {+ // toastr['success']('Added to history!');+ // loadHistory();+ parseHistory([json.data], 10, false);+ };+ }).catch((error) => {+ console.log(error);+ });+ }++ //DELETE+ async function deleteRecord(id){+ const CSRF = document.querySelector('meta[name="csrf-token"]').getAttribute('content');+ const RECORDID = parseInt(id);+ if(isNaN(RECORDID)){+ toastr.error(`Invalid Record ID... ${RECORDID}}`);+ return;+ }++ fetch(`/api/records/${RECORDID}`, {+ method: 'delete',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': CSRF+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ if(json.success == true) {+ let newRecordsList = records.value.filter((record) => {+ return record.recordID != RECORDID;+ });+ records.value = newRecordsList;+ toastr.success('Record deleted!');+ };+ }).catch((error) => {+ console.log(error);+ toastr.error('Unable to delete record.');+ });+ }++ return { records, error};+}\ No newline at end of filediff --git a/resources/js/use/useResource.js b/resources/js/use/useResource.jsnew file mode 100644index 00000000..79bbc375--- /dev/null+++ b/resources/js/use/useResource.js@@ -0,0 +1,14 @@+import { ref } from "vue";++export function useResource() {+ const data = ref(null)+ const error = ref(null)++ // GET++ // POST++ // PATCH++ // DELETE+}\ No newline at end of file