Skip to content

Commit f9bfcdc

Browse files
committed
add frontend function for public drives
1 parent 7b4b2cf commit f9bfcdc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/contents.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
IRegisteredFileTypes
1111
} from './token';
1212
import {
13+
addPublicDrive,
1314
saveObject,
1415
getContents,
1516
mountDrive,
@@ -662,6 +663,26 @@ export class Drive implements Contents.IDrive {
662663
return data;
663664
}
664665

666+
/**
667+
* Add public drive.
668+
*
669+
* @param options: The options used to add the public drive.
670+
*
671+
* @returns A promise which resolves with the contents model.
672+
*/
673+
async addPublicDrive(driveUrl: string): Promise<Contents.IModel> {
674+
data = await addPublicDrive(driveUrl);
675+
676+
Contents.validateContentsModel(data);
677+
this._fileChanged.emit({
678+
type: 'new',
679+
oldValue: null,
680+
newValue: data
681+
});
682+
683+
return data;
684+
}
685+
665686
/**
666687
* Create a checkpoint for a file.
667688
*

src/requests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,33 @@ export async function createDrive(
533533
return data;
534534
}
535535

536+
/**
537+
* Add public drive.
538+
*
539+
* @param driveUrl The public drive URL.
540+
*
541+
* @returns A promise which resolves with the contents model.
542+
*/
543+
export async function addPublicDrive(driveUrl: string) {
544+
await requestAPI<any>('drives/' + driveUrl + '/', 'POST', {
545+
public: true
546+
});
547+
548+
data = {
549+
name: driveUrl,
550+
path: driveUrl,
551+
last_modified: '',
552+
created: '',
553+
content: [],
554+
format: 'json',
555+
mimetype: '',
556+
size: 0,
557+
writable: true,
558+
type: 'directory'
559+
};
560+
return data;
561+
}
562+
536563
namespace Private {
537564
/**
538565
* Helping function for renaming files inside

0 commit comments

Comments
 (0)