Default to BTC Map Overpass provider
Switch the default Overpass API provider to overpass.btcmap.org and migrate users still on the previous overpass-api.de default over once.
This commit is contained in:
2 files changed
+79
-1
No files matched your search
@@ -3,8 +3,11 @@ import { tracked } from '@glimmer/tracking';
|
||||
|
||||
import { DEFAULT_BLOSSOM_SERVER } from './blossom';
|
||||
|
||||
const LEGACY_OVERPASS_API = 'https://overpass-api.de/api/interpreter';
|
||||
const OVERPASS_BTCMAP_MIGRATION_KEY = 'marco:migration:overpass-btcmap';
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
overpassApi: 'https://overpass-api.de/api/interpreter',
|
||||
overpassApi: 'https://overpass.btcmap.org/api/interpreter',
|
||||
mapKinetic: true,
|
||||
photonApi: 'https://photon.komoot.io/api/',
|
||||
showQuickSearchButtons: true,
|
||||
@@ -110,6 +113,16 @@ export default class SettingsService extends Service {
|
||||
if (savedPhotonApi) settings.photonApi = savedPhotonApi;
|
||||
}
|
||||
|
||||
// One-time migration: switch users still on the previous default Overpass
|
||||
// provider to the BTC Map provider. Runs once per device, so users can
|
||||
// change it again afterwards without it being re-applied.
|
||||
if (!localStorage.getItem(OVERPASS_BTCMAP_MIGRATION_KEY)) {
|
||||
if (settings.overpassApi === LEGACY_OVERPASS_API) {
|
||||
settings.overpassApi = DEFAULT_SETTINGS.overpassApi;
|
||||
}
|
||||
localStorage.setItem(OVERPASS_BTCMAP_MIGRATION_KEY, 'true');
|
||||
}
|
||||
|
||||
// Merge with defaults
|
||||
const finalSettings = { ...DEFAULT_SETTINGS, ...settings };
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'marco/tests/helpers';
|
||||
|
||||
const BTCMAP_OVERPASS_API = 'https://overpass.btcmap.org/api/interpreter';
|
||||
const LEGACY_OVERPASS_API = 'https://overpass-api.de/api/interpreter';
|
||||
const PRIVATE_COFFEE_OVERPASS_API =
|
||||
'https://overpass.private.coffee/api/interpreter';
|
||||
const MIGRATION_KEY = 'marco:migration:overpass-btcmap';
|
||||
|
||||
function storeSettings(settings) {
|
||||
localStorage.setItem('marco:settings', JSON.stringify(settings));
|
||||
}
|
||||
|
||||
module('Unit | Service | settings', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let service = this.owner.lookup('service:settings');
|
||||
assert.ok(service);
|
||||
});
|
||||
|
||||
test('new users get the BTC Map Overpass provider by default', function (assert) {
|
||||
let service = this.owner.lookup('service:settings');
|
||||
|
||||
assert.strictEqual(service.overpassApi, BTCMAP_OVERPASS_API);
|
||||
assert.strictEqual(localStorage.getItem(MIGRATION_KEY), 'true');
|
||||
});
|
||||
|
||||
test('users still on the legacy default are migrated to BTC Map once', function (assert) {
|
||||
storeSettings({ overpassApi: LEGACY_OVERPASS_API });
|
||||
|
||||
let service = this.owner.lookup('service:settings');
|
||||
|
||||
assert.strictEqual(service.overpassApi, BTCMAP_OVERPASS_API);
|
||||
assert.strictEqual(localStorage.getItem(MIGRATION_KEY), 'true');
|
||||
});
|
||||
|
||||
test('users on a non-legacy provider are left untouched', function (assert) {
|
||||
storeSettings({ overpassApi: PRIVATE_COFFEE_OVERPASS_API });
|
||||
|
||||
let service = this.owner.lookup('service:settings');
|
||||
|
||||
assert.strictEqual(service.overpassApi, PRIVATE_COFFEE_OVERPASS_API);
|
||||
assert.strictEqual(localStorage.getItem(MIGRATION_KEY), 'true');
|
||||
});
|
||||
|
||||
test('migration does not run again once it has been applied', function (assert) {
|
||||
// Simulate a user who already went through the migration and then
|
||||
// deliberately switched back to the legacy provider.
|
||||
localStorage.setItem(MIGRATION_KEY, 'true');
|
||||
storeSettings({ overpassApi: LEGACY_OVERPASS_API });
|
||||
|
||||
let service = this.owner.lookup('service:settings');
|
||||
|
||||
assert.strictEqual(service.overpassApi, LEGACY_OVERPASS_API);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user