@@ -33,6 +33,7 @@ function sanitize(config: Record<string, string>): Config {
3333 font : "baloo_2" ,
3434 animation : true ,
3535 theme : { light : "light" , dark : "dark" } ,
36+ cache : 60 ,
3637 } ;
3738
3839 if ( ! config . username ?. trim ( ) ) {
@@ -110,13 +111,14 @@ function sanitize(config: Record<string, string>): Config {
110111 sanitized . extensions . push ( RemoteStyleExtension ) ;
111112 }
112113
114+ if ( config . cache && parseInt ( config . cache ) >= 0 && parseInt ( config . cache ) <= 60 * 60 * 24 * 7 ) {
115+ sanitized . cache = parseInt ( config . cache ) ;
116+ }
117+
113118 return sanitized ;
114119}
115120
116121async function generate ( config : Record < string , string > ) : Promise < Response > {
117- const generator = new Generator ( new Cache ( ) ) ;
118- generator . verbose = true ;
119-
120122 let sanitized : Config ;
121123 try {
122124 sanitized = sanitize ( config ) ;
@@ -131,6 +133,9 @@ async function generate(config: Record<string, string>): Promise<Response> {
131133 const cache_header =
132134 `max-age=${ cache_time } ` + ( cache_time <= 0 ? ", no-store, no-cache" : ", public" ) ;
133135
136+ const generator = new Generator ( new Cache ( sanitized . cache ) ) ;
137+ generator . verbose = true ;
138+
134139 const headers = new Header ( ) . add ( "cors" , "svg" ) ;
135140 headers . set ( "cache-control" , cache_header ) ;
136141
@@ -157,6 +162,18 @@ router.get("*", async ({ query }: { query: Record<string, string> }) => {
157162 return await generate ( query ) ;
158163} ) ;
159164
165+ router . delete ( "/:site/:username" , async ( { params } ) => {
166+ if ( params ?. site && params ?. username ) {
167+ const site = params . site . toLowerCase ( ) ;
168+ const username = params . username . toLowerCase ( ) ;
169+ const cache = new Cache ( 60 ) ;
170+ return new Response (
171+ JSON . stringify ( { success : await cache . delete ( `data-${ username } -${ site } ` ) } , null , 4 ) ,
172+ { headers : new Header ( ) . add ( "cors" , "json" ) } ,
173+ ) ;
174+ }
175+ } ) ;
176+
160177// 404 for all other routes
161178router . all ( "*" , ( ) => new Response ( "Not Found." , { status : 404 } ) ) ;
162179
0 commit comments