mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-06 20:08:48 +02:00
init
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
export default function ({ $axios, store }) {
|
||||
$axios.onRequest(config => {
|
||||
console.log('[Axios] Making request to ' + config.url)
|
||||
if (config.url.startsWith('http:') || config.url.startsWith('https:')) {
|
||||
return
|
||||
}
|
||||
var bearerToken = store.getters['user/getToken']
|
||||
if (bearerToken) {
|
||||
config.headers.common['Authorization'] = `Bearer ${bearerToken}`
|
||||
} else {
|
||||
console.warn('[Axios] No Bearer Token for request')
|
||||
}
|
||||
|
||||
var serverUrl = store.state.serverUrl
|
||||
if (serverUrl) {
|
||||
config.url = `${serverUrl}${config.url}`
|
||||
}
|
||||
console.log('[Axios] Request out', config.url)
|
||||
})
|
||||
|
||||
$axios.onError(error => {
|
||||
const code = parseInt(error.response && error.response.status)
|
||||
console.error('Axios error code', code)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import Vue from 'vue'
|
||||
Vue.prototype.$isDev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
import { Toast } from '@capacitor/toast'
|
||||
|
||||
Vue.prototype.$toast = (text) => {
|
||||
if (!Toast) {
|
||||
return console.error('No Toast Plugin')
|
||||
}
|
||||
Toast.show({
|
||||
text: text
|
||||
})
|
||||
}
|
||||
|
||||
Vue.prototype.$bytesPretty = (bytes, decimals = 2) => {
|
||||
if (bytes === 0) {
|
||||
return '0 Bytes'
|
||||
}
|
||||
const k = 1024
|
||||
const dm = decimals < 0 ? 0 : decimals
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
Vue.prototype.$secondsToTimestamp = (seconds) => {
|
||||
var _seconds = seconds
|
||||
var _minutes = Math.floor(seconds / 60)
|
||||
_seconds -= _minutes * 60
|
||||
var _hours = Math.floor(_minutes / 60)
|
||||
_minutes -= _hours * 60
|
||||
_seconds = Math.round(_seconds)
|
||||
if (!_hours) {
|
||||
return `${_minutes}:${_seconds.toString().padStart(2, '0')}`
|
||||
}
|
||||
return `${_hours}:${_minutes.toString().padStart(2, '0')}:${_seconds.toString().padStart(2, '0')}`
|
||||
}
|
||||
|
||||
|
||||
function isClickedOutsideEl(clickEvent, elToCheckOutside, ignoreSelectors = [], ignoreElems = []) {
|
||||
const isDOMElement = (element) => {
|
||||
return element instanceof Element || element instanceof HTMLDocument
|
||||
}
|
||||
|
||||
const clickedEl = clickEvent.srcElement
|
||||
const didClickOnIgnoredEl = ignoreElems.filter((el) => el).some((element) => element.contains(clickedEl) || element.isEqualNode(clickedEl))
|
||||
const didClickOnIgnoredSelector = ignoreSelectors.length ? ignoreSelectors.map((selector) => clickedEl.closest(selector)).reduce((curr, accumulator) => curr && accumulator, true) : false
|
||||
|
||||
if (isDOMElement(elToCheckOutside) && !elToCheckOutside.contains(clickedEl) && !didClickOnIgnoredEl && !didClickOnIgnoredSelector) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Vue.directive('click-outside', {
|
||||
bind: function (el, binding, vnode) {
|
||||
let vm = vnode.context;
|
||||
let callback = binding.value;
|
||||
if (typeof callback !== 'function') {
|
||||
console.error('Invalid callback', binding)
|
||||
return
|
||||
}
|
||||
el['__click_outside__'] = (ev) => {
|
||||
if (isClickedOutsideEl(ev, el)) {
|
||||
callback.call(vm, ev)
|
||||
}
|
||||
}
|
||||
document.addEventListener('click', el['__click_outside__'], false)
|
||||
},
|
||||
unbind: function (el, binding, vnode) {
|
||||
document.removeEventListener('click', el['__click_outside__'], false)
|
||||
delete el['__click_outside__']
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
import { registerPlugin } from '@capacitor/core';
|
||||
|
||||
const MyNativeAudio = registerPlugin('MyNativeAudio');
|
||||
export default MyNativeAudio;
|
||||
@@ -0,0 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import Server from '../Server'
|
||||
|
||||
Vue.prototype.$server = null
|
||||
export default function ({ store }) {
|
||||
Vue.prototype.$server = new Server(store)
|
||||
}
|
||||
Reference in New Issue
Block a user