WebHooker/app/composables/useWebhook.ts
RhenCloud e59b10f739
refactor(admin): unify webui fetch/copy/format helpers; fix audit tab load and delete-group count
- apiFetch + shared needLogin (any 401 shows the login card) replaces six
  duplicated fetch/401/error-handling blocks in the admin composables
- useCopy composable: clipboard + execCommand fallback with timed reset,
  used by MembersPanel and WebhookPanel
- utils/format.ts (fmtTime/splitList/parseMatch) removes inline duplicates
  across SendLogs, AuditLog, RouteEditor and GroupEditor
- fix: load the audit log when the audit tab becomes active (client-side
  navigation never remounted the page, leaving the list empty on first visit)
- fix: fetch the real route count for a group before confirming deletion
  instead of reusing the currently open group's route list
2026-08-14 07:18:55 +08:00

41 lines
1.1 KiB
TypeScript

export interface GroupWebhookInfo {
url: string;
hasSecret: boolean;
secret?: string;
}
export function useWebhookApi() {
const loading = ref(false);
const error = ref("");
async function request<T>(path: string, init?: RequestInit): Promise<T> {
loading.value = true;
error.value = "";
try {
return await apiFetch<T>(path, init);
} catch (err) {
error.value = err instanceof Error ? err.message : String(err);
throw err;
} finally {
loading.value = false;
}
}
function info(groupId: string): Promise<GroupWebhookInfo> {
return request(`/admin/api/groups/${encodeURIComponent(groupId)}/webhook`);
}
function regenerate(groupId: string): Promise<GroupWebhookInfo> {
return request(`/admin/api/groups/${encodeURIComponent(groupId)}/webhook/regenerate`, {
method: "POST",
});
}
function disable(groupId: string): Promise<{ ok: boolean }> {
return request(`/admin/api/groups/${encodeURIComponent(groupId)}/webhook`, {
method: "DELETE",
});
}
return { loading, error, info, regenerate, disable };
}