Add server file manager workflow

This commit is contained in:
npc0-hue
2026-08-24 12:56:55 +08:00
parent dc9b0eaf2a
commit 33d3a13e74
20 changed files with 1961 additions and 22 deletions
+171
View File
@@ -730,6 +730,110 @@ type DeclaredFileReadSnapshotResponse struct {
Reason string `json:"reason,omitempty"`
}
type ServerFileTransferPolicyResponse struct {
Channel string `json:"channel"`
UploadChunkSizeBytes int `json:"uploadChunkSizeBytes"`
DownloadChunkSizeBytes int `json:"downloadChunkSizeBytes"`
MaxInlineEditBytes int `json:"maxInlineEditBytes"`
MaxBrowserUploadBytes int64 `json:"maxBrowserUploadBytes"`
Notes []string `json:"notes,omitempty"`
}
type ServerFileWorkspaceResponse struct {
ServerInstanceID string `json:"serverInstanceId"`
PluginID string `json:"pluginId"`
DefaultDirectoryKey string `json:"defaultDirectoryKey"`
Directories []PluginLogicalDirectoryBody `json:"directories"`
Files []PluginLogicalFileBody `json:"files"`
ConfigFields []PluginConfigFieldBody `json:"configFields"`
Transfer ServerFileTransferPolicyResponse `json:"transfer"`
DeclaredOnly bool `json:"declaredOnly"`
RuntimeWorkspaceScope string `json:"runtimeWorkspaceScope,omitempty"`
}
type ServerFileEntryResponse struct {
Name string `json:"name"`
Kind domain.ServerFileEntryKind `json:"kind"`
DirectoryKey string `json:"directoryKey"`
RelativePath string `json:"relativePath,omitempty"`
LogicalKey string `json:"logicalKey,omitempty"`
Scope string `json:"scope,omitempty"`
SizeBytes int64 `json:"sizeBytes,omitempty"`
ModifiedAt time.Time `json:"modifiedAt,omitempty"`
Checksum string `json:"checksum,omitempty"`
Editable bool `json:"editable"`
Downloadable bool `json:"downloadable"`
Remark string `json:"remark,omitempty"`
}
type ServerFileListRequest struct {
DirectoryKey string `json:"directoryKey"`
Path string `json:"path,omitempty"`
Query string `json:"query,omitempty"`
Recursive bool `json:"recursive,omitempty"`
IdempotencyKey string `json:"idempotencyKey,omitempty"`
}
type ServerFileListResponse struct {
ServerInstanceID string `json:"serverInstanceId"`
PluginID string `json:"pluginId"`
DirectoryKey string `json:"directoryKey"`
Path string `json:"path,omitempty"`
State string `json:"state"`
Entries []ServerFileEntryResponse `json:"entries"`
Job *JobResponse `json:"job,omitempty"`
RefreshedAt time.Time `json:"refreshedAt,omitempty"`
Reason string `json:"reason,omitempty"`
}
type ServerFileReadRequest struct {
PluginID string `json:"pluginId,omitempty"`
Key string `json:"key"`
IdempotencyKey string `json:"idempotencyKey"`
}
type ServerFileWriteRequest struct {
PluginID string `json:"pluginId,omitempty"`
Key string `json:"key"`
Content string `json:"content,omitempty"`
InputRef string `json:"inputRef,omitempty"`
ExpectedVersion int `json:"expectedVersion,omitempty"`
ExpectedChecksum string `json:"expectedChecksum,omitempty"`
IdempotencyKey string `json:"idempotencyKey"`
}
type ServerFileUploadResponse struct {
Status string `json:"status"`
ServerInstanceID string `json:"serverInstanceId"`
DirectoryKey string `json:"directoryKey"`
RelativePath string `json:"relativePath"`
ArtifactID string `json:"artifactId"`
InputRef string `json:"inputRef"`
SizeBytes int64 `json:"sizeBytes"`
Checksum string `json:"checksum"`
Job JobResponse `json:"job"`
}
type ServerFileDownloadRequest struct {
Key string `json:"key"`
IdempotencyKey string `json:"idempotencyKey"`
}
type ServerFileDownloadResponse struct {
Status string `json:"status"`
ServerInstanceID string `json:"serverInstanceId"`
Key string `json:"key"`
Filename string `json:"filename"`
ContentType string `json:"contentType,omitempty"`
Content string `json:"content,omitempty"`
Checksum string `json:"checksum,omitempty"`
SizeBytes int64 `json:"sizeBytes,omitempty"`
Artifact *ArtifactDownloadReferenceResponse `json:"artifact,omitempty"`
Job *JobResponse `json:"job,omitempty"`
ReadAt time.Time `json:"readAt,omitempty"`
Reason string `json:"reason,omitempty"`
}
type RunCapacityResponse struct {
MaxJobs int `json:"maxJobs"`
RunningJobs int `json:"runningJobs"`
@@ -1295,6 +1399,22 @@ func (request FileOperationDispatchRequest) ToDomain() domain.FileOperationDispa
}
}
func (request ServerFileListRequest) ToDomain(serverInstanceID string) domain.ServerFileListRequest {
return domain.ServerFileListRequest{ServerInstanceID: serverInstanceID, DirectoryKey: request.DirectoryKey, Path: request.Path, Query: request.Query, Recursive: request.Recursive, IdempotencyKey: request.IdempotencyKey}
}
func (request ServerFileReadRequest) ToDomain(serverInstanceID string) domain.ServerFileReadRequest {
return domain.ServerFileReadRequest{ServerInstanceID: serverInstanceID, PluginID: request.PluginID, Key: request.Key, IdempotencyKey: request.IdempotencyKey}
}
func (request ServerFileWriteRequest) ToDomain(serverInstanceID string) domain.ServerFileWriteRequest {
return domain.ServerFileWriteRequest{ServerInstanceID: serverInstanceID, PluginID: request.PluginID, Key: request.Key, Content: request.Content, InputRef: request.InputRef, ExpectedVersion: request.ExpectedVersion, ExpectedChecksum: request.ExpectedChecksum, IdempotencyKey: request.IdempotencyKey}
}
func (request ServerFileDownloadRequest) ToDomain(serverInstanceID string) domain.ServerFileDownloadRequest {
return domain.ServerFileDownloadRequest{ServerInstanceID: serverInstanceID, Key: request.Key, IdempotencyKey: request.IdempotencyKey}
}
func (request RunEndpointCreateRequest) ToDomain() domain.RunEndpoint {
return domain.RunEndpoint{
ID: request.ID,
@@ -1827,6 +1947,57 @@ func DeclaredFileReadSnapshotFromDomain(snapshot domain.DeclaredFileReadSnapshot
}
}
func ServerFileWorkspaceFromDomain(view domain.ServerFileWorkspaceView) ServerFileWorkspaceResponse {
view = domain.CopyServerFileWorkspaceView(view)
workspace := domain.PluginFileWorkspace{DefaultDirectoryKey: view.DefaultDirectoryKey, Directories: view.Directories, Files: view.Files, ConfigFields: view.ConfigFields}
body := fileWorkspaceFromDomain(workspace)
return ServerFileWorkspaceResponse{ServerInstanceID: view.ServerInstanceID, PluginID: view.PluginID, DefaultDirectoryKey: view.DefaultDirectoryKey, Directories: body.Directories, Files: body.Files, ConfigFields: body.ConfigFields, Transfer: ServerFileTransferPolicyFromDomain(view.Transfer), DeclaredOnly: view.DeclaredOnly, RuntimeWorkspaceScope: view.RuntimeWorkspaceScope}
}
func ServerFileTransferPolicyFromDomain(policy domain.ServerFileTransferPolicy) ServerFileTransferPolicyResponse {
policy = domain.CopyServerFileTransferPolicy(policy)
return ServerFileTransferPolicyResponse{Channel: policy.Channel, UploadChunkSizeBytes: policy.UploadChunkSizeBytes, DownloadChunkSizeBytes: policy.DownloadChunkSizeBytes, MaxInlineEditBytes: policy.MaxInlineEditBytes, MaxBrowserUploadBytes: policy.MaxBrowserUploadBytes, Notes: policy.Notes}
}
func ServerFileListFromDomain(result domain.ServerFileListResult) ServerFileListResponse {
result = domain.CopyServerFileListResult(result)
items := make([]ServerFileEntryResponse, len(result.Entries))
for index, entry := range result.Entries {
items[index] = ServerFileEntryFromDomain(entry)
}
var job *JobResponse
if result.Job.ID != "" {
body := JobFromDomain(result.Job)
job = &body
}
return ServerFileListResponse{ServerInstanceID: result.ServerInstanceID, PluginID: result.PluginID, DirectoryKey: result.DirectoryKey, Path: result.Path, State: result.State, Entries: items, Job: job, RefreshedAt: result.RefreshedAt, Reason: result.Reason}
}
func ServerFileEntryFromDomain(entry domain.ServerFileEntry) ServerFileEntryResponse {
entry = domain.CopyServerFileEntry(entry)
return ServerFileEntryResponse{Name: entry.Name, Kind: entry.Kind, DirectoryKey: entry.DirectoryKey, RelativePath: entry.RelativePath, LogicalKey: entry.LogicalKey, Scope: entry.Scope, SizeBytes: entry.SizeBytes, ModifiedAt: entry.ModifiedAt, Checksum: entry.Checksum, Editable: entry.Editable, Downloadable: entry.Downloadable, Remark: entry.Remark}
}
func ServerFileUploadFromDomain(dispatch domain.ServerFileUploadDispatch) ServerFileUploadResponse {
dispatch = domain.CopyServerFileUploadDispatch(dispatch)
return ServerFileUploadResponse{Status: dispatch.Status, ServerInstanceID: dispatch.ServerInstanceID, DirectoryKey: dispatch.DirectoryKey, RelativePath: dispatch.RelativePath, ArtifactID: dispatch.ArtifactID, InputRef: dispatch.InputRef, SizeBytes: dispatch.SizeBytes, Checksum: dispatch.Checksum, Job: JobFromDomain(dispatch.Job)}
}
func ServerFileDownloadFromDomain(result domain.ServerFileDownloadResult) ServerFileDownloadResponse {
result = domain.CopyServerFileDownloadResult(result)
var artifact *ArtifactDownloadReferenceResponse
if result.Artifact != nil {
body := ArtifactDownloadReferenceFromDomain(*result.Artifact)
artifact = &body
}
var job *JobResponse
if result.Job.ID != "" {
body := JobFromDomain(result.Job)
job = &body
}
return ServerFileDownloadResponse{Status: result.Status, ServerInstanceID: result.ServerInstanceID, Key: result.Key, Filename: result.Filename, ContentType: result.ContentType, Content: result.Content, Checksum: result.Checksum, SizeBytes: result.SizeBytes, Artifact: artifact, Job: job, ReadAt: result.ReadAt, Reason: result.Reason}
}
func RunEndpointFromDomain(endpoint domain.RunEndpoint) RunEndpointResponse {
endpoint = domain.CopyRunEndpoint(endpoint)
return RunEndpointResponse{