-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (141 loc) · 4.81 KB
/
script.js
File metadata and controls
167 lines (141 loc) · 4.81 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Pitch Deck Drop Zone
const dropZone = document.getElementById('pitch-drop-zone');
const fileInput = document.getElementById('file-input');
const uploadStatus = document.getElementById('upload-status');
const statusText = document.getElementById('status-text');
const progressBar = document.getElementById('progress-bar');
let uploadComplete = false;
const VALID_FILE_TYPES = [
'application/pdf',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
];
const MAX_FILE_SIZE = 10 * 1024 * 1024;
const UPLOADCARE_PUBLIC_KEY = '40a891103e90c0934b6f';
function triggerFileSelect() {
if (!uploadComplete) {
fileInput.click();
}
}
dropZone.addEventListener('click', triggerFileSelect);
dropZone.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
triggerFileSelect();
}
});
fileInput.addEventListener('change', (e) => {
if (e.target.files[0]) {
handleFile(e.target.files[0]);
}
});
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
if (!uploadComplete) {
dropZone.classList.add('drag-over');
}
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('drag-over');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('drag-over');
if (!uploadComplete && e.dataTransfer.files[0]) {
handleFile(e.dataTransfer.files[0]);
}
});
async function handleFile(file) {
if (uploadComplete) {
return;
}
if (!VALID_FILE_TYPES.includes(file.type)) {
alert('Please upload a PDF, PPT, or PPTX file.');
return;
}
if (file.size > MAX_FILE_SIZE) {
alert('File size must be less than 10MB.');
return;
}
showUploadProgress(file.name);
const formData = new FormData();
formData.append('UPLOADCARE_PUB_KEY', UPLOADCARE_PUBLIC_KEY);
formData.append('UPLOADCARE_STORE', '1');
formData.append('file', file);
try {
const uploadResponse = await fetch('https://upload.uploadcare.com/base/', {
method: 'POST',
body: formData
});
if (!uploadResponse.ok) {
throw new Error('Upload failed');
}
const data = await uploadResponse.json();
const fileUrl = `https://ucarecdn.com/${data.file}/`;
await sendNotification(file, fileUrl);
showUploadSuccess();
} catch (error) {
console.error('Upload error:', error);
showUploadError();
}
}
function showUploadProgress(filename) {
uploadStatus.style.display = 'block';
statusText.textContent = `Uploading ${filename}...`;
dropZone.classList.add('uploading');
progressBar.style.width = '0%';
}
function formatFileSize(bytes) {
return (bytes / 1024 / 1024).toFixed(2);
}
async function sendNotification(file, fileUrl) {
const notificationData = new FormData();
notificationData.append('email', 'contact@innos.capital');
notificationData.append('subject', 'New Pitch Deck Received');
notificationData.append('message', [
'New pitch deck submission:',
'',
`Filename: ${file.name}`,
`Size: ${formatFileSize(file.size)}MB`,
`Type: ${file.type}`,
`Date: ${new Date().toLocaleString('de-DE')}`,
'',
`Download link: ${fileUrl}`
].join('\n'));
await fetch('https://formspree.io/f/xvgrknbd', {
method: 'POST',
body: notificationData,
headers: { 'Accept': 'application/json' }
});
}
function showUploadSuccess() {
progressBar.style.width = '100%';
dropZone.classList.remove('uploading');
dropZone.classList.add('success', 'complete');
uploadComplete = true;
const dropContent = dropZone.querySelector('div');
dropContent.innerHTML = `
<svg class="drop-icon" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<path d="M5 13l4 4L19 7" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<h3 class="drop-title">Vielen Dank!</h3>
<p class="drop-subtitle">Ihr Pitch Deck wurde erfolgreich übermittelt.</p>
<p class="drop-info">Wir melden uns in Kürze bei Ihnen.</p>
`;
dropZone.style.cursor = 'default';
setTimeout(() => { uploadStatus.style.display = 'none'; }, 2000);
}
function showUploadError() {
dropZone.classList.remove('uploading');
statusText.textContent = 'Upload failed. Please try again or email directly.';
progressBar.style.width = '0%';
setTimeout(resetUpload, 3000);
}
function resetUpload() {
if (!uploadComplete) {
dropZone.classList.remove('uploading', 'success');
uploadStatus.style.display = 'none';
progressBar.style.width = '0%';
fileInput.value = '';
}
}