-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathcode.js
More file actions
26 lines (25 loc) · 726 Bytes
/
code.js
File metadata and controls
26 lines (25 loc) · 726 Bytes
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
/**
* Make Google Drive files Read only
* Author: amit@labnol.org
* Web: https://digitalinspiration.com/
* MIT License
* */
const makeFileReadyOnly = () => {
const fileUrl = 'https://docs.google.com/document/d/.....';
const [fileId] = fileUrl.split('/').filter((e) => /[_-\w]{25,}/.test(e));
UrlFetchApp.fetch(`https://www.googleapis.com/drive/v3/files/${fileId}?supportsAllDrives=true`, {
method: 'PATCH',
contentType: 'application/json',
headers: {
Authorization: `Bearer ${ScriptApp.getOAuthToken()}`,
},
payload: JSON.stringify({
contentRestrictions: [
{
readOnly: true,
reason: 'Prevent accidental editing',
},
],
}),
});
};