Commit e0fa1e9 1 parent e79c165 commit e0fa1e9 Copy full SHA for e0fa1e9
File tree 3 files changed +56
-27
lines changed
3 files changed +56
-27
lines changed Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+ import { z } from 'zod' ;
3
+
4
+ import { highlightFiles } from '@/lib/highlight-code' ;
5
+ import { getRegistryItem } from '@/lib/registry' ;
6
+
7
+ const ParamsSchema = z . object ( {
8
+ name : z . string ( ) . min ( 1 , 'Name parameter is required' ) ,
9
+ } ) ;
10
+
11
+ export async function GET ( _ : Request , { params } : any ) {
12
+ try {
13
+ const { name } = ParamsSchema . parse ( { name : params . name } ) ;
14
+
15
+ const item = await getRegistryItem ( name ) ;
16
+
17
+ if ( ! item ?. files ) {
18
+ return NextResponse . json ( { files : null } ) ;
19
+ }
20
+
21
+ const highlightedFiles = await highlightFiles ( item . files ) ;
22
+
23
+ return NextResponse . json ( {
24
+ files : highlightedFiles ,
25
+ } ) ;
26
+ } catch ( error ) {
27
+ if ( error instanceof z . ZodError ) {
28
+ console . error ( 'Failed to get registry files:' , error . issues [ 0 ] . message ) ;
29
+
30
+ return NextResponse . json (
31
+ { error : error . issues [ 0 ] . message } ,
32
+ { status : 400 }
33
+ ) ;
34
+ }
35
+
36
+ console . error ( 'Failed to get registry files:' , error ) ;
37
+
38
+ return NextResponse . json (
39
+ { error : 'Failed to get registry files' } ,
40
+ { status : 500 }
41
+ ) ;
42
+ }
43
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ import {
29
29
} from 'lucide-react' ;
30
30
import Link from 'next/link' ;
31
31
32
- import { getHighlightedFiles } from '@/components/block-actions' ;
33
32
import { CopyNpmCommandButton } from '@/components/copy-button' ;
34
33
import {
35
34
Collapsible ,
@@ -132,11 +131,20 @@ function BlockViewerProvider({
132
131
setIsLoading ( true ) ;
133
132
134
133
try {
135
- const files = await getHighlightedFiles ( item . name ) ;
136
- setHighlightedFiles ( files ) ;
134
+ const response = await fetch (
135
+ `/api/registry/${ encodeURIComponent ( item . name ) } `
136
+ ) ;
137
+ const data = await response . json ( ) ;
137
138
138
- if ( ! activeFile && files ?. length ) {
139
- setActiveFile ( files [ 0 ] . target ! ) ;
139
+ if ( ! response . ok ) {
140
+ throw new Error ( data . error || 'Failed to fetch files' ) ;
141
+ }
142
+ if ( data . files ) {
143
+ setHighlightedFiles ( data . files ) ;
144
+
145
+ if ( ! activeFile && data . files ?. length ) {
146
+ setActiveFile ( data . files [ 0 ] . target ! ) ;
147
+ }
140
148
}
141
149
} catch ( error ) {
142
150
console . error ( 'Failed to load files:' , error ) ;
You can’t perform that action at this time.
0 commit comments