@@ -10,10 +10,29 @@ interface ApiProcessedProject {
10
10
submittedAt : number ;
11
11
language : string ;
12
12
}
13
+ // Payload for deleting a project cache
14
+ interface DeleteProjectCachePayload {
15
+ owner : string ;
16
+ repo : string ;
17
+ repo_type : string ;
18
+ language : string ;
19
+ }
20
+
21
+ /** Type guard to validate DeleteProjectCachePayload at runtime */
22
+ function isDeleteProjectCachePayload ( obj : any ) : obj is DeleteProjectCachePayload {
23
+ return (
24
+ obj != null &&
25
+ typeof obj . owner === 'string' && obj . owner . trim ( ) !== '' &&
26
+ typeof obj . repo === 'string' && obj . repo . trim ( ) !== '' &&
27
+ typeof obj . repo_type === 'string' && obj . repo_type . trim ( ) !== '' &&
28
+ typeof obj . language === 'string' && obj . language . trim ( ) !== ''
29
+ ) ;
30
+ }
13
31
14
32
// Ensure this matches your Python backend configuration
15
33
const PYTHON_BACKEND_URL = process . env . PYTHON_BACKEND_HOST || 'http://localhost:8001' ;
16
34
const PROJECTS_API_ENDPOINT = `${ PYTHON_BACKEND_URL } /api/processed_projects` ;
35
+ const CACHE_API_ENDPOINT = `${ PYTHON_BACKEND_URL } /api/wiki_cache` ;
17
36
18
37
export async function GET ( ) {
19
38
try {
@@ -50,4 +69,35 @@ export async function GET() {
50
69
{ status : 503 } // Service Unavailable
51
70
) ;
52
71
}
53
- }
72
+ }
73
+
74
+ export async function DELETE ( request : Request ) {
75
+ try {
76
+ const body : unknown = await request . json ( ) ;
77
+ if ( ! isDeleteProjectCachePayload ( body ) ) {
78
+ return NextResponse . json (
79
+ { error : 'Invalid request body: owner, repo, repo_type, and language are required and must be non-empty strings.' } ,
80
+ { status : 400 }
81
+ ) ;
82
+ }
83
+ const { owner, repo, repo_type, language } = body ;
84
+ const params = new URLSearchParams ( { owner, repo, repo_type, language } ) ;
85
+ const response = await fetch ( `${ CACHE_API_ENDPOINT } ?${ params } ` , {
86
+ method : 'DELETE' ,
87
+ headers : { 'Content-Type' : 'application/json' } ,
88
+ } ) ;
89
+ if ( ! response . ok ) {
90
+ let errorBody = { error : response . statusText } ;
91
+ try {
92
+ errorBody = await response . json ( ) ;
93
+ } catch { }
94
+ console . error ( `Error deleting project cache (${ CACHE_API_ENDPOINT } ): ${ response . status } - ${ JSON . stringify ( errorBody ) } ` ) ;
95
+ return NextResponse . json ( errorBody , { status : response . status } ) ;
96
+ }
97
+ return NextResponse . json ( { message : 'Project deleted successfully' } ) ;
98
+ } catch ( error : unknown ) {
99
+ console . error ( 'Error in DELETE /api/wiki/projects:' , error ) ;
100
+ const message = error instanceof Error ? error . message : 'An unknown error occurred' ;
101
+ return NextResponse . json ( { error : `Failed to delete project: ${ message } ` } , { status : 500 } ) ;
102
+ }
103
+ }
0 commit comments