@@ -22,56 +22,56 @@ export function UrlConverter() {
2222 }
2323 } ;
2424
25- const extractAndConvert = ( url : string ) => {
26- const match = url . match ( / \/ d \/ ( [ a - z A - Z 0 - 9 - _ ] + ) / ) ;
27- if ( match && match [ 1 ] ) {
25+ const buildOutputUrl = (
26+ url : string ,
27+ password : string ,
28+ selectedMode : 'google-drive' | 'custom-domain' = mode
29+ ) => {
30+ if ( ! url ) return '' ;
31+
32+ if ( selectedMode === 'google-drive' ) {
33+ const match = url . match ( / \/ d \/ ( [ a - z A - Z 0 - 9 - _ ] + ) / ) ;
34+ if ( ! match || ! match [ 1 ] ) return '' ;
35+
2836 const fileId = match [ 1 ] ;
2937 let downloadUrl = `https://drive.google.com/uc?export=download&id=${ fileId } ` ;
30- if ( inputPassword && inputPassword . length > 0 ) {
31- const encoded = encodeBase64Utf8 ( inputPassword ) ;
38+ if ( password && password . length > 0 ) {
39+ const encoded = encodeBase64Utf8 ( password ) ;
3240 if ( encoded ) downloadUrl = `${ downloadUrl } #${ encoded } ` ;
3341 }
34- setOutputUrl ( downloadUrl ) ;
3542 return downloadUrl ;
3643 }
37- setOutputUrl ( '' ) ;
38- return null ;
44+
45+ let customUrl = url ;
46+ if ( password && password . length > 0 ) {
47+ const encoded = encodeBase64Utf8 ( password ) ;
48+ if ( encoded ) customUrl = `${ customUrl } #${ encoded } ` ;
49+ }
50+ return customUrl ;
3951 } ;
4052
4153 const handleInputChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
4254 const value = e . target . value ;
4355 setInputUrl ( value ) ;
44- if ( mode === 'google-drive' ) {
45- extractAndConvert ( value ) ;
46- } else {
47- // For custom domain, just update the output URL directly
48- let customUrl = value ;
49- if ( inputPassword && inputPassword . length > 0 ) {
50- const encoded = encodeBase64Utf8 ( inputPassword ) ;
51- if ( encoded ) customUrl = `${ customUrl } #${ encoded } ` ;
52- }
53- setOutputUrl ( customUrl || '' ) ;
54- }
56+ setOutputUrl ( buildOutputUrl ( value , inputPassword ) ) ;
57+ setCopied ( false ) ;
58+ } ;
59+
60+ const handleUrlPaste = ( e : React . ClipboardEvent < HTMLInputElement > ) => {
61+ const pastedText = e . clipboardData . getData ( 'text' ) ;
62+ if ( ! pastedText ) return ;
63+
64+ const value = pastedText . trim ( ) ;
65+ e . preventDefault ( ) ;
66+ setInputUrl ( value ) ;
67+ setOutputUrl ( buildOutputUrl ( value , inputPassword ) ) ;
5568 setCopied ( false ) ;
5669 } ;
5770
5871 const handlePasswordChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
5972 const value = e . target . value ;
6073 setInputPassword ( value ) ;
61- // Recompute output using the existing URL and new password
62- if ( inputUrl ) {
63- if ( mode === 'google-drive' ) {
64- extractAndConvert ( inputUrl ) ;
65- } else {
66- // For custom domain, recompute with new password
67- let customUrl = inputUrl ;
68- if ( value && value . length > 0 ) {
69- const encoded = encodeBase64Utf8 ( value ) ;
70- if ( encoded ) customUrl = `${ inputUrl } #${ encoded } ` ;
71- }
72- setOutputUrl ( customUrl || '' ) ;
73- }
74- }
74+ setOutputUrl ( buildOutputUrl ( inputUrl , value ) ) ;
7575 setCopied ( false ) ;
7676 } ;
7777
@@ -125,6 +125,7 @@ export function UrlConverter() {
125125 type = "text"
126126 value = { inputUrl }
127127 onChange = { handleInputChange }
128+ onPaste = { handleUrlPaste }
128129 placeholder = {
129130 mode === 'google-drive'
130131 ? 'https://drive.google.com/file/d/YOUR_FILE_ID/view?usp=sharing'
0 commit comments