Skip to content

Commit

Permalink
implement file download
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Dover authored and Scott Dover committed Oct 4, 2023
1 parent 9e3ffa0 commit 94f9724
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class ContentDataProvider
errorMessage: string,
): Promise<void> {
if (!newUri) {
window.showErrorMessage(errorMessage);
await window.showErrorMessage(errorMessage);
return;
}

Expand Down
2 changes: 0 additions & 2 deletions client/src/components/ContentNavigator/ContentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export class ContentModel {
}

const fileLink: Link | null = getLink(createdResource.links, "GET", "self");

const memberAdded = await this.addMember(
fileLink?.uri,
getLink(item.links, "POST", "addMember")?.uri,
Expand All @@ -240,7 +239,6 @@ export class ContentModel {
contentType,
},
);

if (!memberAdded) {
return;
}
Expand Down
44 changes: 23 additions & 21 deletions client/src/components/ContentNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ import {
workspace,
} from "vscode";

import { createWriteStream } from "fs";

import { profileConfig } from "../../commands/profile";
import { SubscriptionProvider } from "../SubscriptionProvider";
import { ConnectionType } from "../profile";
import ContentDataProvider from "./ContentDataProvider";
import { ContentModel } from "./ContentModel";
import { Messages } from "./const";
import { ContentItem } from "./types";
import { isContainer as getIsContainer, isItemInRecycleBin } from "./utils";
import {
isContainer as getIsContainer,
getUri,
isItemInRecycleBin,
} from "./utils";

const fileValidator = (value: string): string | null =>
/^([^/<>;\\{}?#]+)\.\w+$/.test(
Expand Down Expand Up @@ -273,31 +279,27 @@ class ContentNavigator implements SubscriptionProvider {
),
commands.registerCommand(
"SAS.downloadResource",
async (item: ContentItem) => {
const uri = await window.showSaveDialog({});
async (resource: ContentItem) => {
const uri = await window.showSaveDialog({
defaultUri: Uri.file(resource.name),
});
if (!uri) {
return;
}

this.treeViewSelections(item).forEach(
async (resource: ContentItem) => {
console.log("resource", resource);
console.log("uri", uri);
await window.withProgress(
{
location: ProgressLocation.Notification,
title: l10n.t("Downloading file..."),
},
async () => {
const stream = createWriteStream(uri.fsPath);
stream.write(
await this.contentDataProvider.readFile(getUri(resource)),
);
stream.end();
},
);
// const uri = await window.showSaveDialog({
// defaultUri: Uri.file(
// `${item.library}.${item.name}.csv`.toLocaleLowerCase(),
// ),
// });
// if (!uri) {
// return;
// }
// const stream = createWriteStream(uri.fsPath);
// await this.libraryDataProvider.writeTableContentsToStream(
// stream,
// item,
// );
},
),
commands.registerCommand(
Expand All @@ -318,7 +320,7 @@ class ContentNavigator implements SubscriptionProvider {
title: l10n.t("Uploading files..."),
},
async () => {
this.contentDataProvider.uploadUrisToTarget(uris, resource);
await this.contentDataProvider.uploadUrisToTarget(uris, resource);
},
);
},
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/ContentNavigator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const resourceType = (item: ContentItem): string | undefined => {
actions.push("convertNotebookToFlow");
}

if (!isContainer(item)) {
actions.push("allowDownload");
}

if (actions.length === 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@
},
{
"command": "SAS.downloadResource",
"when": "(viewItem =~ /update/ || viewItem =~ /createChild/) && view == contentdataprovider",
"when": "viewItem =~ /update/ && viewItem =~ /allowDownload/ && view == contentdataprovider",
"group": "uploaddownloadgroup@0"
},
{
Expand Down

0 comments on commit 94f9724

Please sign in to comment.