Commit
·
9013903
1
Parent(s):
365cae3
fixed types and added readme to search
Browse files- src/index.ts +15 -57
- src/types.ts +21 -34
src/index.ts
CHANGED
@@ -1,46 +1,5 @@
|
|
1 |
import { serve } from "bun";
|
2 |
-
|
3 |
-
// --- Interfaces ---
|
4 |
-
|
5 |
-
export interface Dependency {
|
6 |
-
name: string;
|
7 |
-
source: "relative" | "remote";
|
8 |
-
location: string;
|
9 |
-
}
|
10 |
-
|
11 |
-
export interface DeepSearchData {
|
12 |
-
[key: string]: string;
|
13 |
-
}
|
14 |
-
|
15 |
-
export interface Item {
|
16 |
-
avatar_url: string;
|
17 |
-
name: string;
|
18 |
-
full_name: string;
|
19 |
-
created_at: string;
|
20 |
-
description?: string | null;
|
21 |
-
default_branch?: string;
|
22 |
-
open_issues: number;
|
23 |
-
stargazers_count: number;
|
24 |
-
forks_count: number;
|
25 |
-
watchers_count: number;
|
26 |
-
contentIsCorrect?: boolean;
|
27 |
-
tags_url: string;
|
28 |
-
license: string;
|
29 |
-
readme_content: string;
|
30 |
-
specials?: string;
|
31 |
-
topics?: string[];
|
32 |
-
size: number;
|
33 |
-
has_build_zig_zon?: boolean;
|
34 |
-
has_build_zig?: boolean;
|
35 |
-
fork: boolean;
|
36 |
-
updated_at: string;
|
37 |
-
dependencies?: Dependency[];
|
38 |
-
berg?: number;
|
39 |
-
gitlab?: number;
|
40 |
-
archived?: boolean;
|
41 |
-
}
|
42 |
-
|
43 |
-
// --- Constants ---
|
44 |
|
45 |
const packagesUrls = [
|
46 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/games.json",
|
@@ -52,18 +11,17 @@ const packagesUrls = [
|
|
52 |
const programsUrl =
|
53 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/programs.json";
|
54 |
|
55 |
-
// --- Data Loading ---
|
56 |
|
57 |
-
let packages:
|
58 |
-
let programs:
|
59 |
|
60 |
async function loadData() {
|
61 |
const packagesFile = await Promise.all(packagesUrls.map((url) => fetch(url)));
|
62 |
packages = (await Promise.all(packagesFile.map((file) => file.json())))
|
63 |
-
.flat() as
|
64 |
|
65 |
const programsFile = await fetch(programsUrl);
|
66 |
-
programs = (await programsFile.json()) as
|
67 |
console.log("Data loaded");
|
68 |
}
|
69 |
|
@@ -79,16 +37,16 @@ const corsHeaders: Record<string, string> = {
|
|
79 |
};
|
80 |
|
81 |
// --- Sorting Helpers ---
|
82 |
-
const sortByDate = (a:
|
83 |
new Date(b.created_at ?? "").getTime() - new Date(a.created_at ?? "").getTime();
|
84 |
|
85 |
-
const sortByUsage = (a:
|
86 |
(b.stargazers_count ?? 0) - (a.stargazers_count ?? 0);
|
87 |
|
88 |
// --- Pre-sorted Data ---
|
89 |
function getSorted() {
|
90 |
-
const packagesArray = packages as
|
91 |
-
const programsArray = programs as
|
92 |
|
93 |
return {
|
94 |
packages: {
|
@@ -104,28 +62,28 @@ function getSorted() {
|
|
104 |
|
105 |
// --- Filtering ---
|
106 |
function filterItems(
|
107 |
-
items:
|
108 |
q: string | null,
|
109 |
filter: string | null
|
110 |
-
):
|
111 |
-
return items.filter(({ name, full_name, description, topics }) => {
|
112 |
if (filter && !topics?.some((t) => t.toLowerCase() === filter)) return false;
|
113 |
if (!q) return true;
|
114 |
const lowerQ = q.toLowerCase();
|
115 |
-
return [name, full_name, description, ...(topics ?? [])].some((field) =>
|
116 |
field?.toLowerCase().includes(lowerQ)
|
117 |
);
|
118 |
});
|
119 |
}
|
120 |
|
121 |
// --- Pagination ---
|
122 |
-
function getPaginated(items:
|
123 |
const start = page * size;
|
124 |
return items.slice(start, start + size);
|
125 |
}
|
126 |
|
127 |
// --- Find by Owner/Repo ---
|
128 |
-
function findItem(items:
|
129 |
return items.find(
|
130 |
({ full_name }) => full_name?.toLowerCase() === `${owner}/${repo}`
|
131 |
);
|
|
|
1 |
import { serve } from "bun";
|
2 |
+
import { type Repo } from "./types.ts";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
const packagesUrls = [
|
5 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/games.json",
|
|
|
11 |
const programsUrl =
|
12 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/programs.json";
|
13 |
|
|
|
14 |
|
15 |
+
let packages: Repo[] = [];
|
16 |
+
let programs: Repo[] = [];
|
17 |
|
18 |
async function loadData() {
|
19 |
const packagesFile = await Promise.all(packagesUrls.map((url) => fetch(url)));
|
20 |
packages = (await Promise.all(packagesFile.map((file) => file.json())))
|
21 |
+
.flat() as Repo[];
|
22 |
|
23 |
const programsFile = await fetch(programsUrl);
|
24 |
+
programs = (await programsFile.json()) as Repo[];
|
25 |
console.log("Data loaded");
|
26 |
}
|
27 |
|
|
|
37 |
};
|
38 |
|
39 |
// --- Sorting Helpers ---
|
40 |
+
const sortByDate = (a: Repo, b: Repo) =>
|
41 |
new Date(b.created_at ?? "").getTime() - new Date(a.created_at ?? "").getTime();
|
42 |
|
43 |
+
const sortByUsage = (a: Repo, b: Repo) =>
|
44 |
(b.stargazers_count ?? 0) - (a.stargazers_count ?? 0);
|
45 |
|
46 |
// --- Pre-sorted Data ---
|
47 |
function getSorted() {
|
48 |
+
const packagesArray = packages as Repo[];
|
49 |
+
const programsArray = programs as Repo[];
|
50 |
|
51 |
return {
|
52 |
packages: {
|
|
|
62 |
|
63 |
// --- Filtering ---
|
64 |
function filterItems(
|
65 |
+
items: Repo[],
|
66 |
q: string | null,
|
67 |
filter: string | null
|
68 |
+
): Repo[] {
|
69 |
+
return items.filter(({ name, full_name, description, topics, readme_content }) => {
|
70 |
if (filter && !topics?.some((t) => t.toLowerCase() === filter)) return false;
|
71 |
if (!q) return true;
|
72 |
const lowerQ = q.toLowerCase();
|
73 |
+
return [name, full_name, description, ...(topics ?? []), readme_content].some((field) =>
|
74 |
field?.toLowerCase().includes(lowerQ)
|
75 |
);
|
76 |
});
|
77 |
}
|
78 |
|
79 |
// --- Pagination ---
|
80 |
+
function getPaginated(items: Repo[], page = 0, size = 10): Repo[] {
|
81 |
const start = page * size;
|
82 |
return items.slice(start, start + size);
|
83 |
}
|
84 |
|
85 |
// --- Find by Owner/Repo ---
|
86 |
+
function findItem(items: Repo[], owner: string, repo: string): Repo | undefined {
|
87 |
return items.find(
|
88 |
({ full_name }) => full_name?.toLowerCase() === `${owner}/${repo}`
|
89 |
);
|
src/types.ts
CHANGED
@@ -1,34 +1,21 @@
|
|
1 |
-
export interface
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
specials?: string;
|
23 |
-
topics?: string[];
|
24 |
-
size: number;
|
25 |
-
has_build_zig_zon?: boolean;
|
26 |
-
has_build_zig?: boolean;
|
27 |
-
fork: boolean;
|
28 |
-
updated_at: string;
|
29 |
-
dependencies?: Dependency[];
|
30 |
-
berg?: number;
|
31 |
-
gitlab?: number;
|
32 |
-
archived?: boolean;
|
33 |
-
owner?: string; // Added for findItem compatibility
|
34 |
-
}
|
|
|
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;
|
10 |
+
forks_count: number;
|
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 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|