Download apps_script.js from stepolan/salescomp: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/stepolan/salescomp/resolve/main/apps_script.js
- Command line
-
hf download hf://spaces/stepolan/salescomp/apps_script.js
-
curl -L -o apps_script.js https://huggingface.co/spaces/stepolan/salescomp/resolve/main/apps_script.js
1.76 kB
| // Google Apps Script — paste this into Extensions > Apps Script in your Google Sheet. | |
| // Deploy as: Web App → Execute as Me → Anyone can access. | |
| // | |
| // The sheet must have headers in row 1: name | author | timestamp | data_json | |
| function doPost(e) { | |
| var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
| var data = JSON.parse(e.postData.contents); | |
| if (data.action === "save") { | |
| // Check if scenario already exists (update in place) | |
| var names = sheet.getRange("A:A").getValues(); | |
| var rowIndex = -1; | |
| for (var i = 1; i < names.length; i++) { | |
| if (names[i][0] === data.name) { | |
| rowIndex = i + 1; // 1-indexed | |
| break; | |
| } | |
| } | |
| var row = [data.name, data.author, data.timestamp, data.data_json]; | |
| if (rowIndex > 0) { | |
| sheet.getRange(rowIndex, 1, 1, 4).setValues([row]); | |
| } else { | |
| sheet.appendRow(row); | |
| } | |
| return ContentService.createTextOutput(JSON.stringify({status: "ok"})) | |
| .setMimeType(ContentService.MimeType.JSON); | |
| } else if (data.action === "delete") { | |
| var names = sheet.getRange("A:A").getValues(); | |
| for (var i = 1; i < names.length; i++) { | |
| if (names[i][0] === data.name) { | |
| sheet.deleteRow(i + 1); | |
| break; | |
| } | |
| } | |
| return ContentService.createTextOutput(JSON.stringify({status: "ok"})) | |
| .setMimeType(ContentService.MimeType.JSON); | |
| } | |
| return ContentService.createTextOutput(JSON.stringify({status: "error", message: "Unknown action"})) | |
| .setMimeType(ContentService.MimeType.JSON); | |
| } | |
| // Required for Apps Script web app — handles GET requests with a simple status page | |
| function doGet(e) { | |
| return ContentService.createTextOutput("SalesComp API is running.") | |
| .setMimeType(ContentService.MimeType.TEXT); | |
| } | |