Browse Source

fixup: lint errors

pull/759/head
xwvike 3 years ago
parent
commit
164f608514
  1. 8
      src/lib/WireGuard.js
  2. 2
      src/www/js/api.js
  3. 8
      src/www/js/app.js

8
src/lib/WireGuard.js

@ -327,7 +327,6 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
throw new ServerError(`Invalid Address: ${address}`, 400); throw new ServerError(`Invalid Address: ${address}`, 400);
} }
if (client?.allowedIPs) { if (client?.allowedIPs) {
let allowedIPs = client.allowedIPs
client.allowedIPs[0].address = address; client.allowedIPs[0].address = address;
} }
client.address = address; client.address = address;
@ -335,14 +334,15 @@ Endpoint = ${WG_HOST}:${WG_PORT}`;
await this.saveConfig(); await this.saveConfig();
} }
async updateClientAllowedIPs({ clientId, allowedIPs }) { async updateClientAllowedIPs({ clientId, allowedIPs }) {
const client = await this.getClient({ clientId }); const client = await this.getClient({ clientId });
let ips = allowedIPs.map(item=>item.address) const ips = allowedIPs.map((item) => item.address);
ips.forEach(ip=>{ ips.forEach((ip) => {
if (!Util.isValidIPv4(ip)) { if (!Util.isValidIPv4(ip)) {
throw new ServerError(`Invalid Address: ${ip}`, 400); throw new ServerError(`Invalid Address: ${ip}`, 400);
} }
}) });
client.allowedIPs = allowedIPs; client.allowedIPs = allowedIPs;
client.updatedAt = new Date(); client.updatedAt = new Date();

2
src/www/js/api.js

@ -116,6 +116,7 @@ class API {
body: { address }, body: { address },
}); });
} }
async updateClientAllowedIPs({ clientId, allowedIPs }) { async updateClientAllowedIPs({ clientId, allowedIPs }) {
return this.call({ return this.call({
method: 'put', method: 'put',
@ -124,5 +125,4 @@ class API {
}); });
} }
} }

8
src/www/js/app.js

@ -251,15 +251,15 @@ new Vue({
.finally(() => this.refresh().catch(console.error)); .finally(() => this.refresh().catch(console.error));
}, },
addNewIP() { addNewIP() {
let address = this.userInputIP.slice(0,4).join('.'); const address = this.userInputIP.slice(0, 4).join('.');
let allowedIPs = this.clientEditAllowedIPs.allowedIPs; const allowedIPs = [...this.clientEditAllowedIPs.allowedIPs];
let obj = {type:'ipv4', address, cidr: this.userInputIP[4]}; const obj = { type: 'ipv4', address, cidr: this.userInputIP[4] };
allowedIPs.push(obj); allowedIPs.push(obj);
this.clientEditAllowedIPs.allowedIPs = allowedIPs; this.clientEditAllowedIPs.allowedIPs = allowedIPs;
this.userInputIP = [0, 0, 0, 0, 0]; this.userInputIP = [0, 0, 0, 0, 0];
}, },
removeIP(index) { removeIP(index) {
let allowedIPs = this.clientEditAllowedIPs.allowedIPs; const allowedIPs = [...this.clientEditAllowedIPs.allowedIPs];
allowedIPs.splice(index, 1); allowedIPs.splice(index, 1);
this.clientEditAllowedIPs.allowedIPs = allowedIPs; this.clientEditAllowedIPs.allowedIPs = allowedIPs;
}, },

Loading…
Cancel
Save