File tree Expand file tree Collapse file tree 4 files changed +10
-4
lines changed
app/api/bucket/[bucket]/[key]
components/object-explorer Expand file tree Collapse file tree 4 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { getBucket } from '@/utils/cf' ;
2
2
import { getSettingsRecord } from '@/utils/db/queries' ;
3
+ import { decode } from '@/utils/encoding' ;
3
4
4
5
export const runtime = 'edge' ;
5
6
@@ -14,7 +15,7 @@ export const GET = async (
14
15
return new Response ( 'Unable to read bucket' , { status : 400 } ) ;
15
16
}
16
17
17
- const path = atob ( key ) ;
18
+ const path = decode ( key ) ;
18
19
19
20
const [ , start , end ] = / ^ b y t e s = ( \d + ) - ( \d + ) ? $ / . exec ( req . headers . get ( 'range' ) ?? '' ) ?? [ ] ;
20
21
@@ -73,7 +74,7 @@ export const POST = async (
73
74
return new Response ( 'Unable to read bucket' , { status : 400 } ) ;
74
75
}
75
76
76
- const path = atob ( key ) ;
77
+ const path = decode ( key ) ;
77
78
78
79
const object = await bucket . head ( path ) ;
79
80
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { addLeadingSlash } from '@/utils';
2
2
import type { FileType } from '@/utils' ;
3
3
import { memo } from 'react' ;
4
4
import { twMerge } from 'tailwind-merge' ;
5
+ import { encode } from '@/utils/encoding' ;
5
6
import { useLocation } from '../providers' ;
6
7
import { getFileIcon } from './file-icons' ;
7
8
@@ -21,7 +22,7 @@ export const ObjectPreviewInner = memo(
21
22
const { currentBucket } = useLocation ( ) ;
22
23
if ( ! currentBucket || ! path || ! itemType ) return null ;
23
24
24
- const itemApiSrc = `/api/bucket/${ currentBucket ?. raw } ${ addLeadingSlash ( btoa ( path ) ) } ` ;
25
+ const itemApiSrc = `/api/bucket/${ currentBucket ?. raw } ${ addLeadingSlash ( encode ( path ) ) } ` ;
25
26
26
27
switch ( itemType ) {
27
28
case 'image' : {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
14
14
MediaTimeRange ,
15
15
MediaVolumeRange ,
16
16
} from 'media-chrome/react' ;
17
+ import { encode } from '@/utils/encoding' ;
17
18
import { useLocation , useObjectExplorer } from '../providers' ;
18
19
19
20
export const ObjectPreview = ( ) : JSX . Element => {
@@ -31,7 +32,7 @@ export const ObjectPreview = (): JSX.Element => {
31
32
const [ objectStr , setObjectStr ] = useState < string | null > ( null ) ;
32
33
33
34
const rawPreviewKey = selectedObjects . keys ( ) . next ( ) . value ;
34
- const previewKey = rawPreviewKey ? btoa ( rawPreviewKey ) : undefined ;
35
+ const previewKey = rawPreviewKey ? encode ( rawPreviewKey ) : undefined ;
35
36
36
37
useEffect ( ( ) => {
37
38
if ( ! isPreviewActive || ! currentBucket ) return ;
Original file line number Diff line number Diff line change
1
+ export const encode = ( v : string ) => btoa ( encodeURIComponent ( v ) ) ;
2
+
3
+ export const decode = ( v : string ) => atob ( decodeURIComponent ( v ) ) ;
You can’t perform that action at this time.
0 commit comments