/** Edelman: private, read-only Slopes folder bridge. * Paste into a standalone Google Apps Script project. Run setup once. * Deploy as Web app, Execute as Me, access Anyone. The connection key below * protects every data request; your Drive folder itself stays Restricted. * No Google passwords or Google access tokens are sent to the Hub. */ const SLOPES_FOLDER_ID = '1HIQcPGi3d6VwaQqf6z13_gfskBO-N2C6'; function setup() { const folder = DriveApp.getFolderById(SLOPES_FOLDER_ID); const props = PropertiesService.getScriptProperties(); if (!props.getProperty('HUB_KEY')) props.setProperty('HUB_KEY', Utilities.getUuid()+Utilities.getUuid()); console.log('Folder: '+folder.getName()); console.log('Connection key (paste only into Hub Settings): '+props.getProperty('HUB_KEY')); } function json_(value) { return ContentService.createTextOutput(JSON.stringify(value)).setMimeType(ContentService.MimeType.JSON); } function doGet() { return json_({ok:false,error:'Use the Hub connection to access this bridge.'}); } function equal_(a,b) { let diff=a.length^b.length; for(let i=0;i200)throw Error('Too many subfolders. Use a dedicated Slopes folder.'); const iter=folder.getFiles(); while(iter.hasNext()) { const file=iter.next(); if(file.isTrashed()||!/\.(slopes|zip)$/i.test(file.getName()))continue; files.push({id:file.getId(),name:file.getName(),modified:file.getLastUpdated().toISOString(),size:file.getSize()}); if(files.length>5000)throw Error('Folder exceeds 5,000 Slopes files.'); } const sub=folder.getFolders();while(sub.hasNext())folders.push(sub.next()); } files.sort((a,b)=>a.idb.id?1:0); const pending=files.filter(f=>!after||f.id>after),page=pending.slice(0,100); return {ok:true,folder_id:SLOPES_FOLDER_ID,files:page,cursor:pending.length>100?page[page.length-1].id:null}; } function doPost(e) { try { if(!e||!e.postData||e.postData.contents.length>4096)throw Error('Invalid request.'); const data=JSON.parse(e.postData.contents),key=PropertiesService.getScriptProperties().getProperty('HUB_KEY'); if(!key||typeof data.key!=='string'||!equal_(data.key,key))throw Error('Connection key is incorrect.'); if(data.action==='list')return json_(list_(String(data.cursor||''))); if(data.action!=='download'||!/^[\w-]{10,200}$/.test(data.file_id||''))throw Error('Invalid request.'); const file=DriveApp.getFileById(data.file_id); if(file.isTrashed()||!insideFolder_(file)||!/\.(slopes|zip)$/i.test(file.getName()))throw Error('File is outside the Slopes folder.'); if(file.getSize()>10*1024*1024)throw Error('Slopes file exceeds 10 MB.'); return json_({ok:true,folder_id:SLOPES_FOLDER_ID,name:file.getName(),base64:Utilities.base64Encode(file.getBlob().getBytes())}); } catch(error) { return json_({ok:false,error:String(error.message||error)}); } }