mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-20 17:07:59 +00:00
fix(webui): send DELETE when removing keys and adapters
Deleting a gateway key from the admin UI did nothing and reported "use GET /api/keys": delKey() called api() with an empty options object, so fetch defaulted to GET and the request landed in the GET branch of handleKeysAPI. delAdapter() had the identical bug and reported "adapter code not exposed; edit in UI". This is the third instance of the same mistake —ab20f1bfixed delSource and delTemplate, missing these two — so it is now pinned by tests instead of by review: * TestUIAPICallsDeclareMethod walks every api() call in the embedded index.html and fails if one passes an options object without a method (an AbortSignal-only read is allowed, being a deliberate GET). * TestUIDeleteHelpersUseDelete / TestUIMutatingHelpersUseWriteMethods pin the verb of each removal and write helper by name. * TestKeyDeleteRoundTrip covers create -> DELETE -> gone -> second DELETE is a clean 404, and TestCannotDeleteOwnKey keeps the lockout guard. The 404 bodies for GET /api/keys/{key} and GET /api/adapters/{name} now name the verb to use ("DELETE /api/keys/{key} to remove"), because that message is what a mis-methoded client actually shows its user; "use GET /api/keys" read as though the caller had done nothing wrong. delSource's indentation, broken byab20f1b, is also straightened out.
This commit is contained in:
@ -3027,9 +3027,9 @@
|
||||
}
|
||||
async function delSource(name) {
|
||||
if (!confirm(tFmt("confirmDelSrc", name))) return;
|
||||
await api("/api/sources/" + encodeURIComponent(name), {
|
||||
method: "DELETE",
|
||||
});
|
||||
await api("/api/sources/" + encodeURIComponent(name), {
|
||||
method: "DELETE",
|
||||
});
|
||||
toast(t("toastDelOk"));
|
||||
renderSources();
|
||||
}
|
||||
@ -3992,6 +3992,7 @@
|
||||
async function delAdapter(name) {
|
||||
if (!confirm(tFmt("confirmDelAdp", name))) return;
|
||||
await api("/api/adapters/" + encodeURIComponent(name), {
|
||||
method: "DELETE",
|
||||
});
|
||||
toast(t("toastDelOk"));
|
||||
renderAdapters();
|
||||
@ -4545,6 +4546,7 @@
|
||||
if (!confirm(tFmt("kDelConfirm", name || key))) return;
|
||||
try {
|
||||
await api("/api/keys/" + encodeURIComponent(key), {
|
||||
method: "DELETE",
|
||||
});
|
||||
toast(t("toastDelOk"));
|
||||
loadKeys();
|
||||
|
||||
Reference in New Issue
Block a user