File tree Expand file tree Collapse file tree
apps/www/src/app/api/bump/plugin/[slug] Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { FieldValue } from 'firebase-admin/firestore' ;
22import { Database } from '../../../Firebase' ;
3+ import { FetchPlugins } from '../../v1/plugins/GetPlugins' ;
34
45function withCORS ( response : Response ) : Response {
56 response . headers . set ( 'Access-Control-Allow-Origin' , 'https://steamloopback.host' ) ;
@@ -15,7 +16,14 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
1516 }
1617
1718 try {
18- const docRef = Database . collection ( 'downloads' ) . doc ( slug ) ;
19+ const { pluginData } = await FetchPlugins ( ) ;
20+ const plugin = pluginData . find ( ( p ) => p . id === slug || p . initCommitId === slug ) ;
21+
22+ if ( ! plugin ) {
23+ return withCORS ( new Response ( JSON . stringify ( { success : false , message : 'Plugin not found' } ) , { status : 404 } ) ) ;
24+ }
25+
26+ const docRef = Database . collection ( 'downloads' ) . doc ( plugin . initCommitId ) ;
1927 await docRef . set ( { downloadCount : FieldValue . increment ( 1 ) } , { merge : true } ) ;
2028
2129 const updatedDoc = await docRef . get ( ) ;
You can’t perform that action at this time.
0 commit comments