Files
InvoiceShelf/resources/scripts-v2/api/services/disk.service.ts
Darko Gjorgjijoski 20085cab5d Refactor FileDisk system with per-disk unique names and disk assignments UI
Major changes to the file disk subsystem:

- Each FileDisk now gets a unique Laravel disk name (disk_{id}) instead
  of temp_{driver}, fixing the bug where multiple local disks with
  different roots overwrote each other's config.

- Move disk registration logic from FileDisk model to FileDiskService
  (registerDisk, getDiskName). Model keeps only getDecodedCredentials
  and a deprecated setConfig() wrapper.

- Add Disk Assignments admin UI (File Disk tab) with three purpose
  dropdowns: Media Storage, PDF Storage, Backup Storage. Stored as
  settings (media_disk_id, pdf_disk_id, backup_disk_id).

- Backup tab now uses the assigned backup disk instead of a per-backup
  dropdown. BackupsController refactored to use BackupService which
  centralizes disk resolution. Removed stale 4-second cache.

- Add local_public disk to config/filesystems.php so system disks
  are properly defined.

- Local disk roots stored relative to storage/app/ with hint text
  in the admin modal explaining the convention.

- Fix BaseModal watchEffect -> watch to prevent infinite request
  loops on the File Disk page.

- Fix string/number comparison for disk purpose IDs from settings.

- Add safeguards: prevent deleting disks with files, warn on
  purpose change, prevent deleting system disks.
2026-04-07 02:04:57 +02:00

87 lines
2.1 KiB
TypeScript

import { client } from '../client'
import { API } from '../endpoints'
import type { ApiResponse, ListParams, PaginatedResponse } from '@v2/types/api'
export type DiskDriverValue =
| 'local'
| 's3'
| 's3compat'
| 'doSpaces'
| 'dropbox'
export interface Disk {
id: number
name: string
type: string
driver: DiskDriverValue
set_as_default: boolean
credentials: Record<string, string> | string | null
company_id?: number | null
}
export interface DiskDriversResponse {
drivers: Array<{
name: string
value: DiskDriverValue
}>
default: DiskDriverValue | string
}
export interface CreateDiskPayload {
name: string
driver: DiskDriverValue
credentials?: Record<string, string> | string
set_as_default?: boolean
}
export interface DiskPurposes {
media_disk_id: number | null
pdf_disk_id: number | null
backup_disk_id: number | null
}
export const diskService = {
async list(params?: ListParams): Promise<PaginatedResponse<Disk>> {
const { data } = await client.get(API.DISKS, { params })
return data
},
async get(disk: DiskDriverValue): Promise<Record<string, string>> {
const { data } = await client.get(`${API.DISKS}/${disk}`)
return data
},
async create(payload: CreateDiskPayload): Promise<ApiResponse<Disk>> {
const { data } = await client.post(API.DISKS, payload)
return data
},
async update(
id: number,
payload: Partial<CreateDiskPayload>
): Promise<ApiResponse<Disk>> {
const { data } = await client.put(`${API.DISKS}/${id}`, payload)
return data
},
async delete(id: number): Promise<{ success: boolean }> {
const { data } = await client.delete(`${API.DISKS}/${id}`)
return data
},
async getDrivers(): Promise<DiskDriversResponse> {
const { data } = await client.get(API.DISK_DRIVERS)
return data
},
async getDiskPurposes(): Promise<DiskPurposes> {
const { data } = await client.get(API.DISK_PURPOSES)
return data
},
async updateDiskPurposes(payload: Partial<DiskPurposes>): Promise<{ success: boolean }> {
const { data } = await client.put(API.DISK_PURPOSES, payload)
return data
},
}