File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
google-apps-script/drive-lock Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ # Google Drive Lock 🐢
2+
3+ [ Make files Read-only in Google Drive] ( https://www.labnol.org/code/read-only-google-drive-file-201011 )
Original file line number Diff line number Diff line change 1+ {
2+ "timeZone" : " Asia/Kolkata" ,
3+ "dependencies" : {},
4+ "runtimeVersion" : " V8" ,
5+ "oauthScopes" : [" https://www.googleapis.com/auth/drive" , " https://www.googleapis.com/auth/script.external_request" ]
6+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * Make Google Drive files Read only
3+ * Author: amit@labnol.org
4+ * Web: https://digitalinspiration.com/
5+ * MIT License
6+ **/
7+
8+ const makeFileReadyOnly = ( ) => {
9+ const fileUrl = "https://docs.google.com/document/d/....." ;
10+ const [ fileId ] = fileUrl . split ( "/" ) . filter ( ( e ) => / [ _ - \w ] { 25 , } / . test ( e ) ) ;
11+ UrlFetchApp . fetch ( `https://www.googleapis.com/drive/v3/files/${ fileId } ` , {
12+ method : "PATCH" ,
13+ contentType : "application/json" ,
14+ headers : {
15+ Authorization : `Bearer ${ ScriptApp . getOAuthToken ( ) } ` ,
16+ } ,
17+ payload : JSON . stringify ( {
18+ contentRestrictions : [
19+ {
20+ readOnly : true ,
21+ reason : "Prevent accidental editing" ,
22+ } ,
23+ ] ,
24+ } ) ,
25+ } ) ;
26+ } ;
You can’t perform that action at this time.
0 commit comments