veltrixcode commited on
Commit
b6eb1b6
·
verified ·
1 Parent(s): 5db2386

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -52
app.py CHANGED
@@ -8,6 +8,9 @@ from internetarchive import get_item
8
 
9
  app = Flask(__name__)
10
 
 
 
 
11
  # Internet Archive S3 Configuration
12
  IA_ACCESS_KEY = "YXzY5OrREXLL6XBh"
13
  IA_SECRET_KEY = "m2XnL3X7xCB1pNGE"
@@ -31,7 +34,6 @@ HTML_TEMPLATE = """
31
  padding: 0;
32
  box-sizing: border-box;
33
  }
34
-
35
  body {
36
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
37
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
@@ -41,7 +43,6 @@ HTML_TEMPLATE = """
41
  align-items: center;
42
  padding: 20px;
43
  }
44
-
45
  .container {
46
  background: rgba(255, 255, 255, 0.95);
47
  backdrop-filter: blur(10px);
@@ -51,21 +52,18 @@ HTML_TEMPLATE = """
51
  width: 100%;
52
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
53
  }
54
-
55
  h1 {
56
  color: #2d3748;
57
  margin-bottom: 10px;
58
  font-size: 32px;
59
  text-align: center;
60
  }
61
-
62
  .subtitle {
63
  color: #718096;
64
  text-align: center;
65
  margin-bottom: 30px;
66
  font-size: 14px;
67
  }
68
-
69
  .upload-area {
70
  border: 3px dashed #cbd5e0;
71
  border-radius: 16px;
@@ -76,38 +74,31 @@ HTML_TEMPLATE = """
76
  background: #f7fafc;
77
  margin-bottom: 20px;
78
  }
79
-
80
  .upload-area:hover {
81
  border-color: #667eea;
82
  background: #edf2f7;
83
  transform: translateY(-2px);
84
  }
85
-
86
  .upload-area.dragover {
87
  border-color: #667eea;
88
  background: #e6fffa;
89
  }
90
-
91
  .upload-icon {
92
  font-size: 48px;
93
  margin-bottom: 16px;
94
  }
95
-
96
  .upload-text {
97
  color: #4a5568;
98
  font-size: 18px;
99
  margin-bottom: 8px;
100
  }
101
-
102
  .upload-hint {
103
  color: #a0aec0;
104
  font-size: 14px;
105
  }
106
-
107
  input[type="file"] {
108
  display: none;
109
  }
110
-
111
  .btn {
112
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
113
  color: white;
@@ -121,29 +112,24 @@ HTML_TEMPLATE = """
121
  transition: all 0.3s ease;
122
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
123
  }
124
-
125
  .btn:hover {
126
  transform: translateY(-2px);
127
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
128
  }
129
-
130
  .btn:disabled {
131
  background: #cbd5e0;
132
  cursor: not-allowed;
133
  box-shadow: none;
134
  }
135
-
136
  .preview-container {
137
  margin: 20px 0;
138
  display: none;
139
  }
140
-
141
  .preview-image {
142
  max-width: 100%;
143
  border-radius: 12px;
144
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
145
  }
146
-
147
  .result-container {
148
  margin-top: 20px;
149
  padding: 20px;
@@ -152,18 +138,15 @@ HTML_TEMPLATE = """
152
  border: 2px solid #9ae6b4;
153
  display: none;
154
  }
155
-
156
  .result-container.error {
157
  background: #fff5f5;
158
  border-color: #fc8181;
159
  }
160
-
161
  .url-box {
162
  display: flex;
163
  gap: 10px;
164
  margin-top: 10px;
165
  }
166
-
167
  .url-input {
168
  flex: 1;
169
  padding: 12px;
@@ -172,7 +155,6 @@ HTML_TEMPLATE = """
172
  font-size: 14px;
173
  font-family: monospace;
174
  }
175
-
176
  .copy-btn {
177
  padding: 12px 24px;
178
  background: #667eea;
@@ -183,17 +165,14 @@ HTML_TEMPLATE = """
183
  font-weight: 600;
184
  transition: all 0.3s ease;
185
  }
186
-
187
  .copy-btn:hover {
188
  background: #5568d3;
189
  }
190
-
191
  .loading {
192
  display: none;
193
  text-align: center;
194
  margin: 20px 0;
195
  }
196
-
197
  .spinner {
198
  border: 4px solid #f3f4f6;
199
  border-top: 4px solid #667eea;
@@ -203,12 +182,10 @@ HTML_TEMPLATE = """
203
  animation: spin 1s linear infinite;
204
  margin: 0 auto;
205
  }
206
-
207
  @keyframes spin {
208
  0% { transform: rotate(0deg); }
209
  100% { transform: rotate(360deg); }
210
  }
211
-
212
  .file-info {
213
  margin: 15px 0;
214
  padding: 12px;
@@ -216,7 +193,6 @@ HTML_TEMPLATE = """
216
  border-radius: 8px;
217
  display: none;
218
  }
219
-
220
  .file-info-text {
221
  color: #4a5568;
222
  font-size: 14px;
@@ -227,29 +203,23 @@ HTML_TEMPLATE = """
227
  <div class="container">
228
  <h1>📸 Image Upload</h1>
229
  <p class="subtitle">Upload to Archive.org CDN</p>
230
-
231
  <div class="upload-area" id="uploadArea">
232
  <div class="upload-icon">☁️</div>
233
  <div class="upload-text">Click or drag image here</div>
234
  <div class="upload-hint">PNG, JPG, GIF, WEBP up to 50MB</div>
235
  <input type="file" id="fileInput" accept="image/*">
236
  </div>
237
-
238
  <div class="file-info" id="fileInfo">
239
  <div class="file-info-text" id="fileInfoText"></div>
240
  </div>
241
-
242
  <div class="preview-container" id="previewContainer">
243
  <img id="previewImage" class="preview-image" alt="Preview">
244
  </div>
245
-
246
  <button class="btn" id="uploadBtn" disabled>Upload Image</button>
247
-
248
  <div class="loading" id="loading">
249
  <div class="spinner"></div>
250
  <p style="margin-top: 10px; color: #4a5568;">Uploading...</p>
251
  </div>
252
-
253
  <div class="result-container" id="resultContainer">
254
  <div style="font-weight: 600; margin-bottom: 10px; color: #2d3748;" id="resultTitle">✅ Upload Successful!</div>
255
  <div class="url-box">
@@ -258,7 +228,6 @@ HTML_TEMPLATE = """
258
  </div>
259
  </div>
260
  </div>
261
-
262
  <script>
263
  const uploadArea = document.getElementById('uploadArea');
264
  const fileInput = document.getElementById('fileInput');
@@ -272,20 +241,15 @@ HTML_TEMPLATE = """
272
  const fileInfo = document.getElementById('fileInfo');
273
  const fileInfoText = document.getElementById('fileInfoText');
274
  const resultTitle = document.getElementById('resultTitle');
275
-
276
  let selectedFile = null;
277
-
278
  uploadArea.addEventListener('click', () => fileInput.click());
279
-
280
  uploadArea.addEventListener('dragover', (e) => {
281
  e.preventDefault();
282
  uploadArea.classList.add('dragover');
283
  });
284
-
285
  uploadArea.addEventListener('dragleave', () => {
286
  uploadArea.classList.remove('dragover');
287
  });
288
-
289
  uploadArea.addEventListener('drop', (e) => {
290
  e.preventDefault();
291
  uploadArea.classList.remove('dragover');
@@ -294,24 +258,20 @@ HTML_TEMPLATE = """
294
  handleFile(files[0]);
295
  }
296
  });
297
-
298
  fileInput.addEventListener('change', (e) => {
299
  if (e.target.files.length > 0) {
300
  handleFile(e.target.files[0]);
301
  }
302
  });
303
-
304
  function handleFile(file) {
305
  if (!file.type.startsWith('image/')) {
306
  alert('Please select an image file');
307
  return;
308
  }
309
-
310
  if (file.size > 50 * 1024 * 1024) {
311
  alert('File size must be less than 50MB');
312
  return;
313
  }
314
-
315
  selectedFile = file;
316
 
317
  const reader = new FileReader();
@@ -320,31 +280,24 @@ HTML_TEMPLATE = """
320
  previewContainer.style.display = 'block';
321
  };
322
  reader.readAsDataURL(file);
323
-
324
  fileInfoText.textContent = `${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`;
325
  fileInfo.style.display = 'block';
326
  uploadBtn.disabled = false;
327
  resultContainer.style.display = 'none';
328
  }
329
-
330
  uploadBtn.addEventListener('click', async () => {
331
  if (!selectedFile) return;
332
-
333
  const formData = new FormData();
334
  formData.append('file', selectedFile);
335
-
336
  uploadBtn.disabled = true;
337
  loading.style.display = 'block';
338
  resultContainer.style.display = 'none';
339
-
340
  try {
341
  const response = await fetch('/upload', {
342
  method: 'POST',
343
  body: formData
344
  });
345
-
346
  const data = await response.json();
347
-
348
  if (data.success) {
349
  urlInput.value = data.url;
350
  resultContainer.className = 'result-container';
@@ -366,7 +319,6 @@ HTML_TEMPLATE = """
366
  uploadBtn.disabled = false;
367
  }
