File tree Expand file tree Collapse file tree 1 file changed +7
-21
lines changed
Expand file tree Collapse file tree 1 file changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -40,37 +40,23 @@ const FeedbackImage = ({ url }: Props) => {
4040 } ) ;
4141
4242 const imageKey = useMemo ( ( ) => {
43- if ( ! channelData ?. imageConfig ?. enablePresignedUrlDownload ) return url ;
43+ if ( ! channelData ?. imageConfig ?. enablePresignedUrlDownload ) return '' ;
4444
45- let parsed : URL | null = null ;
46- try {
47- parsed = new URL (
48- url ,
49- typeof window !== 'undefined' ?
50- window . location . href
51- : 'http://localhost' ,
52- ) ;
53- } catch {
54- return url ;
55- }
56- if ( ! / ^ h t t p s ? : $ / . test ( parsed . protocol ) ) return url ;
45+ const s3Pattern = / ( s 3 [ . - ] [ a - z 0 - 9 - ] + \. a m a z o n a w s \. c o m | s 3 \. a m a z o n a w s \. c o m ) / ;
46+ if ( ! s3Pattern . test ( url ) ) return '' ;
5747
58- const rawPath = parsed . pathname . replace ( / ^ \/ + / , '' ) ;
59- let key = rawPath ;
60- try {
61- key = decodeURIComponent ( rawPath ) ;
62- } catch {
63- /* keep raw */
64- }
48+ const parsedUrl = new URL ( url ) ;
49+ const key = decodeURIComponent ( parsedUrl . pathname . replace ( / ^ \/ + / , '' ) ) ;
50+ const host = parsedUrl . hostname ;
6551
66- const host = parsed . hostname ;
6752 const parts = key . split ( '/' , 2 ) ;
6853 if (
6954 ( host === 's3.amazonaws.com' || host . startsWith ( 's3.' ) ) &&
7055 parts . length >= 2
7156 ) {
7257 return parts . slice ( 1 ) . join ( '/' ) ;
7358 }
59+
7460 return key ;
7561 } , [ channelData , url ] ) ;
7662
You can’t perform that action at this time.
0 commit comments