mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +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.
77 lines
2.1 KiB
JavaScript
Vendored
77 lines
2.1 KiB
JavaScript
Vendored
import http from '@/scripts/http'
|
|
import { defineStore } from 'pinia'
|
|
import { useNotificationStore } from '@/scripts/stores/notification'
|
|
import { handleError } from '@/scripts/helpers/error-handling'
|
|
|
|
export const useBackupStore = (useWindow = false) => {
|
|
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
|
const { global } = window.i18n
|
|
|
|
return defineStoreFunc({
|
|
id: 'backup',
|
|
|
|
state: () => ({
|
|
backups: [],
|
|
currentBackupData: {
|
|
option: 'full',
|
|
selected_disk: null,
|
|
},
|
|
}),
|
|
|
|
actions: {
|
|
fetchBackups(params) {
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.get(`/api/v1/backups`, { params })
|
|
.then((response) => {
|
|
this.backups = response.data.data
|
|
resolve(response)
|
|
})
|
|
.catch((err) => {
|
|
handleError(err)
|
|
reject(err)
|
|
})
|
|
})
|
|
},
|
|
|
|
createBackup(data) {
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.post(`/api/v1/backups`, data)
|
|
.then((response) => {
|
|
const notificationStore = useNotificationStore()
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: global.t('settings.backup.created_message'),
|
|
})
|
|
resolve(response)
|
|
})
|
|
.catch((err) => {
|
|
handleError(err)
|
|
reject(err)
|
|
})
|
|
})
|
|
},
|
|
|
|
removeBackup(params) {
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.delete(`/api/v1/backups/${params.disk}`, { params })
|
|
.then((response) => {
|
|
const notificationStore = useNotificationStore()
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: global.t('settings.backup.deleted_message'),
|
|
})
|
|
resolve(response)
|
|
})
|
|
.catch((err) => {
|
|
handleError(err)
|
|
reject(err)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
})()
|
|
}
|