368
  });
369
-
370
  copyBtn.addEventListener('click', () => {
371
  urlInput.select();
372
  document.execCommand('copy');
@@ -454,4 +406,5 @@ def api_upload():
454
  return upload_file()
455
 
456
  if __name__ == '__main__':
457
- app.run(host='0.0.0.0', port=7860, debug=False)
 
 
8
 
9
  app = Flask(__name__)
10
 
11
+ # Allow all hosts
12
+ app.config['SERVER_NAME'] = None
13
+
14
  # Internet Archive S3 Configuration
15
  IA_ACCESS_KEY = "YXzY5OrREXLL6XBh"
16
  IA_SECRET_KEY = "m2XnL3X7xCB1pNGE"
 
34
  padding: 0;
35
  box-sizing: border-box;
36
  }
 
37
  body {
38
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
39
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
 
43
  align-items: center;
44
  padding: 20px;
45
  }
 
46
  .container {
47
  background: rgba(255, 255, 255, 0.95);
48
  backdrop-filter: blur(10px);
 
52
  width: 100%;
53
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
54
  }
 
55
  h1 {
56
  color: #2d3748;
57
  margin-bottom: 10px;
58
  font-size: 32px;
59
  text-align: center;
60
  }
 
61
  .subtitle {
62
  color: #718096;
63
  text-align: center;
64
  margin-bottom: 30px;
65
  font-size: 14px;
66
  }
 
67
  .upload-area {
68
  border: 3px dashed #cbd5e0;
69
  border-radius: 16px;
 
74
  background: #f7fafc;
75
  margin-bottom: 20px;
76
  }
 
77
  .upload-area:hover {
78
  border-color: #667eea;
79
  background: #edf2f7;
80
  transform: translateY(-2px);
81
  }
 
82
  .upload-area.dragover {
83
  border-color: #667eea;
84
  background: #e6fffa;
85
  }
 
86
  .upload-icon {
87
  font-size: 48px;
88
  margin-bottom: 16px;
89
  }
 
90
  .upload-text {
91
  color: #4a5568;
92
  font-size: 18px;
93
  margin-bottom: 8px;
94
  }
 
95
  .upload-hint {
96
  color: #a0aec0;
97
  font-size: 14px;
98
  }
 
99
  input[type="file"] {
100
  display: none;
101
  }
 
102
  .btn {
103
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
104
  color: white;
 
112
  transition: all 0.3s ease;
113
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
114
  }
 
115
  .btn:hover {
116
  transform: translateY(-2px);
117
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
118
  }
 
119
  .btn:disabled {
120
  background: #cbd5e0;
121
  cursor: not-allowed;
122
  box-shadow: none;
123
  }
 
124
  .preview-container {
125
  margin: 20px 0;
126
  display: none;
127
  }
 
128
  .preview-image {
129
  max-width: 100%;
130
  border-radius: 12px;
131
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
132
  }
 
133
  .result-container {
134
  margin-top: 20px;
135
  padding: 20px;
 
138
  border: 2px solid #9ae6b4;
139
  display: none;
140
  }
 
141
  .result-container.error {
142
  background: #fff5f5;
143
  border-color: #fc8181;
144
  }
 
145
  .url-box {
146
  display: flex;
147
  gap: 10px;
148
  margin-top: 10px;
149
  }
 
150
  .url-input {
151
  flex: 1;
152
  padding: 12px;
 
155
  font-size: 14px;
156
  font-family: monospace;
157
  }
 
158
  .copy-btn {
159
  padding: 12px 24px;
160
  background: #667eea;
 
165
  font-weight: 600;
166
  transition: all 0.3s ease;
167
  }
 
168
  .copy-btn:hover {
169
  background: #5568d3;
170
  }
 
171
  .loading {
172
  display: none;
173
  text-align: center;
174
  margin: 20px 0;
175
  }
 
176
  .spinner {
177
  border: 4px solid #f3f4f6;
178
  border-top: 4px solid #667eea;
 
182
  animation: spin 1s linear infinite;
183
  margin: 0 auto;
184
  }
 
185
  @keyframes spin {
186
  0% { transform: rotate(0deg); }
187
  100% { transform: rotate(360deg); }
188
  }
 
189
  .file-info {
190
  margin: 15px 0;
191
  padding: 12px;
 
193
  border-radius: 8px;
194
  display: none;
195
  }
 
196
  .file-info-text {
197
  color: #4a5568;
198
  font-size: 14px;
 
203
  <div class="container">
204
  <h1>📸 Image Upload</h1>
205
  <p class="subtitle">Upload to Archive.org CDN</p>
 
206
  <div class="upload-area" id="uploadArea">
207
  <div class="upload-icon">☁️</div>
208
  <div class="upload-text">Click or drag image here</div>
209
  <div class="upload-hint">PNG, JPG, GIF, WEBP up to 50MB</div>
210
  <input type="file" id="fileInput" accept="image/*">
211
  </div>
 
212
  <div class="file-info" id="fileInfo">
213
  <div class="file-info-text" id="fileInfoText"></div>
214
  </div>
 
215
  <div class="preview-container" id="previewContainer">
216
  <img id="previewImage" class="preview-image" alt="Preview">
217
  </div>
 
218
  <button class="btn" id="uploadBtn" disabled>Upload Image</button>
 
219
  <div class="loading" id="loading">
220
  <div class="spinner"></div>
221
  <p style="margin-top: 10px; color: #4a5568;">Uploading...</p>
222
  </div>
 
223
  <div class="result-container" id="resultContainer">
224
  <div style="font-weight: 600; margin-bottom: 10px; color: #2d3748;" id="resultTitle">✅ Upload Successful!</div>
225
  <div class="url-box">
 
228
  </div>
229
  </div>
230
  </div>
 
231
  <script>
232
  const uploadArea = document.getElementById('uploadArea');
233
  const fileInput = document.getElementById('fileInput');
 
241
  const fileInfo = document.getElementById('fileInfo');
242
  const fileInfoText = document.getElementById('fileInfoText');
243
  const resultTitle = document.getElementById('resultTitle');
 
244
  let selectedFile = null;
 
245
  uploadArea.addEventListener('click', () => fileInput.click());
 
246
  uploadArea.addEventListener('dragover', (e) => {
247
  e.preventDefault();
248
  uploadArea.classList.add('dragover');
249
  });
 
250
  uploadArea.addEventListener('dragleave', () => {
251
  uploadArea.classList.remove('dragover');
252
  });
 
253
  uploadArea.addEventListener('drop', (e) => {
254
  e.preventDefault();
255
  uploadArea.classList.remove('dragover');
 
258
  handleFile(files[0]);
259
  }
260
  });
 
261
  fileInput.addEventListener('change', (e) => {
262
  if (e.target.files.length > 0) {
263
  handleFile(e.target.files[0]);
264
  }
265
  });
 
266
  function handleFile(file) {
267
  if (!file.type.startsWith('image/')) {
268
  alert('Please select an image file');
269
  return;
270
  }
 
271
  if (file.size > 50 * 1024 * 1024) {
272
  alert('File size must be less than 50MB');
273
  return;
274
  }
 
275
  selectedFile = file;
276
 
277
  const reader = new FileReader();
 
280
  previewContainer.style.display = 'block';
281
  };
282
  reader.readAsDataURL(file);
 
283
  fileInfoText.textContent = `${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`;
284
  fileInfo.style.display = 'block';
285
  uploadBtn.disabled = false;
286
  resultContainer.style.display = 'none';
287
  }
 
288
  uploadBtn.addEventListener('click', async () => {
289
  if (!selectedFile) return;
 
290
  const formData = new FormData();
291
  formData.append('file', selectedFile);
 
292
  uploadBtn.disabled = true;
293
  loading.style.display = 'block';
294
  resultContainer.style.display = 'none';
 
295
  try {
296
  const response = await fetch('/upload', {
297
  method: 'POST',
298
  body: formData
299
  });
 
300
  const data = await response.json();
 
301
  if (data.success) {
302
  urlInput.value = data.url;
303
  resultContainer.className = 'result-container';
 
319
  uploadBtn.disabled = false;
320
  }
321
  });
 
322
  copyBtn.addEventListener('click', () => {
323
  urlInput.select();
324
  document.execCommand('copy');
 
406
  return upload_file()
407
 
408
  if __name__ == '__main__':
409
+ # Listen on all interfaces (0.0.0.0) to allow all hosts
410
+ app.run(host='0.0.0.0', port=7860, debug=False, threaded=True)