Skip to content

Commit

Permalink
Support for custom versions of the IITC core has been added to the me…
Browse files Browse the repository at this point in the history
…thods for creating and restoring backups
  • Loading branch information
modos189 committed Sep 28, 2023
1 parent 1d053e4 commit c0501eb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/backup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3

import { parseMeta } from './helpers.js';
import { isSet, parseMeta } from './helpers.js';
import deepmerge from '@bundled-es-modules/deepmerge';

/**
Expand Down Expand Up @@ -78,9 +78,9 @@ export const exportPluginsSettings = (all_storage) => {
};

/**
* Exports external plugins from the provided storage object.
* Exports external IITC core and plugins from the provided storage object.
*
* This function takes a storage object and extracts external plugins based on predefined keys.
* This function takes a storage object and extracts external IITC core and plugins based on predefined keys.
* It creates a new object containing the external plugins organized by their channels and filenames,
* and returns it.
*
Expand All @@ -91,15 +91,34 @@ export const exportExternalPlugins = (all_storage) => {
const external_plugins = {};

// An array of predefined keys for external plugins
const storage_keys = ['release_plugins_user', 'beta_plugins_user', 'custom_plugins_user'];
const storage_keys = [
'release_iitc_core_user',
'beta_iitc_core_user',
'custom_iitc_core_user',
'release_plugins_user',
'beta_plugins_user',
'custom_plugins_user',
];

// Loop through all_storage and check if the keys are present in storage_keys
// If present, process and add the external plugins to the external_plugins object
for (const key in all_storage) {
if (storage_keys.includes(key)) {
// Extract the channel name from the key by splitting at '_'
const channel = key.split('_')[0];
external_plugins[channel] = {};
const variant = key.split('_')[1];

// Create a channel if it doesn't exist
if (!(channel in external_plugins)) {
external_plugins[channel] = {};
}

// Add a custom IITC core to the external_plugins object
if (variant === 'iitc' && isSet(all_storage[key]) && isSet(all_storage[key]['code'])) {
const plugin_filename = 'total-conversion-build.user.js';
external_plugins[channel][plugin_filename] = all_storage[key]['code'];
continue;
}

// Loop through each plugin UID in the current key's storage data
for (const plugin_uid in all_storage[key]) {
Expand Down
42 changes: 42 additions & 0 deletions test/manager.9.backup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ describe('getBackupData and setBackupData', function () {
let manager = null;
const first_plugin_uid = 'Available AP statistics+https://github.com/IITC-CE/ingress-intel-total-conversion';
const external_code = '// ==UserScript==\n// @name IITC plugin\n// ==/UserScript==\nreturn false;';
const external_iitc_code =
'// ==UserScript==\n' +
'// @name IITC: Ingress intel map total conversion\n' +
'// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion\n' +
'// ==/UserScript==\n' +
'return false;';
const initialBackupData = {
external_plugins: {
beta: {},
custom: {},
release: {
'total-conversion-build.user.js': external_iitc_code,
'bookmarks1.user.js': external_code,
},
},
Expand All @@ -39,6 +46,7 @@ describe('getBackupData and setBackupData', function () {
'bookmarks2.user.js': external_code,
},
beta: {
'total-conversion-build.user.js': external_iitc_code,
'bookmarks3.user.js': external_code,
},
},
Expand Down Expand Up @@ -90,6 +98,31 @@ describe('getBackupData and setBackupData', function () {
const run = await manager.managePlugin(first_plugin_uid, 'on');
expect(run).to.be.undefined;
});
it('Add custom IITC core', async function () {
const scripts = [
{
meta: {
id: 'total-conversion-build',
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
name: 'IITC: Ingress intel map total conversion',
filename: 'total-conversion-build.user.js',
},
code: external_iitc_code,
},
];
const installed = {
'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion': {
uid: 'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion',
id: 'total-conversion-build',
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
name: 'IITC: Ingress intel map total conversion',
code: external_iitc_code,
filename: 'total-conversion-build.user.js',
},
};
const run = await manager.addUserScripts(scripts);
expect(run).to.deep.equal(installed);
});
it('Add external plugin', async function () {
const scripts = [
{
Expand Down Expand Up @@ -155,6 +188,15 @@ describe('getBackupData and setBackupData', function () {
VMin9999: 'backup2',
});

const externalCore = await storage.get(['beta_iitc_core_user']);
expect(externalCore['beta_iitc_core_user']).to.deep.equal({
uid: 'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion',
name: 'IITC: Ingress intel map total conversion',
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
code: external_iitc_code,
filename: 'total-conversion-build.user.js',
});

const externalPlugins = await storage.get(['release_plugins_user', 'beta_plugins_user']);
expect(externalPlugins['release_plugins_user']).to.have.all.keys(
'Bookmarks for maps and portals+https://github.com/IITC-CE/ingress-intel-total-conversion',
Expand Down

0 comments on commit c0501eb

Please sign in to comment.