Skip to content

Commit

Permalink
add mod-search-database dev api endpoint
Browse files Browse the repository at this point in the history
-updates the local on-disk copy of the mod search database
-only works in dev
-no authentication
  • Loading branch information
otobot1 committed Aug 10, 2024
1 parent f8cce0c commit 351e12a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { NextResponse, type NextRequest } from "next/server";
import { serverLogger as logger } from "~/logger/serverLogger";
import { getUpdatedModSearchDatabase } from "~/server/gamebananaMirror/yamlHandlers/modSearchDatabase";




/** Handle actual update webhook requests */
export const GET = async (_req: NextRequest) => {
if (process.env.NODE_ENV !== "development") return new NextResponse(
"Not Found",
{
status: 404,
}
);


logger.info("Updating the Mod Search Database.");

try {
await getUpdatedModSearchDatabase();
} catch (error) {
let errorMessage: string;

if (typeof error === "string") {
errorMessage = error; // Error strings are logged in the getUpdatedYaml function
} else {
logger.error(`Failed to update the Mod Search Database. ${error}`);

errorMessage = "An unknown error occurred while updating the Mod Search Database.";
}


return new NextResponse(
errorMessage,
{
status: 500,
}
);
}


const message = "The Mod Search Database has been updated.";

logger.info(message);

return new NextResponse(
message,
{
status: 200,
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCurrentYaml, getFileSystemErrorString, getUpdatedYaml } from "./util

const EVEREST_UPDATE_DATABASE_YAML_URL = "https://maddie480.ovh/celeste/everest_update.yaml";

const EVEREST_UPDATE_DATABASE_JSON_PATH = process.env.EVEREST_UPDATE_DATABASE_PATH || "";
const EVEREST_UPDATE_DATABASE_JSON_PATH = process.env.EVEREST_UPDATE_DATABASE_JSON_PATH || "";


const EVEREST_UPDATE_DATABASE_YAML_NAME = "Everest Update Database";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCurrentYaml, getFileSystemErrorString, getUpdatedYaml } from "./util

const MOD_SEARCH_DATABASE_YAML_URL = "https://maddie480.ovh/celeste/mod_search_database.yaml";

const MOD_SEARCH_DATABASE_JSON_PATH = process.env.MOD_SEARCH_DATABASE_PATH || "";
const MOD_SEARCH_DATABASE_JSON_PATH = process.env.MOD_SEARCH_DATABASE_JSON_PATH || "";


const MOD_SEARCH_DATABASE_YAML_NAME = "Mod Search Database";
Expand Down

0 comments on commit 351e12a

Please sign in to comment.