Skip to content

Commit

Permalink
word
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed May 29, 2024
1 parent cd0d7e8 commit a4561b7
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 117 deletions.
14 changes: 0 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { router } from "@/handler";
// import { instrument, ResolveConfigFn } from "@microlabs/otel-cf-workers";

const handler = {
fetch: router.handle,
};

// // eslint-disable-next-line @typescript-eslint/no-unused-vars
// const config: ResolveConfigFn = (env: Env, _trigger) => {
// return {
// exporter: {
// url: "https://otel.baselime.io/v1",
// headers: { "x-api-key": env.BASELIME_API_KEY },
// },
// service: { name: env.SERVICE_NAME },
// };
// };

// export default instrument(handler, config);

export default handler;
31 changes: 0 additions & 31 deletions src/lib/d1/checkRow.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/lib/d1/checkTable.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/lib/d1/getAssetRequests.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/responseHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export const responseHeaders: Record<string, string> = {
"Referrer-Policy": "strict-origin-when-cross-origin",
"content-type": "application/json;charset=UTF-8",
"access-control-allow-origin": "*",
"Cache-Control": `max-age=${60 * 60 * 1}`,
"Cache-Control": `max-age=${60 * 60 * 2}`,
};
14 changes: 4 additions & 10 deletions src/routes/games/getAsset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { responseHeaders } from "@/lib/responseHeaders";
import { listBucket } from "@/lib/listBucket";
import { checkTable } from "@/lib/d1/checkTable";
import { checkRow } from "@/lib/d1/checkRow";
import type { Image } from "@/lib/types/asset";

export const getAsset = async (
Expand Down Expand Up @@ -62,14 +60,10 @@ export const getAsset = async (
size: file.size,
}));

const lastUploaded = images.sort((a, b) => b.uploaded - a.uploaded)[0];

try {
await checkTable(env.database, gameId);
await checkRow(env.database, gameId, asset);
} catch (e) {
console.error(e);
}
const sortedImages = [...images].sort(
(a, b) => b.uploaded - a.uploaded
);
const lastUploaded = sortedImages[0];

response = new Response(
JSON.stringify({
Expand Down
25 changes: 3 additions & 22 deletions src/routes/games/getGameId.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { responseHeaders } from "@/lib/responseHeaders";
import { listBucket } from "@/lib/listBucket";
import { checkTable } from "@/lib/d1/checkTable";
import { getAssetRequests } from "@/lib/d1/getAssetRequests";
import type { Location } from "@/lib/types/game";

export const getGameId = async (
Expand Down Expand Up @@ -48,6 +46,7 @@ export const getGameId = async (
});

const fileCount = subfolderFiles.objects.length;

const lastUploaded = subfolderFiles.objects.reduce(
(prev, current) => {
const prevDate = new Date(prev.uploaded);
Expand All @@ -59,38 +58,20 @@ export const getGameId = async (

const name = file.replace(`${gameId}/`, "").replace("/", "");

try {
await checkTable(env.database, gameId);
} catch (e) {
console.error(e);
}

let popularity = 0;
try {
const requestsCount = await getAssetRequests(
env.database,
gameId,
name
);
popularity = requestsCount;
} catch (e) {
console.error(e);
}

return {
name,
path: `https://api.wanderer.moe/game/${gameId}/${file
.replace(`${gameId}/`, "")
.replace("/", "")}`,
fileCount,
popularity,
popularity: 0,
lastUploaded: lastUploaded.uploaded,
} as Location;
});

const locationsWithFileCount = await Promise.all(locations);
locationsWithFileCount.sort((a, b) => b.popularity - a.popularity);

locationsWithFileCount.sort((a, b) => b.lastUploaded - a.lastUploaded);
locationsWithFileCount.forEach((location, index) => {
location.popularity = index + 1;
});
Expand Down

0 comments on commit a4561b7

Please sign in to comment.