This repository has been archived on 2026-05-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
GallerySubscriber/frontend/src/stores/downloads.js
T
2026-01-24 22:52:51 -05:00

51 lines
1.1 KiB
JavaScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { downloadsApi } from '../services/api'
export const useDownloadsStore = defineStore('downloads', () => {
const downloads = ref([])
const stats = ref(null)
const loading = ref(false)
const total = ref(0)
const currentPage = ref(1)
const perPage = ref(20)
async function fetchDownloads(params = {}) {
loading.value = true
try {
const response = await downloadsApi.list({
page: currentPage.value,
per_page: perPage.value,
...params,
})
downloads.value = response.data.items
total.value = response.data.total
return response.data
} finally {
loading.value = false
}
}
async function fetchStats(params = {}) {
const response = await downloadsApi.stats(params)
stats.value = response.data
return response.data
}
async function retryDownload(id) {
return await downloadsApi.retry(id)
}
return {
downloads,
stats,
loading,
total,
currentPage,
perPage,
fetchDownloads,
fetchStats,
retryDownload,
}
})