Skip to content

Commit 300b9ec

Browse files
fix: append https:// to urls without it (#14)
Co-authored-by: Romain Courtois <romain@coderamp.io>
1 parent 96d62f9 commit 300b9ec

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/static/js/utils.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ function copyText(className) {
2828
});
2929
}
3030

31+
function validateGithubUrl(url) {
32+
// Add https:// if missing
33+
if (!url.startsWith('https://')) {
34+
url = 'https://' + url;
35+
}
36+
37+
// Check if it's a valid GitHub URL
38+
const githubPattern = /^https:\/\/github\.com\/[^\/]+\/[^\/]+/;
39+
return githubPattern.test(url);
40+
}
41+
3142
function handleSubmit(event, showLoading = false) {
3243
event.preventDefault();
3344
const form = event.target || document.getElementById('ingestForm');
@@ -46,6 +57,23 @@ function handleSubmit(event, showLoading = false) {
4657
formData.append('max_file_size', slider.value);
4758
}
4859

60+
// Get the input URL
61+
const formData = new FormData(form);
62+
const inputUrl = formData.get('input_text');
63+
64+
// Validate URL
65+
if (!validateGithubUrl(inputUrl)) {
66+
const errorMessage = document.getElementById('error-message') || (() => {
67+
const div = document.createElement('div');
68+
div.id = 'error-message';
69+
div.className = 'text-red-500 text-sm mt-2';
70+
form.appendChild(div);
71+
return div;
72+
})();
73+
errorMessage.textContent = 'Please enter a valid GitHub repository URL (e.g., github.com/user/repo)';
74+
return;
75+
}
76+
4977
const originalContent = submitButton.innerHTML;
5078
const currentStars = document.getElementById('github-stars')?.textContent;
5179

@@ -166,6 +194,7 @@ document.addEventListener('DOMContentLoaded', initializeSlider);
166194

167195
// Make sure these are available globally
168196
window.copyText = copyText;
197+
169198
window.handleSubmit = handleSubmit;
170199
window.initializeSlider = initializeSlider;
171-
window.formatSize = formatSize;
200+
window.formatSize = formatSize;

src/utils/parse_url.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
21
import uuid
32

43
from config import TMP_BASE_PATH
54

65
def parse_url(url: str, max_file_size: int) -> dict:
76
parsed = {
8-
97
"user_name": None,
108
"repo_name": None,
119
"type": None,
@@ -17,11 +15,14 @@ def parse_url(url: str, max_file_size: int) -> dict:
1715
"max_file_size": int(max_file_size) * 1024
1816
}
1917

20-
print(f"max_file_size: {max_file_size}")
21-
if not url.startswith("https://github.com/"):
22-
raise ValueError("Invalid GitHub URL. Please provide a valid GitHub repository URL.")
18+
2319

2420

21+
if not url.startswith("https://"):
22+
url = "https://" + url
23+
24+
if not url.startswith("https://github.com/"):
25+
raise ValueError("Invalid GitHub URL. Please provide a valid GitHub repository URL.")
2526

2627
# Remove anything after the first space
2728
url = url.split(" ")[0]

0 commit comments

Comments
 (0)