File size: 3,244 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { request } from "../request";

export interface UserInfo {
  remark: string;
  username: string;
}

export interface ACLData {
  whitelist: Record<string, UserInfo>;
  blacklist: Record<string, UserInfo>;
  pending: PendingEntry[];
}

export interface PendingEntry {
  user_id: string;
  channel: string;
  timestamp: number;
  first_message: string;
  remark: string;
  username: string;
}

export interface ACLUserEntry {
  userId: string;
  remark: string;
  username: string;
}

export const accessControlApi = {
  getAclAll: () => request<Record<string, ACLData>>("/access-control"),

  getAclChannel: (channel: string) =>
    request<ACLData>(`/access-control/${channel}`),

  /**
   * Unified whitelist/blacklist/remark APIs - work for both single and batch.
   * Pass an array of entries (1 or more).
   */
  addAclWhitelist: (
    entries: {
      channel: string;
      user_id: string;
      remark?: string;
      username?: string;
    }[],
  ) =>
    request("/access-control/whitelist/add", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  removeAclWhitelist: (entries: { channel: string; user_id: string }[]) =>
    request("/access-control/whitelist/remove", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  addAclBlacklist: (
    entries: {
      channel: string;
      user_id: string;
      remark?: string;
      username?: string;
    }[],
  ) =>
    request("/access-control/blacklist/add", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  removeAclBlacklist: (entries: { channel: string; user_id: string }[]) =>
    request("/access-control/blacklist/remove", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  updateAclRemark: (channel: string, userId: string, remark: string) =>
    request("/access-control/remark", {
      method: "POST",
      body: JSON.stringify({ channel, user_id: userId, remark }),
    }),

  getAclAllPending: () =>
    request<PendingEntry[]>("/access-control/pending/all"),

  /**
   * Unified pending action API - works for both single and batch operations.
   * Pass an array of entries (1 or more).
   */
  approveAclPending: (
    entries: { channel: string; user_id: string; remark?: string }[],
  ) =>
    request("/access-control/pending/approve", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  denyAclPending: (
    entries: { channel: string; user_id: string; remark?: string }[],
  ) =>
    request("/access-control/pending/deny", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  dismissAclPending: (entries: { channel: string; user_id: string }[]) =>
    request("/access-control/pending/dismiss", {
      method: "POST",
      body: JSON.stringify({ entries }),
    }),

  updatePendingRemark: (channel: string, userId: string, remark: string) =>
    request("/access-control/pending/remark", {
      method: "POST",
      body: JSON.stringify({ channel, user_id: userId, remark }),
    }),

  updateUsername: (channel: string, userId: string, username: string) =>
    request("/access-control/username", {
      method: "POST",
      body: JSON.stringify({ channel, user_id: userId, username }),
    }),
};