Add server file manager workflow
This commit is contained in:
@@ -32,6 +32,7 @@ import type {
|
||||
CurrentUserResponse,
|
||||
DependencyCatalogResponse,
|
||||
DependencyJobRequest,
|
||||
DeclaredFileReadSnapshotResponse,
|
||||
FileOperationDispatchRequest,
|
||||
FileOperationDispatchResponse,
|
||||
GameClientBridgeCancelRequest,
|
||||
@@ -84,6 +85,14 @@ import type {
|
||||
ServerDeploymentResponse,
|
||||
ServerInstanceListResponse,
|
||||
ServerDeletionRequest,
|
||||
ServerFileDownloadRequest,
|
||||
ServerFileDownloadResponse,
|
||||
ServerFileListRequest,
|
||||
ServerFileListResponse,
|
||||
ServerFileReadRequest,
|
||||
ServerFileUploadResponse,
|
||||
ServerFileWorkspaceResponse,
|
||||
ServerFileWriteRequest,
|
||||
ServerInstanceUpdateRequest,
|
||||
ServerInstanceResponse,
|
||||
ServerMemberListResponse,
|
||||
@@ -575,6 +584,51 @@ export class PlatformApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
async getServerFileWorkspace(serverInstanceId: string): Promise<ServerFileWorkspaceResponse> {
|
||||
return this.request<ServerFileWorkspaceResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/workspace`);
|
||||
}
|
||||
|
||||
async listServerFiles(serverInstanceId: string, request: Partial<ServerFileListRequest> = {}): Promise<ServerFileListResponse> {
|
||||
const params = serverFileListQuery(request);
|
||||
return this.request<ServerFileListResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/list${params}`);
|
||||
}
|
||||
|
||||
async refreshServerFiles(serverInstanceId: string, request: ServerFileListRequest): Promise<ServerFileListResponse> {
|
||||
return this.request<ServerFileListResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/refresh`, { method: "POST", body: request });
|
||||
}
|
||||
|
||||
async readServerFile(serverInstanceId: string, request: ServerFileReadRequest): Promise<FileOperationDispatchResponse> {
|
||||
return this.request<FileOperationDispatchResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/read`, { method: "POST", body: request });
|
||||
}
|
||||
|
||||
async getServerFileReadSnapshot(serverInstanceId: string, key: string): Promise<DeclaredFileReadSnapshotResponse> {
|
||||
const params = new URLSearchParams({ key });
|
||||
return this.request<DeclaredFileReadSnapshotResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/read-snapshot?${params.toString()}`);
|
||||
}
|
||||
|
||||
async writeServerFile(serverInstanceId: string, request: ServerFileWriteRequest): Promise<FileOperationDispatchResponse> {
|
||||
return this.request<FileOperationDispatchResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/write`, { method: "POST", body: request });
|
||||
}
|
||||
|
||||
async uploadServerFile(serverInstanceId: string, request: { directoryKey: string; relativePath?: string; file: File; idempotencyKey: string }): Promise<ServerFileUploadResponse> {
|
||||
const body = new FormData();
|
||||
body.set("directoryKey", request.directoryKey);
|
||||
body.set("relativePath", request.relativePath ?? "");
|
||||
body.set("filename", request.file.name);
|
||||
body.set("idempotencyKey", request.idempotencyKey);
|
||||
body.set("file", request.file);
|
||||
const headers = new Headers();
|
||||
const sessionToken = this.sessionTokenProvider();
|
||||
if (sessionToken) headers.set("Authorization", `Bearer ${sessionToken}`);
|
||||
const response = await fetch(`${this.baseUrl}/server-instances/${encodeURIComponent(serverInstanceId)}/files/upload`, { method: "POST", credentials: "same-origin", headers, body });
|
||||
if (!response.ok) throw await responseError(response);
|
||||
return response.json() as Promise<ServerFileUploadResponse>;
|
||||
}
|
||||
|
||||
async prepareServerFileDownload(serverInstanceId: string, request: ServerFileDownloadRequest): Promise<ServerFileDownloadResponse> {
|
||||
return this.request<ServerFileDownloadResponse>(`/server-instances/${encodeURIComponent(serverInstanceId)}/files/download`, { method: "POST", body: request });
|
||||
}
|
||||
|
||||
async listLogStreams(serverInstanceId?: string): Promise<LogStreamListResponse> {
|
||||
const query = serverInstanceId ? `?serverInstanceId=${encodeURIComponent(serverInstanceId)}` : "";
|
||||
return this.request<LogStreamListResponse>(`/log-streams${query}`);
|
||||
@@ -900,4 +954,14 @@ function artifactQuery(filter: ArtifactFilterRequest): string {
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
function serverFileListQuery(request: Partial<ServerFileListRequest>): string {
|
||||
const params = new URLSearchParams();
|
||||
if (request.directoryKey) params.set("directoryKey", request.directoryKey);
|
||||
if (request.path) params.set("path", request.path);
|
||||
if (request.query) params.set("query", request.query);
|
||||
if (request.recursive) params.set("recursive", "true");
|
||||
const query = params.toString();
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
export const platformApiClient = new PlatformApiClient(readWebRuntimeEnv().platformApiBaseUrl);
|
||||
|
||||
Reference in New Issue
Block a user