@@ -28,6 +28,17 @@ function copyText(className) {
28
28
} ) ;
29
29
}
30
30
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 = / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ [ ^ \/ ] + \/ [ ^ \/ ] + / ;
39
+ return githubPattern . test ( url ) ;
40
+ }
41
+
31
42
function handleSubmit ( event , showLoading = false ) {
32
43
event . preventDefault ( ) ;
33
44
const form = event . target || document . getElementById ( 'ingestForm' ) ;
@@ -46,6 +57,23 @@ function handleSubmit(event, showLoading = false) {
46
57
formData . append ( 'max_file_size' , slider . value ) ;
47
58
}
48
59
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
+
49
77
const originalContent = submitButton . innerHTML ;
50
78
const currentStars = document . getElementById ( 'github-stars' ) ?. textContent ;
51
79
@@ -166,6 +194,7 @@ document.addEventListener('DOMContentLoaded', initializeSlider);
166
194
167
195
// Make sure these are available globally
168
196
window . copyText = copyText ;
197
+
169
198
window . handleSubmit = handleSubmit ;
170
199
window . initializeSlider = initializeSlider ;
171
- window . formatSize = formatSize ;
200
+ window . formatSize = formatSize ;
0 commit comments