Enhance token refresh logic and improve MITM server handling
- Introduced a caching mechanism for in-flight token refresh requests to prevent race conditions and reduce unnecessary API calls. - Added error handling for unrecoverable refresh errors, ensuring that the application can gracefully handle token reuse and invalidation scenarios. - Updated the MITM server management to handle port 443 conflicts, allowing users to kill processes occupying the port before starting the server. - Improved user feedback in the MitmServerCard component regarding port conflicts and admin privileges. - Refactored the ComboList component to streamline the display of media provider combos. This update aims to enhance the reliability and user experience of the token management and MITM functionalities.
This commit is contained in:
parent
b8e3a46add
commit
4ba546afe7
17 changed files with 680 additions and 229 deletions
|
|
@ -93,7 +93,7 @@ export async function GET() {
|
|||
// POST - Start MITM server (cert + server, no DNS)
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const { apiKey, sudoPassword, mitmRouterBaseUrl } = await request.json();
|
||||
const { apiKey, sudoPassword, mitmRouterBaseUrl, forceKillPort443 } = await request.json();
|
||||
const pwd = getPassword(sudoPassword) || await loadEncryptedPassword() || "";
|
||||
|
||||
if (!apiKey || requiresSudoPassword(pwd)) {
|
||||
|
|
@ -122,12 +122,18 @@ export async function POST(request) {
|
|||
}
|
||||
}
|
||||
|
||||
const result = await startServer(apiKey, pwd);
|
||||
const result = await startServer(apiKey, pwd, !!forceKillPort443);
|
||||
if (!isWin) setCachedPassword(pwd);
|
||||
|
||||
return NextResponse.json({ success: true, running: result.running, pid: result.pid });
|
||||
} catch (error) {
|
||||
console.log("Error starting MITM server:", error.message);
|
||||
if (error.code === "PORT_443_BUSY") {
|
||||
return NextResponse.json(
|
||||
{ error: error.message, code: "PORT_443_BUSY", portOwner: error.portOwner },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json({ error: error.message || "Failed to start MITM server" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue