@@ -3,6 +3,35 @@ import { getSupabaseAdmin } from "@/lib/supabase";
33
44type RouteContext = { params : Promise < { slug : string } > } ;
55
6+ const MODULE_INSTALL_COLUMNS =
7+ "id, name, slug, version, downloads, git_url, min_threatcrush_version, os_support, license" ;
8+
9+ function installPayload ( mod : {
10+ name : string ;
11+ slug : string ;
12+ version : string ;
13+ downloads ?: number | null ;
14+ git_url ?: string | null ;
15+ min_threatcrush_version ?: string | null ;
16+ os_support ?: string [ ] | null ;
17+ license ?: string | null ;
18+ } ) {
19+ return {
20+ name : mod . name ,
21+ slug : mod . slug ,
22+ version : mod . version ,
23+ downloads : mod . downloads || 0 ,
24+ license : mod . license ,
25+ min_threatcrush_version : mod . min_threatcrush_version ,
26+ os_support : mod . os_support ,
27+ install : {
28+ npm_package : null ,
29+ git_url : mod . git_url || null ,
30+ tarball_url : null ,
31+ } ,
32+ } ;
33+ }
34+
635/**
736 * GET /api/modules/[slug]/install
837 * Query module install info without incrementing download count.
@@ -16,7 +45,7 @@ export async function GET(
1645
1746 const { data : mod , error : modError } = await sb
1847 . from ( "modules" )
19- . select ( "id, name, slug, version, downloads, git_url, npm_package, tarball_url, min_threatcrush_version, os_support, license" )
48+ . select ( MODULE_INSTALL_COLUMNS )
2049 . eq ( "slug" , slug )
2150 . eq ( "published" , true )
2251 . single ( ) ;
@@ -26,20 +55,7 @@ export async function GET(
2655 }
2756
2857 return NextResponse . json ( {
29- module : {
30- name : mod . name ,
31- slug : mod . slug ,
32- version : mod . version ,
33- downloads : mod . downloads || 0 ,
34- license : mod . license ,
35- min_threatcrush_version : mod . min_threatcrush_version ,
36- os_support : mod . os_support ,
37- install : {
38- npm_package : mod . npm_package || null ,
39- git_url : mod . git_url || null ,
40- tarball_url : mod . tarball_url || null ,
41- } ,
42- } ,
58+ module : installPayload ( mod ) ,
4359 } ) ;
4460}
4561
@@ -63,7 +79,7 @@ export async function POST(
6379 // Get module with full install info
6480 const { data : mod , error : modError } = await sb
6581 . from ( "modules" )
66- . select ( "id, name, slug, version, downloads, git_url, npm_package, tarball_url, min_threatcrush_version, os_support, license" )
82+ . select ( MODULE_INSTALL_COLUMNS )
6783 . eq ( "slug" , slug )
6884 . eq ( "published" , true )
6985 . single ( ) ;
@@ -90,18 +106,6 @@ export async function POST(
90106 return NextResponse . json ( {
91107 success : true ,
92108 downloads : newCount ,
93- module : {
94- name : mod . name ,
95- slug : mod . slug ,
96- version : mod . version ,
97- license : mod . license ,
98- min_threatcrush_version : mod . min_threatcrush_version ,
99- os_support : mod . os_support ,
100- install : {
101- npm_package : mod . npm_package || null ,
102- git_url : mod . git_url || null ,
103- tarball_url : mod . tarball_url || null ,
104- } ,
105- } ,
109+ module : installPayload ( { ...mod , downloads : newCount } ) ,
106110 } ) ;
107111}
0 commit comments