-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
363 lines (313 loc) Β· 12.7 KB
/
setup.sh
File metadata and controls
363 lines (313 loc) Β· 12.7 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
# bashupload Setup Script
echo "π Setting up bashupload project structure..."
# Create directories
mkdir -p templates static cmd/cli uploads
# Create template file if it doesn't exist
if [ ! -f "templates/index.html" ]; then
echo "π Creating HTML template..."
echo "<!-- Copy the HTML template content from the artifacts to this file -->" > templates/index.html
echo "β
HTML template placeholder created!"
fi
# Create CSS file if it doesn't exist
if [ ! -f "static/style.css" ]; then
echo "π¨ Creating CSS styles..."
echo "/* Copy the CSS content from the artifacts to this file */" > static/style.css
echo "β
CSS file placeholder created!"
fi
# Create go.mod if it doesn't exist
if [ ! -f "go.mod" ]; then
echo "π¦ Initializing Go module..."
go mod init bashupload
echo "β
Go module initialized!"
fi
# Create main.go if it doesn't exist
if [ ! -f "main.go" ]; then
echo "π§ Creating main.go placeholder..."
cat > main.go << 'EOF'
package main
import (
"log"
)
func main() {
log.Println("bashupload server - copy the main.go content from artifacts")
}
EOF
echo "β
main.go placeholder created!"
fi
# Create CLI main.go if it doesn't exist
if [ ! -f "cmd/cli/main.go" ]; then
echo "π» Creating CLI main.go placeholder..."
mkdir -p cmd/cli
cat > cmd/cli/main.go << 'EOF'
package main
import (
"log"
)
func main() {
log.Println("bashupload CLI - copy the CLI main.go content from artifacts")
}
EOF
echo "β
CLI main.go placeholder created!"
fi
echo ""
echo "β
bashupload setup complete!"
echo ""
echo "π Next steps:"
echo " 1. Copy the full main.go content from artifacts"
echo " 2. Copy the CLI content to cmd/cli/main.go from artifacts"
echo " 3. Copy the HTML template to templates/index.html"
echo " 4. Copy the CSS styles to static/style.css"
echo " 5. Run: go mod tidy"
echo " 6. Run: make build"
echo " 7. Run: make run"
echo ""
echo "π³ Or use Docker:"
echo " docker-compose up -d"
echo ""
echo "π§ Configuration examples:"
echo " export API_KEY=your_secret_key # Enable private mode"
echo " export MAX_UPLOAD_SIZE=500MB # Set upload limit"
echo " export MAX_DOWNLOADS=1 # Single download (default)"
echo " export MAX_DOWNLOADS=5 # Allow 5 downloads"
echo " export FILE_EXPIRE_AFTER=3D # 3 days (default)"
echo " export FILE_EXPIRE_AFTER=1W # 1 week expiration"
echo " export FILE_EXPIRE_AFTER=1MO # 1 month expiration"
echo ""
echo "π Access bashupload at: http://localhost:3000"
echo ""
echo "π Features:"
echo " β’ Configurable upload limit (default 1GB)"
echo " β’ Configurable download limit (default 1)"
echo " β’ Configurable expiration time (default 3 days)"
echo " β’ Terminal-style web interface"
echo " β’ cURL upload support"
echo " β’ API key authentication (optional)"
echo " β’ Cross-platform CLI tool"
if [ ! -f "templates/index.html" ]; then
echo "π Creating HTML template..."
cat > templates/index.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bashupload</title>
<link rel="stylesheet" href="/static/style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>bashupload</h1>
<div class="description">
Upload files from command line to easily share between servers,<br>
desktops and mobiles, 50G max. Files are stored for 3 days and can be<br>
downloaded only once.
</div>
<div class="terminal-box">
<span class="command">curl bashupload.com -T your_file.txt{{.AuthHeader}}</span>
</div>
{{if .RequiresAuth}}
<div class="auth-section">
<div style="margin-bottom: 15px; color: #ff6600;">π API Key Required</div>
<input type="password" id="apiKeyInput" class="auth-input" placeholder="Enter your API key..." value="">
<button class="btn" onclick="setApiKey()">πΎ SAVE KEY</button>
</div>
{{end}}
<div class="upload-area" onclick="document.getElementById('fileInput').click()">
<p>π alternatively <strong>choose file(s)</strong> to upload</p>
<p class="file-info">Maximum file size: 50GB β’ Files expire in 3 days β’ Single download only</p>
</div>
<input type="file" id="fileInput" class="file-input">
<div class="progress">
<div class="progress-bar"></div>
</div>
<button class="btn" onclick="uploadFile()">βΊ UPLOAD FILE</button>
<div id="result" class="result"></div>
<div class="alternative">
alternatively <a href="#" onclick="showCurlExample()">read more docs</a>
</div>
</div>
<script>
let selectedFile = null;
const uploadArea = document.querySelector('.upload-area');
const fileInput = document.getElementById('fileInput');
const progressBar = document.querySelector('.progress');
const progressFill = document.querySelector('.progress-bar');
const result = document.getElementById('result');
const requiresAuth = {{.RequiresAuth}};
let apiKey = '';
if (requiresAuth) {
const savedKey = localStorage.getItem('api_key');
if (savedKey) {
apiKey = savedKey;
}
}
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
selectedFile = files[0];
updateUploadArea();
}
});
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
selectedFile = e.target.files[0];
updateUploadArea();
}
});
function updateUploadArea() {
if (selectedFile) {
uploadArea.innerHTML = \`
<p>π \${selectedFile.name}</p>
<p class="file-info">Size: \${formatBytes(selectedFile.size)} β’ Ready to upload</p>
\`;
}
}
function setApiKey() {
const key = document.getElementById('apiKeyInput').value;
if (key) {
apiKey = key;
localStorage.setItem('api_key', key);
document.querySelector('.auth-section').style.display = 'none';
showResult('β
API key saved', 'success');
}
}
function formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
async function uploadFile() {
if (!selectedFile) {
showResult('β Please select a file first', 'error');
return;
}
if (requiresAuth && !apiKey) {
showResult('β API key required. Please enter your API key.', 'error');
return;
}
const formData = new FormData();
formData.append('file', selectedFile);
if (requiresAuth && apiKey) {
formData.append('api_key', apiKey);
}
const uploadBtn = document.querySelector('.btn');
uploadBtn.disabled = true;
uploadBtn.textContent = 'β‘ UPLOADING...';
progressBar.style.display = 'block';
result.style.display = 'none';
try {
const xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', (e) => {
if (e.lengthComputable) {
const percentComplete = (e.loaded / e.total) * 100;
progressFill.style.width = percentComplete + '%';
}
});
xhr.onload = function() {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.success) {
showResult(\`
<div style="margin-bottom: 15px;">
<div style="color: #00ff41; font-size: 1.2em; margin-bottom: 10px;">β
UPLOAD SUCCESSFUL</div>
<div>File: \${selectedFile.name}</div>
<div>Size: \${formatBytes(response.file_size)}</div>
<div>Expires: 3 days (single download)</div>
</div>
<div class="terminal-box" style="margin: 15px 0; word-break: break-all;">
<span style="color: #00ff41;">\${response.download_url}</span>
</div>
<div>
<a href="\${response.download_url}" class="download-link" target="_blank">β¬ DOWNLOAD</a>
<button class="btn" onclick="copyToClipboard('\${response.download_url}')">π COPY LINK</button>
</div>
\`, 'success');
} else {
showResult('β ' + response.message, 'error');
}
} else {
const errorText = xhr.responseText ? JSON.parse(xhr.responseText).message : 'Upload failed';
showResult('β ' + errorText, 'error');
}
resetUpload();
};
xhr.onerror = function() {
showResult('β Network error. Check your connection.', 'error');
resetUpload();
};
xhr.open('POST', '/api/upload');
xhr.send(formData);
} catch (error) {
showResult('β Upload failed: ' + error.message, 'error');
resetUpload();
}
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
showResult('π Link copied to clipboard!', 'success');
});
}
function showResult(message, type) {
result.innerHTML = message;
result.className = 'result ' + type;
result.style.display = 'block';
}
function resetUpload() {
const uploadBtn = document.querySelector('.btn');
uploadBtn.disabled = false;
uploadBtn.textContent = 'βΊ UPLOAD FILE';
progressBar.style.display = 'none';
progressFill.style.width = '0%';
}
function showCurlExample() {
const authHeader = requiresAuth ? ' -H "X-API-Key: YOUR_API_KEY"' : '';
alert(\`cURL Examples:
Upload: curl\${authHeader} \${location.origin} -T filename.ext
Or use form: curl\${authHeader} -F "file=@filename.ext" \${location.origin}/api/upload\`);
}
if (requiresAuth && !apiKey) {
setTimeout(() => {
showResult('π This instance requires an API key', 'error');
}, 1000);
}
</script>
</body>
</html>
EOF
echo "β
HTML template created!"
fi
# Create CSS file if it doesn't exist
if [ ! -f "static/style.css" ]; then
echo "π¨ Creating CSS styles..."
echo "/* CSS content would be here - see the artifacts for the full CSS */" > static/style.css
echo "β
CSS file created! (You'll need to copy the full CSS content from the artifacts)"
fi
echo ""
echo "β
Setup complete!"
echo ""
echo "π Next steps:"
echo " 1. Copy the full CSS content to static/style.css"
echo " 2. Run: go mod tidy"
echo " 3. Run: make build"
echo " 4. Run: make run"
echo ""
echo "π³ Or use Docker:"
echo " docker-compose up -d"
echo ""
echo "π§ For private instance, set API_KEY environment variable:"
echo " export API_KEY=your_secret_key"