-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
133 lines (119 loc) · 3.62 KB
/
Code.gs
File metadata and controls
133 lines (119 loc) · 3.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* SUPERTEAM BRASIL — Submissão de Projetos
* Google Apps Script Web App: recebe submissões do site,
* salva os arquivos no Google Drive e loga numa Sheet.
*/
// =================================================================
// CONFIG — substitua pelos seus IDs
// =================================================================
// 1. Crie uma pasta no Drive (ex: "Submissões Superteam BR"),
// abra ela, e copie o ID da URL:
// drive.google.com/drive/folders/AQUI_VEM_O_ID
const FOLDER_ID = "PASTE_YOUR_DRIVE_FOLDER_ID";
// 2. Crie uma Google Sheet nova, copie o ID da URL:
// docs.google.com/spreadsheets/d/AQUI_VEM_O_ID/edit
const SHEET_ID = "PASTE_YOUR_SHEET_ID";
// =================================================================
// MAIN HANDLER
// =================================================================
function doPost(e) {
try {
const data = JSON.parse(e.postData.contents);
const safeName = (data.projectName || "sem-nome")
.replace(/[^\w\s-]/g, "")
.replace(/\s+/g, "-")
.slice(0, 40);
const timestamp = Utilities.formatDate(
new Date(),
"America/Sao_Paulo",
"yyyy-MM-dd_HH-mm"
);
const submissionId = Utilities.getUuid().slice(0, 8);
const folderName = `${timestamp}_${safeName}_${submissionId}`;
const parentFolder = DriveApp.getFolderById(FOLDER_ID);
const submissionFolder = parentFolder.createFolder(folderName);
const fileLinks = [];
if (Array.isArray(data.files)) {
for (const file of data.files) {
const blob = Utilities.newBlob(
Utilities.base64Decode(file.base64),
file.mimeType || "application/octet-stream",
file.name
);
const driveFile = submissionFolder.createFile(blob);
fileLinks.push(`${file.name}: ${driveFile.getUrl()}`);
}
}
const metaContent = [
`Projeto: ${data.projectName}`,
`Founder: ${data.founderName}`,
`Email: ${data.email}`,
`Telegram: ${data.telegram}`,
`Track: ${data.track}`,
`Estágio: ${data.stage}`,
`Website: ${data.website || "—"}`,
`Vídeo: ${data.videoUrl || "—"}`,
``,
`Descrição:`,
data.description,
``,
`Submetido em: ${new Date().toISOString()}`,
`ID: ${submissionId}`,
].join("\n");
submissionFolder.createFile("_INFO.txt", metaContent, "text/plain");
const sheet = SpreadsheetApp.openById(SHEET_ID).getSheets()[0];
if (sheet.getLastRow() === 0) {
sheet.appendRow([
"Timestamp",
"ID",
"Projeto",
"Founder",
"Email",
"Telegram",
"Track",
"Estágio",
"Descrição",
"Website",
"Link Vídeo",
"Pasta Drive",
"Arquivos",
"Status",
]);
}
sheet.appendRow([
new Date(),
submissionId,
data.projectName,
data.founderName,
data.email,
data.telegram,
data.track,
data.stage,
data.description,
data.website || "",
data.videoUrl || "",
submissionFolder.getUrl(),
fileLinks.join("\n"),
"Pendente",
]);
return jsonResponse({
success: true,
id: submissionId,
folderUrl: submissionFolder.getUrl(),
});
} catch (err) {
console.error(err);
return jsonResponse({ success: false, error: err.toString() });
}
}
function jsonResponse(obj) {
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(
ContentService.MimeType.JSON
);
}
function doGet() {
return jsonResponse({
status: "Superteam BR submission endpoint OK",
timestamp: new Date().toISOString(),
});
}