mirror of
https://github.com/cyclotruc/gitingest.git
synced 2026-04-28 12:49:29 +00:00
fix: append https:// to urls without it (#14)
Co-authored-by: Romain Courtois <romain@coderamp.io>
This commit is contained in:
parent
96d62f9021
commit
300b9ec537
2 changed files with 36 additions and 6 deletions
|
|
@ -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');
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue