mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 20:51:16 +00:00
feat(fronend): wip org prefixed routing
This commit is contained in:
@@ -32,6 +32,7 @@ import { formatError } from "@/lib/error"
|
||||
import { directoryContentQueryKey } from "@/vfs/api"
|
||||
import type { DirectoryInfoWithPath } from "@/vfs/vfs"
|
||||
import { currentDriveAtom } from "@/drive/drive"
|
||||
import { useCurrentOrganization } from "@/organization/context"
|
||||
import {
|
||||
clearAllFileUploadStatusesAtom,
|
||||
clearFileUploadStatusesAtom,
|
||||
@@ -63,6 +64,7 @@ function useUploadFilesAtom({
|
||||
targetDirectory: DirectoryInfoWithPath
|
||||
}) {
|
||||
const store = useStore()
|
||||
const org = useCurrentOrganization()
|
||||
|
||||
const options = useMemo(
|
||||
() =>
|
||||
@@ -70,9 +72,11 @@ function useUploadFilesAtom({
|
||||
mutationFn: async (files: PickedFile[]) => {
|
||||
const drive = store.get(currentDriveAtom)
|
||||
if (!drive) throw new Error("No drive selected")
|
||||
const orgSlug = org.slug
|
||||
|
||||
const promises = files.map((pickedFile) =>
|
||||
uploadFile({
|
||||
orgSlug,
|
||||
drive,
|
||||
file: pickedFile.file,
|
||||
targetDirectory,
|
||||
@@ -140,6 +144,7 @@ function useUploadFilesAtom({
|
||||
if (drive) {
|
||||
client.invalidateQueries({
|
||||
queryKey: directoryContentQueryKey(
|
||||
org.slug,
|
||||
drive.id,
|
||||
targetDirectory.id,
|
||||
),
|
||||
@@ -151,7 +156,7 @@ function useUploadFilesAtom({
|
||||
toast.error(formatError(error))
|
||||
},
|
||||
}),
|
||||
[store, targetDirectory],
|
||||
[org.slug, store, targetDirectory],
|
||||
)
|
||||
|
||||
return useMemo(() => atomWithMutation(() => options), [options])
|
||||
|
||||
@@ -14,12 +14,14 @@ export const Upload = type({
|
||||
export type Upload = typeof Upload.infer
|
||||
|
||||
export async function uploadFile({
|
||||
orgSlug,
|
||||
drive,
|
||||
file,
|
||||
targetDirectory,
|
||||
onStart,
|
||||
onProgress,
|
||||
}: {
|
||||
orgSlug: string
|
||||
drive: Drive
|
||||
file: File
|
||||
targetDirectory: DirectoryInfoWithPath
|
||||
@@ -28,7 +30,7 @@ export async function uploadFile({
|
||||
}) {
|
||||
const [, upload] = await fetchApi(
|
||||
"POST",
|
||||
`/drives/${drive.id}/uploads`,
|
||||
`/${orgSlug}/drives/${drive.id}/uploads`,
|
||||
{
|
||||
body: JSON.stringify({
|
||||
name: file.name,
|
||||
@@ -45,12 +47,16 @@ export async function uploadFile({
|
||||
onProgress,
|
||||
})
|
||||
|
||||
await fetchApi("PATCH", `/drives/${drive.id}/uploads/${upload.id}`, {
|
||||
body: JSON.stringify({
|
||||
status: "completed",
|
||||
}),
|
||||
returns: Upload,
|
||||
})
|
||||
await fetchApi(
|
||||
"PATCH",
|
||||
`/${orgSlug}/drives/${drive.id}/uploads/${upload.id}`,
|
||||
{
|
||||
body: JSON.stringify({
|
||||
status: "completed",
|
||||
}),
|
||||
returns: Upload,
|
||||
},
|
||||
)
|
||||
|
||||
return upload
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user