-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mod-search-database dev api endpoint
-updates the local on-disk copy of the mod search database -only works in dev -no authentication
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/app/api/gamebanana-mirror/update-webhook/mod-search-database/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters