mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-06-26 07:08:45 +02:00
Disable CapacitorHttp and add plugin to replace axios calls #781
This commit is contained in:
parent
27bbe40874
commit
57d1fbfa83
21 changed files with 142 additions and 62 deletions
40
plugins/nativeHttp.js
Normal file
40
plugins/nativeHttp.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { CapacitorHttp } from '@capacitor/core'
|
||||
|
||||
export default function ({ store }, inject) {
|
||||
const nativeHttp = {
|
||||
request(method, _url, data, options = {}) {
|
||||
let url = _url
|
||||
const headers = {}
|
||||
if (!url.startsWith('http') && !url.startsWith('capacitor')) {
|
||||
const bearerToken = store.getters['user/getToken']
|
||||
if (bearerToken) {
|
||||
headers['Authorization'] = `Bearer ${bearerToken}`
|
||||
} else {
|
||||
console.warn('[nativeHttp] No Bearer Token for request')
|
||||
}
|
||||
const serverUrl = store.getters['user/getServerAddress']
|
||||
if (serverUrl) {
|
||||
url = `${serverUrl}${url}`
|
||||
}
|
||||
}
|
||||
console.log(`[nativeHttp] Making ${method} request to ${url}`)
|
||||
return CapacitorHttp.request({
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
headers,
|
||||
...options
|
||||
}).then(res => res.data)
|
||||
},
|
||||
get(url, options = {}) {
|
||||
return this.request('GET', url, undefined, options)
|
||||
},
|
||||
post(url, data, options = {}) {
|
||||
return this.request('POST', url, data, options)
|
||||
},
|
||||
patch(url, data, options = {}) {
|
||||
return this.request('PATCH', url, data, options)
|
||||
}
|
||||
}
|
||||
inject('nativeHttp', nativeHttp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue