@c4t4/heyamigo 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wa/whitelist.js +25 -2
- package/package.json +1 -1
package/dist/wa/whitelist.js
CHANGED
|
@@ -99,6 +99,29 @@ function load() {
|
|
|
99
99
|
const content = readFileSync(ACCESS_FILE, 'utf-8');
|
|
100
100
|
return AccessSchema.parse(JSON.parse(content));
|
|
101
101
|
}
|
|
102
|
+
// Per-field merge: access.json's role definition overrides individual fields
|
|
103
|
+
// of DEFAULT_ROLES, instead of replacing the whole role object. This means
|
|
104
|
+
// adding new role fields (maxFileBytes, dailyTokenLimit, …) in code stays
|
|
105
|
+
// effective for existing installs whose access.json predates those fields.
|
|
106
|
+
function resolveRoles() {
|
|
107
|
+
const configured = current.roles ?? {};
|
|
108
|
+
const out = {};
|
|
109
|
+
const names = new Set([
|
|
110
|
+
...Object.keys(DEFAULT_ROLES),
|
|
111
|
+
...Object.keys(configured),
|
|
112
|
+
]);
|
|
113
|
+
for (const name of names) {
|
|
114
|
+
const def = DEFAULT_ROLES[name];
|
|
115
|
+
const cfg = configured[name];
|
|
116
|
+
if (def && cfg)
|
|
117
|
+
out[name] = { ...def, ...cfg };
|
|
118
|
+
else if (cfg)
|
|
119
|
+
out[name] = cfg;
|
|
120
|
+
else if (def)
|
|
121
|
+
out[name] = def;
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
102
125
|
function save(next) {
|
|
103
126
|
writeFileSync(ACCESS_FILE, JSON.stringify(next, null, 2) + '\n', 'utf-8');
|
|
104
127
|
current = next;
|
|
@@ -128,7 +151,7 @@ export function canSendProactive(jid) {
|
|
|
128
151
|
}
|
|
129
152
|
export function getRole(senderNumber) {
|
|
130
153
|
const users = current.users ?? {};
|
|
131
|
-
const roles =
|
|
154
|
+
const roles = resolveRoles();
|
|
132
155
|
const entry = users[senderNumber];
|
|
133
156
|
if (entry) {
|
|
134
157
|
const roleName = entry.role;
|
|
@@ -154,7 +177,7 @@ export function getRole(senderNumber) {
|
|
|
154
177
|
}
|
|
155
178
|
export function getRoleForContext(senderNumber, isGroup) {
|
|
156
179
|
const users = current.users ?? {};
|
|
157
|
-
const roles =
|
|
180
|
+
const roles = resolveRoles();
|
|
158
181
|
const entry = users[senderNumber];
|
|
159
182
|
if (entry) {
|
|
160
183
|
return {
|