Commit 738bde20a8256e929e5eed916be058b1bd73a20d

Authored by Adhidarma Hadiwinoto
1 parent dabbcb087e
Exists in master

APISERVER: config-senders del cleanup

Showing 1 changed file with 14 additions and 1 deletions Side-by-side Diff

lib/apiserver/router-config-senders.js
... ... @@ -43,11 +43,24 @@ function pageIndex(req, res) {
43 43 res.json(config.senders_imsi);
44 44 }
45 45  
46   -function delImsi(data, imsi) {
  46 +function delImsi(data, imsi, cleanup) {
47 47 const idx = data.indexOf(imsi);
48 48 if (idx < 0) return;
49 49  
50 50 data.splice(idx, 1);
  51 +
  52 + if (cleanup) {
  53 + Object.keys(config.senders_imsi.prefix_names).forEach((key) => {
  54 + if (!config.senders_imsi.prefix_names[key]) return;
  55 +
  56 + if (!Array.isArray(config.senders_imsi.prefix_names[key])) return;
  57 +
  58 + if (config.senders_imsi.prefix_names[key].length === 0) {
  59 + delete config.senders_imsi.prefix_names[key];
  60 + }
  61 + });
  62 + }
  63 +
51 64 saveConfig();
52 65 }
53 66