-
Notifications
You must be signed in to change notification settings - Fork 1
/
add library.js
28 lines (27 loc) · 1.09 KB
/
add library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function addLibraryToMyDrive(e) {
var libraryKey = e.parameter.libraryKey;
if (!libraryKey) {
var html = '<p style="margin:25px">Error: Missing library key.</p>';
return HtmlService.createHtmlOutput(html);
}
try {
var library = DriveApp.getFolderById(libraryKey);
} catch(err) {
html = '<p style="margin:25px">Error: Unable to access library with key <strong>' + libraryKey + '</strong></p>';
return HtmlService.createHtmlOutput(html);
}
try {
var root = DriveApp.getRootFolder();
root.addFolder(library);
} catch(err) {
html = '<p style="margin:25px">Error: ' + err.message + '</p>';
}
html = HtmlService.createTemplateFromFile('libraryAdded');
html.libraryName = library.getName();
html.libraryDescription = library.getDescription();
html.libraryUrl = "https://drive.google.com/drive/folders/" + libraryKey;
html.user = root.getOwner().getEmail();
var domain = html.user.split("@")[1];
Libraries.PublishedLibrary.logUserAction("Added to Drive", libraryKey, '', domain);
return html.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}