Skip to content

Commit 1191019

Browse files
Scott DoverScott Dover
authored andcommitted
feat: add ability to create files and folders
Signed-off-by: Scott Dover <[email protected]>
1 parent ce3c564 commit 1191019

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

client/src/connection/rest/RestSASServerAdapter.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,51 @@ class RestSASServerAdapter implements ContentAdapter {
8080
parentItem: ContentItem,
8181
folderName: string,
8282
): Promise<ContentItem | undefined> {
83-
throw new Error("cnf Method not implemented.");
83+
const response = await this.fileSystemApi.createFileOrDirectory({
84+
sessionId: this.sessionId,
85+
fileOrDirectoryPath: parentItem.uri.replace(
86+
`/compute/sessions/${this.sessionId}/files/`,
87+
"",
88+
),
89+
fileProperties: { name: folderName, isDirectory: true },
90+
});
91+
92+
return this.enrichWithDataProviderProperties(
93+
this.filePropertiesToContentItem(response.data),
94+
);
8495
}
8596

8697
public async createNewItem(
8798
parentItem: ContentItem,
8899
fileName: string,
89100
buffer?: ArrayBufferLike,
90101
): Promise<ContentItem | undefined> {
91-
throw new Error("cni Method not implemented.");
102+
const response = await this.fileSystemApi.createFileOrDirectory({
103+
sessionId: this.sessionId,
104+
fileOrDirectoryPath: parentItem.uri.replace(
105+
`/compute/sessions/${this.sessionId}/files/`,
106+
"",
107+
),
108+
fileProperties: { name: fileName, isDirectory: false },
109+
});
110+
111+
if (buffer) {
112+
const etag = response.headers.etag;
113+
const filePath = getLink(response.data.links, "GET", "self").uri.replace(
114+
`/compute/sessions/${this.sessionId}/files/`,
115+
"",
116+
);
117+
await this.fileSystemApi.updateFileContentOnSystem({
118+
sessionId: this.sessionId,
119+
filePath,
120+
body: new File([buffer], response.data.name),
121+
ifMatch: etag,
122+
});
123+
}
124+
125+
return this.enrichWithDataProviderProperties(
126+
this.filePropertiesToContentItem(response.data),
127+
);
92128
}
93129

94130
public async deleteItem(item: ContentItem): Promise<boolean> {

client/src/connection/rest/util.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright © 2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { Uri } from "vscode";
3+
import { FileType, Uri } from "vscode";
44

55
import {
66
DATAFLOW_TYPE,
@@ -55,6 +55,7 @@ export const resourceType = (item: ContentItem): string | undefined => {
5555
if (!isValidItem(item)) {
5656
return;
5757
}
58+
5859
const { write, delete: del, addMember } = getPermission(item);
5960
const isRecycled = isItemInRecycleBin(item);
6061
const actions = [
@@ -110,11 +111,15 @@ export const getSasServerUri = (item: ContentItem, readOnly?: boolean): Uri =>
110111

111112
export const getPermission = (item: ContentItem): Permission => {
112113
const itemType = getTypeName(item);
113-
return [FOLDER_TYPE, ...FILE_TYPES].includes(itemType) // normal folders and files
114+
return [FOLDER_TYPE, ...FILE_TYPES].includes(itemType) ||
115+
item.fileStat?.type === FileType.Directory
114116
? {
115117
write: !!getLink(item.links, "PUT", "update"),
116118
delete: !!getLink(item.links, "DELETE", "deleteResource"),
117-
addMember: !!getLink(item.links, "POST", "createChild"),
119+
addMember:
120+
!!getLink(item.links, "POST", "createChild") ||
121+
!!getLink(item.links, "POST", "makeDirectory") ||
122+
!!getLink(item.links, "POST", "createFile"),
118123
}
119124
: {
120125
// delegate folders, user folder and user root folder

0 commit comments

Comments
 (0)