RohanVashisht commited on
Commit
aef2282
·
1 Parent(s): 9206294

fixed api stuff

Browse files
Files changed (2) hide show
  1. src/index.ts +22 -9
  2. src/types.ts +15 -3
src/index.ts CHANGED
@@ -160,12 +160,17 @@ serve({
160
  });
161
  }
162
 
163
- // Get single program/package by owner/repo
164
- const programMatch = pathname.match(/^\/api\/programs\/([^/]+)\/([^/]+)$/);
165
  if (programMatch) {
166
- const owner = programMatch[1]?.toLowerCase() ?? "";
167
- const repo = programMatch[2]?.toLowerCase() ?? "";
168
- const found = findItem(programs, owner, repo);
 
 
 
 
 
169
  if (found) {
170
  const result = { ...found, readme_content: "" };
171
  return Response.json(result, {
@@ -178,11 +183,18 @@ serve({
178
  headers: corsHeaders,
179
  });
180
  }
181
- const packageMatch = pathname.match(/^\/api\/packages\/([^/]+)\/([^/]+)$/);
 
 
182
  if (packageMatch) {
183
- const owner = packageMatch[1]?.toLowerCase() ?? "";
184
- const repo = packageMatch[2]?.toLowerCase() ?? "";
185
- const found = findItem(packages, owner, repo);
 
 
 
 
 
186
  if (found) {
187
  const result = { ...found, readme_content: "" };
188
  return Response.json(result, {
@@ -196,6 +208,7 @@ serve({
196
  });
197
  }
198
 
 
199
  // Index details endpoints
200
  if (pathname === "/api/indexDetailsPackages") {
201
  const section = searchParams.get("section");
 
160
  });
161
  }
162
 
163
+ // Get single program by repo_from/owner/repo
164
+ const programMatch = pathname.match(/^\/api\/programs\/([^/]+)\/([^/]+)\/([^/]+)$/);
165
  if (programMatch) {
166
+ const repo_from = programMatch[1]?.toLowerCase() ?? "";
167
+ const owner = programMatch[2]?.toLowerCase() ?? "";
168
+ const repo = programMatch[3]?.toLowerCase() ?? "";
169
+ const found = programs.find(
170
+ (item) =>
171
+ item.repo_from?.toLowerCase() === repo_from &&
172
+ item.full_name?.toLowerCase() === `${owner}/${repo}`
173
+ );
174
  if (found) {
175
  const result = { ...found, readme_content: "" };
176
  return Response.json(result, {
 
183
  headers: corsHeaders,
184
  });
185
  }
186
+
187
+ // Get single package by repo_from/owner/repo
188
+ const packageMatch = pathname.match(/^\/api\/packages\/([^/]+)\/([^/]+)\/([^/]+)$/);
189
  if (packageMatch) {
190
+ const repo_from = packageMatch[1]?.toLowerCase() ?? "";
191
+ const owner = packageMatch[2]?.toLowerCase() ?? "";
192
+ const repo = packageMatch[3]?.toLowerCase() ?? "";
193
+ const found = packages.find(
194
+ (item) =>
195
+ item.repo_from?.toLowerCase() === repo_from &&
196
+ item.full_name?.toLowerCase() === `${owner}/${repo}`
197
+ );
198
  if (found) {
199
  const result = { ...found, readme_content: "" };
200
  return Response.json(result, {
 
208
  });
209
  }
210
 
211
+
212
  // Index details endpoints
213
  if (pathname === "/api/indexDetailsPackages") {
214
  const section = searchParams.get("section");
src/types.ts CHANGED
@@ -1,9 +1,10 @@
1
  export interface Repo {
2
- avatar_url: string;
 
3
  name: string;
4
  full_name: string;
5
  created_at: string;
6
- description: string;
7
  default_branch: string;
8
  open_issues: number;
9
  stargazers_count: number;
@@ -11,11 +12,22 @@ export interface Repo {
11
  watchers_count: number;
12
  tags_url: string;
13
  license: string;
14
- topics: string[] | null;
15
  size: number;
16
  fork: boolean;
17
  updated_at: string;
18
  has_build_zig: boolean;
19
  has_build_zig_zon: boolean;
 
 
 
20
  readme_content: string;
 
 
 
 
 
 
 
 
21
  }
 
1
  export interface Repo {
2
+ content_is_correct?: boolean;
3
+ avatar_url: string | null;
4
  name: string;
5
  full_name: string;
6
  created_at: string;
7
+ description?: string | null;
8
  default_branch: string;
9
  open_issues: number;
10
  stargazers_count: number;
 
12
  watchers_count: number;
13
  tags_url: string;
14
  license: string;
15
+ topics?: string[] | null;
16
  size: number;
17
  fork: boolean;
18
  updated_at: string;
19
  has_build_zig: boolean;
20
  has_build_zig_zon: boolean;
21
+ zig_minimum_version: string;
22
+ repo_from: string;
23
+ dependencies?: (DependenciesEntity | null)[] | null;
24
  readme_content: string;
25
+ dependents?: (string | null)[] | null;
26
+ }
27
+ export interface DependenciesEntity {
28
+ name: string;
29
+ url: string;
30
+ commit?: string | null;
31
+ tar_url?: string | null;
32
+ type: string;
33
  }