Skip to content

Commit 881ee28

Browse files
authored
Merge pull request #32 from modos189/fix-update-check-interval
Change _update_check_interval values from hours to seconds according to docs
2 parents 2bfa75e + 6b0b690 commit 881ee28

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lib-iitc-manager",
3-
"version": "1.8.3",
3+
"version": "1.8.4",
44
"description": "Library for managing IITC plugins",
55
"main": "src/index.js",
66
"type": "module",

src/backup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const exportIitcSettings = (all_storage) => {
4747
// Loop through all_storage and check if the keys are present in storage_keys
4848
// If present, add them to the iitc_settings object
4949
for (const key in all_storage) {
50-
if (storage_keys.includes(key)) {
50+
if (storage_keys.includes(key) && isSet(all_storage[key])) {
5151
iitc_settings[key] = all_storage[key];
5252
}
5353
}

src/migrations.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function number_of_migrations() {
66
return migrates.length;
77
}
88

9-
const migrates = [migration_0001, migration_0002, migration_0003, migration_0004];
9+
const migrates = [migration_0001, migration_0002, migration_0003, migration_0004, migration_0005];
1010

1111
export async function migrate(storage) {
1212
const storage_iitc_code = await storage.get(['release_iitc_code', 'beta_iitc_code', 'custom_iitc_code']);
@@ -25,6 +25,12 @@ export async function migrate(storage) {
2525
'local_plugins_user',
2626
]);
2727
const storage_misc = await storage.get(['channel', 'network_host', 'lastversion', 'storage_version']);
28+
const update_check_interval = await storage.get([
29+
'release_update_check_interval',
30+
'beta_update_check_interval',
31+
'custom_update_check_interval',
32+
'external_update_check_interval',
33+
]);
2834

2935
if (!isSet(storage_misc['storage_version']) && isSet(storage_misc['lastversion'])) {
3036
storage_misc['storage_version'] = 0;
@@ -34,13 +40,13 @@ export async function migrate(storage) {
3440
for (const migrate of migrates) {
3541
const index = migrates.indexOf(migrate);
3642
if (parseInt(storage_misc['storage_version']) < index + 1) {
37-
await migrate(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc);
43+
await migrate(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc, update_check_interval);
3844
is_migrated = true;
3945
}
4046
}
4147

4248
storage_misc['storage_version'] = migrates.length;
43-
await storage.set({ ...storage_iitc_code, ...storage_plugins_flat, ...storage_plugins_user, ...storage_misc });
49+
await storage.set({ ...storage_iitc_code, ...storage_plugins_flat, ...storage_plugins_user, ...storage_misc, ...update_check_interval });
4450
return is_migrated;
4551
}
4652

@@ -96,3 +102,16 @@ async function migration_0004(storage_iitc_code) {
96102
}
97103
}
98104
}
105+
106+
async function migration_0005(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc, update_check_interval) {
107+
for (let channel of Object.keys(update_check_interval)) {
108+
const interval = update_check_interval[channel];
109+
if (!isSet(interval)) {
110+
delete update_check_interval[channel];
111+
continue;
112+
}
113+
if (interval !== 24 * 60 * 60) {
114+
update_check_interval[channel] = interval * 60 * 60;
115+
}
116+
}
117+
}

src/worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class Worker {
263263
async _getUrl(url, variant, retry) {
264264
if (retry > 1) {
265265
let seconds = retry * retry;
266-
if (seconds > 60 * 60 * 24) seconds = 60 * 60 * 24;
266+
if (seconds > 30 * 60) seconds = 30 * 60; // maximum is 30 minutes
267267
try {
268268
this.message('serverNotAvailableRetry', String(seconds));
269269
} catch {
@@ -311,7 +311,7 @@ export class Worker {
311311
this.channel + '_plugins_user',
312312
]);
313313

314-
let update_check_interval = storage[this.channel + '_update_check_interval'] * 60 * 60;
314+
let update_check_interval = storage[this.channel + '_update_check_interval'];
315315
if (!update_check_interval) update_check_interval = 24 * 60 * 60;
316316

317317
if (!isSet(storage[this.channel + '_last_modified']) || !isSet(storage.last_check_update)) {
@@ -455,7 +455,7 @@ export class Worker {
455455
async _checkExternalUpdates(force) {
456456
const local = await this.storage.get(['channel', 'last_check_external_update', 'external_update_check_interval', this.channel + '_plugins_user']);
457457

458-
let update_check_interval = local['external_update_check_interval'] * 60 * 60;
458+
let update_check_interval = local['external_update_check_interval'];
459459
if (!update_check_interval) {
460460
update_check_interval = 24 * 60 * 60;
461461
}

test/manager.0.base.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ describe('manage.js base integration tests', function () {
5757
const fn = await manager.setUpdateCheckInterval(24 * 60 * 60, 'release');
5858
expect(fn).to.be.undefined;
5959
});
60+
it('Should set correct interval in seconds', async function () {
61+
const interval = await storage.get(['release_update_check_interval']).then((data) => data.release_update_check_interval);
62+
expect(interval).to.equal(24 * 60 * 60);
63+
});
6064
});
6165

6266
describe('inject', function () {

test/migrations.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('test migrations', function () {
3434
category: 'Controls',
3535
},
3636
},
37+
release_update_check_interval: 6,
3738
lastversion: '1.7.0',
3839
storage_version: 0,
3940
});
@@ -62,5 +63,9 @@ describe('test migrations', function () {
6263
expect(db_data['release_iitc_core']['author']).to.equal('jonatkins');
6364
expect(db_data['release_iitc_core']['code']).to.to.include('jonatkins');
6465
});
66+
it('Should change _update_check_interval from hours to seconds', async function () {
67+
const db_data = await storage.get(['release_update_check_interval']);
68+
expect(db_data['release_update_check_interval']).to.be.equal(6 * 60 * 60);
69+
});
6570
});
6671
});

0 commit comments

Comments
 (0)