mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 21:44:51 +00:00
* refactor: add HTTP client wrapper and upgrade axios to v1 Introduce a thin HTTP wrapper (resources/scripts/http) that centralizes axios configuration, interceptors, and auth header injection. All 43 files now import from the wrapper instead of axios directly, making future library swaps a single-file change. Upgrade axios from 0.30.0 to 1.14.0. * fix: restore window.Ls assignment removed during axios refactor company.js uses window.Ls.set() to persist selected company, which broke after the axios plugin (that set window.Ls) was deleted.
71 lines
1.9 KiB
JavaScript
Vendored
71 lines
1.9 KiB
JavaScript
Vendored
const { defineStore } = window.pinia
|
|
import { handleError } from '@/scripts/helpers/error-handling'
|
|
import { useNotificationStore } from '@/scripts/stores/notification'
|
|
import http from '@/scripts/http'
|
|
|
|
export const usePDFDriverStore = (useWindow = false) => {
|
|
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
|
const { global } = window.i18n
|
|
|
|
return defineStoreFunc({
|
|
id: 'pdf-driver',
|
|
|
|
state: () => ({
|
|
pdfDriverConfig: null,
|
|
pdf_driver: 'dompdf',
|
|
pdf_drivers: [],
|
|
|
|
dompdf: {
|
|
pdf_driver: '',
|
|
},
|
|
gotenberg: {
|
|
pdf_driver: '',
|
|
gotenberg_host: '',
|
|
gotenberg_papersize: ''
|
|
}
|
|
}),
|
|
|
|
actions: {
|
|
async fetchDrivers() {
|
|
try {
|
|
const response = await http.get('/api/v1/pdf/drivers')
|
|
this.pdf_drivers = response.data
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
async fetchConfig() {
|
|
try {
|
|
const response = await http.get('/api/v1/pdf/config')
|
|
this.pdfDriverConfig = response.data
|
|
this.pdf_driver = response.data.pdf_driver
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
async updateConfig(data) {
|
|
try {
|
|
const response = await http.post('/api/v1/pdf/config', data)
|
|
const notificationStore = useNotificationStore()
|
|
if (response.data.success) {
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: global.t('settings.pdf.' + response.data.success),
|
|
})
|
|
} else {
|
|
notificationStore.showNotification({
|
|
type: 'error',
|
|
message: global.t('settings.pdf.' + response.data.error),
|
|
})
|
|
}
|
|
} catch (err) {
|
|
handleError(err)
|
|
throw err
|
|
}
|
|
},
|
|
},
|
|
})()
|
|
}
|