feat: disconnect a custom endpoint (DELETE /api/custom-provider + Disconnect in its editor)
Connecting was one-way: POST could only replace the base URL, and the only escape was hand-editing settings.json. DELETE now mirrors POST — drop the stored section, delete the reserved key, unregister the provider from piModels() — and the connect editor grows a Disconnect beside Connect, following the stored-key rows' Delete pattern (quiet text, one click, no confirm, only once there is an endpoint to remove).
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* fast), store the key, persist { baseUrl, models }, re-sync the
|
||||
* provider into piModels(). Discovery lives here because connecting
|
||||
* and discovering are one user action.
|
||||
* DELETE → disconnect: drop the stored config + the stored key and unregister
|
||||
* the provider (the mirror image of POST; idempotent).
|
||||
*/
|
||||
import {
|
||||
deleteKey,
|
||||
@@ -56,3 +58,15 @@ export async function POST(request: Request) {
|
||||
syncCustomProvider(next.customProvider);
|
||||
return Response.json({ ok: true, models: next.customProvider?.models ?? [] });
|
||||
}
|
||||
|
||||
/** Disconnect: forget the endpoint AND its key, then unregister the provider.
|
||||
* Deleting the section (rather than blanking baseUrl) keeps settings.json the
|
||||
* same shape as a never-connected install. Idempotent by construction. */
|
||||
export async function DELETE() {
|
||||
const record = readSettingsRecord() ?? { version: 1 };
|
||||
const { customProvider: _dropped, ...rest } = record;
|
||||
const next = writeSettingsRecord(rest);
|
||||
deleteKey(CUSTOM_PROVIDER.envVar);
|
||||
syncCustomProvider(next.customProvider);
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user