mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 20:41:18 +00:00
refactor: account model overhaul
This commit is contained in:
@@ -31,7 +31,7 @@ import {
|
||||
import { formatError } from "@/lib/error"
|
||||
import { directoryContentQueryKey } from "@/vfs/api"
|
||||
import type { DirectoryInfoWithPath } from "@/vfs/vfs"
|
||||
import { currentAccountAtom } from "../account/account"
|
||||
import { currentDriveAtom } from "@/drive/drive"
|
||||
import {
|
||||
clearAllFileUploadStatusesAtom,
|
||||
clearFileUploadStatusesAtom,
|
||||
@@ -68,12 +68,12 @@ function useUploadFilesAtom({
|
||||
() =>
|
||||
mutationOptions({
|
||||
mutationFn: async (files: PickedFile[]) => {
|
||||
const account = store.get(currentAccountAtom)
|
||||
if (!account) throw new Error("No account selected")
|
||||
const drive = store.get(currentDriveAtom)
|
||||
if (!drive) throw new Error("No drive selected")
|
||||
|
||||
const promises = files.map((pickedFile) =>
|
||||
uploadFile({
|
||||
account,
|
||||
drive,
|
||||
file: pickedFile.file,
|
||||
targetDirectory,
|
||||
onStart: () => {
|
||||
@@ -136,11 +136,11 @@ function useUploadFilesAtom({
|
||||
}
|
||||
|
||||
// Invalidate all queries for the target directory (with any params)
|
||||
const account = store.get(currentAccountAtom)
|
||||
if (account) {
|
||||
const drive = store.get(currentDriveAtom)
|
||||
if (drive) {
|
||||
client.invalidateQueries({
|
||||
queryKey: directoryContentQueryKey(
|
||||
account.id,
|
||||
drive.id,
|
||||
targetDirectory.id,
|
||||
),
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type } from "arktype"
|
||||
import type { Account } from "@/account/account"
|
||||
import { ApiError, fetchApi } from "@/lib/api"
|
||||
import type { Drive } from "@/drive/drive"
|
||||
import type { DirectoryInfoWithPath } from "@/vfs/vfs"
|
||||
|
||||
export const UploadStatus = type.enumerated("pending", "completed", "failed")
|
||||
@@ -14,13 +14,13 @@ export const Upload = type({
|
||||
export type Upload = typeof Upload.infer
|
||||
|
||||
export async function uploadFile({
|
||||
account,
|
||||
drive,
|
||||
file,
|
||||
targetDirectory,
|
||||
onStart,
|
||||
onProgress,
|
||||
}: {
|
||||
account: Account
|
||||
drive: Drive
|
||||
file: File
|
||||
targetDirectory: DirectoryInfoWithPath
|
||||
onStart: (xhr: XMLHttpRequest) => void
|
||||
@@ -28,7 +28,7 @@ export async function uploadFile({
|
||||
}) {
|
||||
const [, upload] = await fetchApi(
|
||||
"POST",
|
||||
`/accounts/${account.id}/uploads`,
|
||||
`/drives/${drive.id}/uploads`,
|
||||
{
|
||||
body: JSON.stringify({
|
||||
name: file.name,
|
||||
@@ -45,7 +45,7 @@ export async function uploadFile({
|
||||
onProgress,
|
||||
})
|
||||
|
||||
await fetchApi("PATCH", `/accounts/${account.id}/uploads/${upload.id}`, {
|
||||
await fetchApi("PATCH", `/drives/${drive.id}/uploads/${upload.id}`, {
|
||||
body: JSON.stringify({
|
||||
status: "completed",
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user