Skip to content

Commit

Permalink
Merge pull request #32 from modos189/fix-update-check-interval
Browse files Browse the repository at this point in the history
Change _update_check_interval values from hours to seconds according to docs
  • Loading branch information
modos189 authored Feb 1, 2024
2 parents 2bfa75e + 6b0b690 commit 881ee28
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lib-iitc-manager",
"version": "1.8.3",
"version": "1.8.4",
"description": "Library for managing IITC plugins",
"main": "src/index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const exportIitcSettings = (all_storage) => {
// Loop through all_storage and check if the keys are present in storage_keys
// If present, add them to the iitc_settings object
for (const key in all_storage) {
if (storage_keys.includes(key)) {
if (storage_keys.includes(key) && isSet(all_storage[key])) {
iitc_settings[key] = all_storage[key];
}
}
Expand Down
25 changes: 22 additions & 3 deletions src/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function number_of_migrations() {
return migrates.length;
}

const migrates = [migration_0001, migration_0002, migration_0003, migration_0004];
const migrates = [migration_0001, migration_0002, migration_0003, migration_0004, migration_0005];

export async function migrate(storage) {
const storage_iitc_code = await storage.get(['release_iitc_code', 'beta_iitc_code', 'custom_iitc_code']);
Expand All @@ -25,6 +25,12 @@ export async function migrate(storage) {
'local_plugins_user',
]);
const storage_misc = await storage.get(['channel', 'network_host', 'lastversion', 'storage_version']);
const update_check_interval = await storage.get([
'release_update_check_interval',
'beta_update_check_interval',
'custom_update_check_interval',
'external_update_check_interval',
]);

if (!isSet(storage_misc['storage_version']) && isSet(storage_misc['lastversion'])) {
storage_misc['storage_version'] = 0;
Expand All @@ -34,13 +40,13 @@ export async function migrate(storage) {
for (const migrate of migrates) {
const index = migrates.indexOf(migrate);
if (parseInt(storage_misc['storage_version']) < index + 1) {
await migrate(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc);
await migrate(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc, update_check_interval);
is_migrated = true;
}
}

storage_misc['storage_version'] = migrates.length;
await storage.set({ ...storage_iitc_code, ...storage_plugins_flat, ...storage_plugins_user, ...storage_misc });
await storage.set({ ...storage_iitc_code, ...storage_plugins_flat, ...storage_plugins_user, ...storage_misc, ...update_check_interval });
return is_migrated;
}

Expand Down Expand Up @@ -96,3 +102,16 @@ async function migration_0004(storage_iitc_code) {
}
}
}

async function migration_0005(storage_iitc_code, storage_plugins_flat, storage_plugins_user, storage_misc, update_check_interval) {
for (let channel of Object.keys(update_check_interval)) {
const interval = update_check_interval[channel];
if (!isSet(interval)) {
delete update_check_interval[channel];
continue;
}
if (interval !== 24 * 60 * 60) {
update_check_interval[channel] = interval * 60 * 60;
}
}
}
6 changes: 3 additions & 3 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class Worker {
async _getUrl(url, variant, retry) {
if (retry > 1) {
let seconds = retry * retry;
if (seconds > 60 * 60 * 24) seconds = 60 * 60 * 24;
if (seconds > 30 * 60) seconds = 30 * 60; // maximum is 30 minutes
try {
this.message('serverNotAvailableRetry', String(seconds));
} catch {
Expand Down Expand Up @@ -311,7 +311,7 @@ export class Worker {
this.channel + '_plugins_user',
]);

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

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

let update_check_interval = local['external_update_check_interval'] * 60 * 60;
let update_check_interval = local['external_update_check_interval'];
if (!update_check_interval) {
update_check_interval = 24 * 60 * 60;
}
Expand Down
4 changes: 4 additions & 0 deletions test/manager.0.base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ describe('manage.js base integration tests', function () {
const fn = await manager.setUpdateCheckInterval(24 * 60 * 60, 'release');
expect(fn).to.be.undefined;
});
it('Should set correct interval in seconds', async function () {
const interval = await storage.get(['release_update_check_interval']).then((data) => data.release_update_check_interval);
expect(interval).to.equal(24 * 60 * 60);
});
});

describe('inject', function () {
Expand Down
5 changes: 5 additions & 0 deletions test/migrations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('test migrations', function () {
category: 'Controls',
},
},
release_update_check_interval: 6,
lastversion: '1.7.0',
storage_version: 0,
});
Expand Down Expand Up @@ -62,5 +63,9 @@ describe('test migrations', function () {
expect(db_data['release_iitc_core']['author']).to.equal('jonatkins');
expect(db_data['release_iitc_core']['code']).to.to.include('jonatkins');
});
it('Should change _update_check_interval from hours to seconds', async function () {
const db_data = await storage.get(['release_update_check_interval']);
expect(db_data['release_update_check_interval']).to.be.equal(6 * 60 * 60);
});
});
});

0 comments on commit 881ee28

Please sign in to comment.