Skip to content

fix: append https:// to urls without it #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ function copyText(className) {
});
}

function validateGithubUrl(url) {
// Add https:// if missing
if (!url.startsWith('https://')) {
url = 'https://' + url;
}

// Check if it's a valid GitHub URL
const githubPattern = /^https:\/\/github\.com\/[^\/]+\/[^\/]+/;
return githubPattern.test(url);
}

function handleSubmit(event, showLoading = false) {
event.preventDefault();
const form = event.target || document.getElementById('ingestForm');
Expand All @@ -46,6 +57,23 @@ function handleSubmit(event, showLoading = false) {
formData.append('max_file_size', slider.value);
}

// Get the input URL
const formData = new FormData(form);
const inputUrl = formData.get('input_text');

// Validate URL
if (!validateGithubUrl(inputUrl)) {
const errorMessage = document.getElementById('error-message') || (() => {
const div = document.createElement('div');
div.id = 'error-message';
div.className = 'text-red-500 text-sm mt-2';
form.appendChild(div);
return div;
})();
errorMessage.textContent = 'Please enter a valid GitHub repository URL (e.g., github.com/user/repo)';
return;
}

const originalContent = submitButton.innerHTML;
const currentStars = document.getElementById('github-stars')?.textContent;

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

// Make sure these are available globally
window.copyText = copyText;

window.handleSubmit = handleSubmit;
window.initializeSlider = initializeSlider;
window.formatSize = formatSize;
window.formatSize = formatSize;
11 changes: 6 additions & 5 deletions src/utils/parse_url.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

import uuid

from config import TMP_BASE_PATH

def parse_url(url: str, max_file_size: int) -> dict:
parsed = {

"user_name": None,
"repo_name": None,
"type": None,
Expand All @@ -17,11 +15,14 @@ def parse_url(url: str, max_file_size: int) -> dict:
"max_file_size": int(max_file_size) * 1024
}

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



if not url.startswith("https://"):
url = "https://" + url

if not url.startswith("https://github.com/"):
raise ValueError("Invalid GitHub URL. Please provide a valid GitHub repository URL.")

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