-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
63 lines (53 loc) · 2.14 KB
/
Copy pathCode.gs
File metadata and controls
63 lines (53 loc) · 2.14 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ============================================================================
// Microlearning Content Reviewer — Sheets Web App perantara
//
// Cara pasang:
// 1. Buka Google Sheet tujuan.
// 2. Menu Extensions > Apps Script.
// 3. Hapus isi default, paste seluruh isi file ini.
// 4. Ganti SHARED_SECRET di bawah dengan string acak buatanmu sendiri
// (perlakukan seperti password — jangan dibagikan).
// 5. Sesuaikan SHEET_NAME kalau nama tab sheet tujuan bukan "Sheet1".
// 6. Klik Deploy > New deployment > pilih tipe "Web app".
// - Execute as: Me
// - Who has access: Anyone
// 7. Klik Deploy, izinkan akses saat diminta otorisasi.
// 8. Salin "Web app URL" yang muncul, tempel ke pengaturan extension
// bersama SHARED_SECRET di atas.
// ============================================================================
const SHARED_SECRET = "GANTI_DENGAN_SECRET_RAHASIA_KAMU";
const SHEET_NAME = "Sheet1";
function doPost(e) {
try {
const payload = JSON.parse(e.postData.contents);
if (payload.secret !== SHARED_SECRET) {
return jsonResponse({ ok: false, error: "Unauthorized: secret tidak cocok." });
}
const columns = payload.columns;
const rows = payload.rows;
if (!Array.isArray(columns) || !Array.isArray(rows)) {
return jsonResponse({ ok: false, error: "Payload tidak valid: columns/rows harus array." });
}
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) {
sheet = ss.insertSheet(SHEET_NAME);
}
if (payload.includeHeader && sheet.getLastRow() === 0) {
sheet.appendRow(columns);
}
rows.forEach((row) => sheet.appendRow(row));
return jsonResponse({ ok: true, appended: rows.length });
} catch (err) {
return jsonResponse({ ok: false, error: String(err) });
}
}
// Buka URL Web App langsung di browser (GET) untuk cek deployment hidup.
function doGet(e) {
return jsonResponse({ ok: true, message: "Web app aktif. Gunakan POST untuk mengirim data." });
}
function jsonResponse(obj) {
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(
ContentService.MimeType.JSON
);
}