mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
feat(web): add oRPC contracts and service hooks for app asset API
- Add TypeScript types for app asset management (types/app-asset.ts) - Add oRPC contract definitions with nested router pattern (contract/console/app-asset.ts) - Add React Query hooks for all asset operations (service/use-app-asset.ts) - Integrate app asset contracts into console router Endpoints covered: tree, createFolder, createFile, getFileContent, updateFileContent, deleteNode, renameNode, moveNode, reorderNode, publish
This commit is contained in:
119
web/contract/console/app-asset.ts
Normal file
119
web/contract/console/app-asset.ts
Normal file
@ -0,0 +1,119 @@
|
||||
import type {
|
||||
AppAssetDeleteResponse,
|
||||
AppAssetFileContentResponse,
|
||||
AppAssetNode,
|
||||
AppAssetPublishResponse,
|
||||
AppAssetTreeResponse,
|
||||
CreateFolderPayload,
|
||||
MoveNodePayload,
|
||||
RenameNodePayload,
|
||||
ReorderNodePayload,
|
||||
UpdateFileContentPayload,
|
||||
} from '@/types/app-asset'
|
||||
import { type } from '@orpc/contract'
|
||||
import { base } from '../base'
|
||||
|
||||
export const treeContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/tree',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string }
|
||||
}>())
|
||||
.output(type<AppAssetTreeResponse>())
|
||||
|
||||
export const createFolderContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/folders',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string }
|
||||
body: CreateFolderPayload
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const createFileContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/files',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string }
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const getFileContentContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/files/{nodeId}',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
}>())
|
||||
.output(type<AppAssetFileContentResponse>())
|
||||
|
||||
export const updateFileContentContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/files/{nodeId}',
|
||||
method: 'PUT',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
body: UpdateFileContentPayload
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const deleteNodeContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/nodes/{nodeId}',
|
||||
method: 'DELETE',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
}>())
|
||||
.output(type<AppAssetDeleteResponse>())
|
||||
|
||||
export const renameNodeContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/nodes/{nodeId}/rename',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
body: RenameNodePayload
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const moveNodeContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/nodes/{nodeId}/move',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
body: MoveNodePayload
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const reorderNodeContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/nodes/{nodeId}/reorder',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string, nodeId: string }
|
||||
body: ReorderNodePayload
|
||||
}>())
|
||||
.output(type<AppAssetNode>())
|
||||
|
||||
export const publishContract = base
|
||||
.route({
|
||||
path: '/apps/{appId}/assets/publish',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: { appId: string }
|
||||
}>())
|
||||
.output(type<AppAssetPublishResponse>())
|
||||
@ -4,6 +4,18 @@ import {
|
||||
bindPartnerStackContract,
|
||||
systemFeaturesContract,
|
||||
} from './console'
|
||||
import {
|
||||
createFileContract,
|
||||
createFolderContract,
|
||||
deleteNodeContract,
|
||||
getFileContentContract,
|
||||
moveNodeContract,
|
||||
publishContract,
|
||||
renameNodeContract,
|
||||
reorderNodeContract,
|
||||
treeContract,
|
||||
updateFileContentContract,
|
||||
} from './console/app-asset'
|
||||
import {
|
||||
activateSandboxProviderContract,
|
||||
deleteSandboxProviderConfigContract,
|
||||
@ -32,6 +44,18 @@ export const consoleRouterContract = {
|
||||
deleteSandboxProviderConfig: deleteSandboxProviderConfigContract,
|
||||
activateSandboxProvider: activateSandboxProviderContract,
|
||||
getActiveSandboxProvider: getActiveSandboxProviderContract,
|
||||
appAsset: {
|
||||
tree: treeContract,
|
||||
createFolder: createFolderContract,
|
||||
createFile: createFileContract,
|
||||
getFileContent: getFileContentContract,
|
||||
updateFileContent: updateFileContentContract,
|
||||
deleteNode: deleteNodeContract,
|
||||
renameNode: renameNodeContract,
|
||||
moveNode: moveNodeContract,
|
||||
reorderNode: reorderNodeContract,
|
||||
publish: publishContract,
|
||||
},
|
||||
}
|
||||
|
||||
export type ConsoleInputs = InferContractRouterInputs<typeof consoleRouterContract>
|
||||
|
||||
Reference in New Issue
Block a user