coollsd commited on
Commit
7d1bbf1
·
verified ·
1 Parent(s): 514c417

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -775,7 +775,7 @@ HTML_CONTENT = """
775
  linkContainer.style.marginBottom = '10px';
776
 
777
  const link = document.createElement('a');
778
- link.href = url.replace('.png', '');
779
  link.textContent = `View ${fileName}`;
780
  link.className = 'result-link';
781
  link.target = '_blank';
@@ -790,7 +790,7 @@ HTML_CONTENT = """
790
  copyBtn.textContent = 'Copy Link';
791
  copyBtn.className = 'small-btn copy-btn';
792
  copyBtn.onclick = () => {
793
- navigator.clipboard.writeText(window.location.origin + url.replace('.png', '')).then(() => {
794
  alert('Link copied to clipboard!');
795
  });
796
  };
@@ -801,7 +801,7 @@ HTML_CONTENT = """
801
  embedBtn.textContent = 'Embed Video for Discord';
802
  embedBtn.className = 'small-btn embed-btn';
803
  embedBtn.onclick = () => {
804
- showEmbedModal(url.replace('.png', ''));
805
  };
806
  buttonsContainer.appendChild(embedBtn);
807
  }
@@ -826,7 +826,7 @@ HTML_CONTENT = """
826
 
827
  function saveToHistory(fileName, url, originalExtension) {
828
  let history = JSON.parse(localStorage.getItem('uploadHistory')) || [];
829
- history.unshift({ fileName, url: url.replace('.png', ''), originalExtension, timestamp: new Date().toISOString() });
830
  if (history.length > 500) history = history.slice(0, 500);
831
  localStorage.setItem('uploadHistory', JSON.stringify(history));
832
  }
@@ -950,21 +950,14 @@ async def handle_upload(file: UploadFile = File(...)):
950
  return JSONResponse(content={"error": "Failed"}, status_code=500)
951
 
952
  original_extension = os.path.splitext(file.filename)[1][1:]
953
- supported_types = ['mp4', 'png', 'zip', 'pdf', 'txt']
954
-
955
- if original_extension.lower() in supported_types:
956
- temp_filename = file.filename
957
- content_type = file.content_type
958
- else:
959
- temp_filename = f"{file.filename}.png"
960
- content_type = "image/png"
961
-
962
- upload_result = await initiate_upload(cookies, temp_filename, content_type)
963
  if not upload_result or 'upload_url' not in upload_result:
964
  return JSONResponse(content={"error": "Failed to upload"}, status_code=500)
965
 
966
  file_content = await file.read()
967
- upload_success = await retry_upload(upload_result['upload_url'], file_content, content_type)
968
  if not upload_success:
969
  return JSONResponse(content={"error": "FAILED GOD MAN AFTER alot of attempts"}, status_code=500)
970
 
@@ -992,12 +985,11 @@ async def handle_file_stream(path: str, request: Request):
992
  if response.status_code == 206:
993
  headers['Content-Range'] = response.headers.get('Content-Range')
994
 
995
- # Remove .png extension if present
996
- if path.lower().endswith('.png'):
997
- original_filename = os.path.splitext(path)[0]
998
- content_type, _ = mimetypes.guess_type(original_filename)
999
- if content_type:
1000
- headers['Content-Type'] = content_type
1001
 
1002
  return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
1003
 
 
775
  linkContainer.style.marginBottom = '10px';
776
 
777
  const link = document.createElement('a');
778
+ link.href = url;
779
  link.textContent = `View ${fileName}`;
780
  link.className = 'result-link';
781
  link.target = '_blank';
 
790
  copyBtn.textContent = 'Copy Link';
791
  copyBtn.className = 'small-btn copy-btn';
792
  copyBtn.onclick = () => {
793
+ navigator.clipboard.writeText(window.location.origin + url).then(() => {
794
  alert('Link copied to clipboard!');
795
  });
796
  };
 
801
  embedBtn.textContent = 'Embed Video for Discord';
802
  embedBtn.className = 'small-btn embed-btn';
803
  embedBtn.onclick = () => {
804
+ showEmbedModal(url);
805
  };
806
  buttonsContainer.appendChild(embedBtn);
807
  }
 
826
 
827
  function saveToHistory(fileName, url, originalExtension) {
828
  let history = JSON.parse(localStorage.getItem('uploadHistory')) || [];
829
+ history.unshift({ fileName, url, originalExtension, timestamp: new Date().toISOString() });
830
  if (history.length > 500) history = history.slice(0, 500);
831
  localStorage.setItem('uploadHistory', JSON.stringify(history));
832
  }
 
950
  return JSONResponse(content={"error": "Failed"}, status_code=500)
951
 
952
  original_extension = os.path.splitext(file.filename)[1][1:]
953
+ temp_filename = f"{file.filename}.png"
954
+
955
+ upload_result = await initiate_upload(cookies, temp_filename, "image/png")
 
 
 
 
 
 
 
956
  if not upload_result or 'upload_url' not in upload_result:
957
  return JSONResponse(content={"error": "Failed to upload"}, status_code=500)
958
 
959
  file_content = await file.read()
960
+ upload_success = await retry_upload(upload_result['upload_url'], file_content, "image/png")
961
  if not upload_success:
962
  return JSONResponse(content={"error": "FAILED GOD MAN AFTER alot of attempts"}, status_code=500)
963
 
 
985
  if response.status_code == 206:
986
  headers['Content-Range'] = response.headers.get('Content-Range')
987
 
988
+ # Set the correct Content-Type based on the original file extension
989
+ original_extension = os.path.splitext(path)[1][1:]
990
+ content_type, _ = mimetypes.guess_type(f"file.{original_extension}")
991
+ if content_type:
992
+ headers['Content-Type'] = content_type
 
993
 
994
  return StreamingResponse(generate(), status_code=response.status_code, headers=headers)
995