Commit
·
9206294
1
Parent(s):
9050040
removed readme to make search results returning faster.
Browse files- src/index.ts +36 -11
src/index.ts
CHANGED
@@ -8,7 +8,6 @@ const packagesUrls = [
|
|
8 |
const programsUrl =
|
9 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/programs.json";
|
10 |
|
11 |
-
|
12 |
let packages: Repo[] = [];
|
13 |
let programs: Repo[] = [];
|
14 |
|
@@ -40,6 +39,14 @@ const sortByDate = (a: Repo, b: Repo) =>
|
|
40 |
const sortByUsage = (a: Repo, b: Repo) =>
|
41 |
(b.stargazers_count ?? 0) - (a.stargazers_count ?? 0);
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
// --- Pre-sorted Data ---
|
44 |
function getSorted() {
|
45 |
const packagesArray = packages as Repo[];
|
@@ -120,11 +127,11 @@ serve({
|
|
120 |
// Search endpoints
|
121 |
if (pathname === "/api/searchPackages") {
|
122 |
const result = filterItems(packages, q, filter).slice(0, 25);
|
123 |
-
return Response.json(result, { headers: corsHeaders });
|
124 |
}
|
125 |
if (pathname === "/api/searchPrograms") {
|
126 |
const result = filterItems(programs, q, filter).slice(0, 25);
|
127 |
-
return Response.json(result, { headers: corsHeaders });
|
128 |
}
|
129 |
|
130 |
// Infinite scroll endpoints
|
@@ -135,7 +142,8 @@ serve({
|
|
135 |
{ error: "Invalid page number" },
|
136 |
{ status: 400, headers: corsHeaders }
|
137 |
);
|
138 |
-
|
|
|
139 |
headers: corsHeaders,
|
140 |
});
|
141 |
}
|
@@ -146,7 +154,8 @@ serve({
|
|
146 |
{ error: "Invalid page number" },
|
147 |
{ status: 400, headers: corsHeaders }
|
148 |
);
|
149 |
-
|
|
|
150 |
headers: corsHeaders,
|
151 |
});
|
152 |
}
|
@@ -157,8 +166,15 @@ serve({
|
|
157 |
const owner = programMatch[1]?.toLowerCase() ?? "";
|
158 |
const repo = programMatch[2]?.toLowerCase() ?? "";
|
159 |
const found = findItem(programs, owner, repo);
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
headers: corsHeaders,
|
163 |
});
|
164 |
}
|
@@ -167,8 +183,15 @@ serve({
|
|
167 |
const owner = packageMatch[1]?.toLowerCase() ?? "";
|
168 |
const repo = packageMatch[2]?.toLowerCase() ?? "";
|
169 |
const found = findItem(packages, owner, repo);
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
headers: corsHeaders,
|
173 |
});
|
174 |
}
|
@@ -185,7 +208,8 @@ serve({
|
|
185 |
const sortKey = section === "latestRepos" ? "latest" : "mostUsed";
|
186 |
const data = sorted.packages[sortKey as keyof typeof sorted.packages] ?? packages;
|
187 |
const [start, end] = parseRange(searchParams.get("range"), data.length);
|
188 |
-
|
|
|
189 |
}
|
190 |
if (pathname === "/api/indexDetailsPrograms") {
|
191 |
const section = searchParams.get("section");
|
@@ -198,7 +222,8 @@ serve({
|
|
198 |
const sortKey = section === "latestRepos" ? "latest" : "mostUsed";
|
199 |
const data = sorted.programs[sortKey as keyof typeof sorted.programs] ?? programs;
|
200 |
const [start, end] = parseRange(searchParams.get("range"), data.length);
|
201 |
-
|
|
|
202 |
}
|
203 |
|
204 |
// Not found
|
|
|
8 |
const programsUrl =
|
9 |
"https://raw.githubusercontent.com/Zigistry/database/refs/heads/main/database/programs.json";
|
10 |
|
|
|
11 |
let packages: Repo[] = [];
|
12 |
let programs: Repo[] = [];
|
13 |
|
|
|
39 |
const sortByUsage = (a: Repo, b: Repo) =>
|
40 |
(b.stargazers_count ?? 0) - (a.stargazers_count ?? 0);
|
41 |
|
42 |
+
// --- Helper to remove readme content ---
|
43 |
+
function removeReadmeContent(repos: Repo[]): Repo[] {
|
44 |
+
return repos.map(repo => ({
|
45 |
+
...repo,
|
46 |
+
readme_content: ""
|
47 |
+
}));
|
48 |
+
}
|
49 |
+
|
50 |
// --- Pre-sorted Data ---
|
51 |
function getSorted() {
|
52 |
const packagesArray = packages as Repo[];
|
|
|
127 |
// Search endpoints
|
128 |
if (pathname === "/api/searchPackages") {
|
129 |
const result = filterItems(packages, q, filter).slice(0, 25);
|
130 |
+
return Response.json(removeReadmeContent(result), { headers: corsHeaders });
|
131 |
}
|
132 |
if (pathname === "/api/searchPrograms") {
|
133 |
const result = filterItems(programs, q, filter).slice(0, 25);
|
134 |
+
return Response.json(removeReadmeContent(result), { headers: corsHeaders });
|
135 |
}
|
136 |
|
137 |
// Infinite scroll endpoints
|
|
|
142 |
{ error: "Invalid page number" },
|
143 |
{ status: 400, headers: corsHeaders }
|
144 |
);
|
145 |
+
const result = getPaginated(packages, page);
|
146 |
+
return Response.json(removeReadmeContent(result), {
|
147 |
headers: corsHeaders,
|
148 |
});
|
149 |
}
|
|
|
154 |
{ error: "Invalid page number" },
|
155 |
{ status: 400, headers: corsHeaders }
|
156 |
);
|
157 |
+
const result = getPaginated(programs, page);
|
158 |
+
return Response.json(removeReadmeContent(result), {
|
159 |
headers: corsHeaders,
|
160 |
});
|
161 |
}
|
|
|
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, {
|
172 |
+
status: 200,
|
173 |
+
headers: corsHeaders,
|
174 |
+
});
|
175 |
+
}
|
176 |
+
return Response.json({ error: "Program not found" }, {
|
177 |
+
status: 404,
|
178 |
headers: corsHeaders,
|
179 |
});
|
180 |
}
|
|
|
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, {
|
189 |
+
status: 200,
|
190 |
+
headers: corsHeaders,
|
191 |
+
});
|
192 |
+
}
|
193 |
+
return Response.json({ error: "Package not found" }, {
|
194 |
+
status: 404,
|
195 |
headers: corsHeaders,
|
196 |
});
|
197 |
}
|
|
|
208 |
const sortKey = section === "latestRepos" ? "latest" : "mostUsed";
|
209 |
const data = sorted.packages[sortKey as keyof typeof sorted.packages] ?? packages;
|
210 |
const [start, end] = parseRange(searchParams.get("range"), data.length);
|
211 |
+
const result = data.slice(start, end);
|
212 |
+
return Response.json(removeReadmeContent(result), { headers: corsHeaders });
|
213 |
}
|
214 |
if (pathname === "/api/indexDetailsPrograms") {
|
215 |
const section = searchParams.get("section");
|
|
|
222 |
const sortKey = section === "latestRepos" ? "latest" : "mostUsed";
|
223 |
const data = sorted.programs[sortKey as keyof typeof sorted.programs] ?? programs;
|
224 |
const [start, end] = parseRange(searchParams.get("range"), data.length);
|
225 |
+
const result = data.slice(start, end);
|
226 |
+
return Response.json(removeReadmeContent(result), { headers: corsHeaders });
|
227 |
}
|
228 |
|
229 |
// Not found
|