Skip to content

Commit 12aa805

Browse files
committed
add functionality to create new drive
1 parent 3121c8f commit 12aa805

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

jupyter_drives/handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ async def get(self, drive: str = "", path: str = ""):
8989
@tornado.web.authenticated
9090
async def post(self, drive: str = "", path: str = ""):
9191
body = self.get_json_body()
92-
result = await self._manager.new_file(drive, path, **body)
92+
if 'location' in body:
93+
result = await self._manager.new_drive(**body)
94+
else:
95+
result = await self._manager.new_file(drive, path, **body)
9396
self.finish(result)
9497

9598
@tornado.web.authenticated

jupyter_drives/manager.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,23 @@ async def check_file(self, drive_name, path):
563563

564564
return
565565

566+
async def new_drive(self, new_drive_name, location='us-east-1'):
567+
"""Create a new drive in the given location.
568+
569+
Args:
570+
new_drive_name: name of new drive to create
571+
location: (optional) region of bucket
572+
"""
573+
try:
574+
await self._file_system._mkdir(new_drive_name, region_name = location)
575+
except Exception as e:
576+
raise tornado.web.HTTPError(
577+
status_code= httpx.codes.BAD_REQUEST,
578+
reason=f"The following error occured when creating the new drive: {e}",
579+
)
580+
581+
return
582+
566583
async def _get_drive_location(self, drive_name):
567584
"""Helping function for getting drive region.
568585

src/requests.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,39 @@ export const countObjectNameAppearances = async (
500500
return counter;
501501
};
502502

503+
/**
504+
* Create a new drive.
505+
*
506+
* @param newDriveName The new drive name.
507+
* @param options.location The region where drive should be located.
508+
*
509+
* @returns A promise which resolves with the contents model.
510+
*/
511+
export async function createDrive(
512+
newDriveName: string,
513+
options: {
514+
location: string;
515+
}
516+
) {
517+
await requestAPI<any>('drives/' + newDriveName + '/', 'POST', {
518+
location: options.location
519+
});
520+
521+
data = {
522+
name: newDriveName,
523+
path: newDriveName,
524+
last_modified: '',
525+
created: '',
526+
content: [],
527+
format: 'json',
528+
mimetype: '',
529+
size: 0,
530+
writable: true,
531+
type: 'directory'
532+
};
533+
return data;
534+
}
535+
503536
namespace Private {
504537
/**
505538
* Helping function for renaming files inside

0 commit comments

Comments
 (0)