Skip to content

Commit bce30a4

Browse files
committed
add command for external drives
1 parent 4bab58b commit bce30a4

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

src/contents.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
createDrive,
2525
getDrivesList,
2626
excludeDrive,
27-
includeDrive
27+
includeDrive,
28+
addExternalDrive
2829
} from './requests';
2930

3031
export class Drive implements Contents.IDrive {
@@ -850,6 +851,42 @@ export class Drive implements Contents.IDrive {
850851
return data;
851852
}
852853

854+
/**
855+
* Add external drive.
856+
*
857+
* @param options: The options used to add the external drive.
858+
*
859+
* @returns A promise which resolves with the contents model.
860+
*/
861+
async addExternalDrive(
862+
driveUrl: string,
863+
location: string
864+
): Promise<Contents.IModel> {
865+
await addExternalDrive(driveUrl, location);
866+
867+
const data: Contents.IModel = {
868+
name: driveUrl,
869+
path: driveUrl,
870+
last_modified: '',
871+
created: '',
872+
content: [],
873+
format: 'json',
874+
mimetype: '',
875+
size: 0,
876+
writable: true,
877+
type: 'directory'
878+
};
879+
880+
Contents.validateContentsModel(data);
881+
this._fileChanged.emit({
882+
type: 'new',
883+
oldValue: null,
884+
newValue: data
885+
});
886+
887+
return data;
888+
}
889+
853890
/**
854891
* Exclude drive from browser.
855892
*

src/plugins/driveBrowserPlugin.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,38 @@ namespace Private {
454454
rank: 110
455455
});
456456

457+
app.commands.addCommand(CommandIDs.addExternalDrive, {
458+
isVisible: () => {
459+
return browser.model.path === 's3:';
460+
},
461+
execute: async () => {
462+
return showDialog({
463+
title: 'Add External Drive',
464+
body: new Private.CreateDriveHandler(drive.name),
465+
focusNodeSelector: 'input',
466+
buttons: [
467+
Dialog.cancelButton(),
468+
Dialog.okButton({
469+
label: 'Add',
470+
ariaLabel: 'Add Drive'
471+
})
472+
]
473+
}).then(result => {
474+
if (result.value) {
475+
drive.addExternalDrive(result.value[0], result.value[1]);
476+
}
477+
});
478+
},
479+
label: 'Add External Drive',
480+
icon: driveBrowserIcon.bindprops({ stylesheet: 'menuItem' })
481+
});
482+
483+
app.contextMenu.addItem({
484+
command: CommandIDs.addExternalDrive,
485+
selector: '#drive-file-browser.jp-SidePanel .jp-DirListing-content',
486+
rank: 110
487+
});
488+
457489
app.commands.addCommand(CommandIDs.toggleFileFilter, {
458490
execute: () => {
459491
// Update toggled state, then let the toolbar button update

src/requests.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,22 @@ export async function createDrive(
509509
*/
510510
export async function addPublicDrive(driveUrl: string) {
511511
return await requestAPI<any>('drives/' + driveUrl + '/', 'POST', {
512-
public: true
512+
is_public: true
513+
});
514+
}
515+
516+
/**
517+
* Add external drive.
518+
*
519+
* @param driveUrl The drive URL.
520+
* @param location The drive region.
521+
*
522+
* @returns A promise which resolves with the contents model.
523+
*/
524+
export async function addExternalDrive(driveUrl: string, location: string) {
525+
return await requestAPI<any>('drives/' + driveUrl + '/', 'POST', {
526+
is_public: false,
527+
region: location
513528
});
514529
}
515530

src/token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export namespace CommandIDs {
99
export const toggleBrowser = 'drives:toggle-main';
1010
export const createNewDrive = 'drives:create-new-drive';
1111
export const addPublicDrive = 'drives:add-public-drive';
12+
export const addExternalDrive = 'drives:add-external-drive';
1213
export const launcher = 'launcher:create';
1314
export const toggleFileFilter = 'drives:toggle-file-filter';
1415
export const createNewDirectory = 'drives:create-new-directory';

0 commit comments

Comments
 (0)