refactor(authz): move to domain-based authz and flatten routes

This commit is contained in:
yiling
2026-05-25 23:51:37 +08:00
parent 35fd5c78ce
commit 9f9549255d
61 changed files with 1646 additions and 1147 deletions
@@ -16,13 +16,11 @@ const projectInfoQueryOptions = (projectId: string) => ({
},
})
const collectionInfoQueryOptions = (teamId: string, projectId: string, collectionId: string) => ({
queryKey: ['collections', teamId, projectId, collectionId],
const collectionInfoQueryOptions = (collectionId: string) => ({
queryKey: ['collections', collectionId],
queryFn: async () => {
const res = await client.api.teams[':teamId'].projects[':projectId'].collections[
':collectionId'
].$get({
param: { teamId, projectId, collectionId },
const res = await client.api.collections[':collectionId'].$get({
param: { collectionId },
})
if (!res.ok) throw new Error('Failed to fetch collection')
return await res.json()
@@ -40,17 +38,14 @@ function CollectionPage() {
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
const { data: collection, refetch: refetchCollection } = useQuery({
...collectionInfoQueryOptions(teamId || '', projectId, collectionId),
enabled: !!teamId,
...collectionInfoQueryOptions(collectionId),
})
const { mutate: updateCollection } = useMutation({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mutationFn: async (updates: { name?: string; filter?: any }) => {
const res = await client.api.teams[':teamId'].projects[':projectId'].collections[
':collectionId'
].$patch({
param: { teamId: teamId!, projectId, collectionId },
const res = await client.api.collections[':collectionId'].$patch({
param: { collectionId },
json: updates,
})
if (!res.ok) throw new Error('Failed to update collection')
@@ -64,15 +59,15 @@ function CollectionPage() {
const rootFolderId = projectInfo?.rootFolder
const { data: rootFolder } = useQuery({
queryKey: ['folders', teamId!, rootFolderId!],
queryKey: ['folders', rootFolderId!],
queryFn: async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId!, folderId: rootFolderId! },
const res = await client.api.folders[':folderId'].$get({
param: { folderId: rootFolderId! },
})
if (!res.ok) throw new Error('Failed to fetch folder')
return await res.json()
},
enabled: !!teamId && !!rootFolderId,
enabled: !!rootFolderId,
})
if (!teamId || !rootFolderId || !rootFolder || !collection) {
@@ -34,7 +34,7 @@ function FileViewPage() {
const [leftSidebarWidth, setLeftSidebarWidth] = useState(280)
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
const [annotations, setAnnotations] = useState<Annotation[]>([])
const $patchMetadata = client.api.teams[':teamId'].files[':fileId'].metadata.$patch
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
const { mutate: patchMetadata } = useMutation<
InferResponseType<typeof $patchMetadata>,
Error,
@@ -65,10 +65,10 @@ function FileViewPage() {
isError: isStackError,
isFetching: isStackFetching,
} = useQuery({
queryKey: ['teams', teamId, 'files', fileId],
queryKey: ['files', fileId],
queryFn: async () => {
const res = await client.api.teams[':teamId'].files[':fileId'].$get({
param: { teamId: teamId!, fileId: fileId },
const res = await client.api.files[':fileId'].$get({
param: { fileId: fileId },
})
if (!res.ok) throw new Error('Failed to fetch stack')
return await res.json()
@@ -83,10 +83,10 @@ function FileViewPage() {
isError: isVersionError,
isFetching: isVersionFetching,
} = useQuery({
queryKey: ['teams', teamId, 'files', versionAssetId],
queryKey: ['files', versionAssetId],
queryFn: async () => {
const res = await client.api.teams[':teamId'].files[':fileId'].$get({
param: { teamId: teamId!, fileId: versionAssetId! },
const res = await client.api.files[':fileId'].$get({
param: { fileId: versionAssetId! },
})
if (!res.ok) throw new Error('Failed to fetch version')
return await res.json()
@@ -96,10 +96,10 @@ function FileViewPage() {
})
const { data: versionsList } = useQuery({
queryKey: ['projects', projectId, 'version_stacks', fileId, 'versions'],
queryKey: ['version_stacks', fileId, 'versions'],
queryFn: async () => {
const res = await client.api.projects[':projectId'].version_stacks[':stackId'].versions.$get({
param: { projectId: projectId, stackId: fileId },
const res = await client.api.version_stacks[':stackId'].versions.$get({
param: { stackId: fileId },
})
if (!res.ok) throw new Error('Failed to fetch versions')
return await res.json()
@@ -180,13 +180,13 @@ function FileViewPage() {
if (!teamId) return
patchMetadata(
{
param: { teamId: teamId, fileId: activeFileId },
param: { fileId: activeFileId },
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
},
{
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['teams', teamId, 'files', activeFileId],
queryKey: ['files', activeFileId],
})
},
},
@@ -216,7 +216,6 @@ function FileViewPage() {
<>
<div style={{ width: leftSidebarWidth }} className="flex-shrink-0">
<FileViewerLeftSidebar
teamId={teamId!}
projectId={projectId}
currentAssetId={activeFileId}
parentFolderId={
@@ -29,15 +29,15 @@ function FolderPage() {
const rootFolderId = projectInfo?.rootFolder
const { data: rootFolder } = useQuery({
queryKey: ['folders', teamId!, rootFolderId!],
queryKey: ['folders', rootFolderId!],
queryFn: () =>
(async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId!, folderId: rootFolderId! },
const res = await client.api.folders[':folderId'].$get({
param: { folderId: rootFolderId! },
})
return await res.json()
})(),
enabled: !!teamId && !!rootFolderId,
enabled: !!rootFolderId,
})
if (!teamId || !rootFolderId || !rootFolder) {
+4 -4
View File
@@ -29,15 +29,15 @@ function ProjectPage() {
const rootFolderId = projectInfo?.rootFolder
const { data: rootFolder } = useQuery({
queryKey: ['folders', teamId!, rootFolderId!],
queryKey: ['folders', rootFolderId!],
queryFn: async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId!, folderId: rootFolderId! },
const res = await client.api.folders[':folderId'].$get({
param: { folderId: rootFolderId! },
})
if (!res.ok) throw new Error('failed to fetch folder')
return await res.json()
},
enabled: !!teamId && !!rootFolderId,
enabled: !!rootFolderId,
})
if (!teamId || !rootFolderId || !rootFolder) {
@@ -29,15 +29,15 @@ function RecentlyDeletedPage() {
const rootFolderId = projectInfo?.rootFolder
const { data: rootFolder } = useQuery({
queryKey: ['folders', teamId!, rootFolderId!],
queryKey: ['folders', rootFolderId!],
queryFn: () =>
(async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId!, folderId: rootFolderId! },
const res = await client.api.folders[':folderId'].$get({
param: { folderId: rootFolderId! },
})
return await res.json()
})(),
enabled: !!teamId && !!rootFolderId,
enabled: !!rootFolderId,
})
if (!teamId || !rootFolderId || !rootFolder) {
@@ -29,15 +29,15 @@ function SharePage() {
const rootFolderId = projectInfo?.rootFolder
const { data: rootFolder } = useQuery({
queryKey: ['folders', teamId!, rootFolderId!],
queryKey: ['folders', rootFolderId!],
queryFn: async () => {
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
param: { teamId: teamId!, folderId: rootFolderId! },
const res = await client.api.folders[':folderId'].$get({
param: { folderId: rootFolderId! },
})
if (!res.ok) throw new Error('Failed to fetch folder')
return await res.json()
},
enabled: !!teamId && !!rootFolderId,
enabled: !!rootFolderId,
})
if (!teamId || !rootFolderId || !rootFolder) {