Migrate from iot.eclipse.org to mqtt.eclipse.org
This commit is contained in:
@@ -166,16 +166,38 @@ export const deleteConnection = (connectionId: string) => (dispatch: Dispatch<an
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ensureConnectionsHaveBeenInitialized() {
|
async function ensureConnectionsHaveBeenInitialized() {
|
||||||
const connections = await persistentStorage.load(storedConnectionsIdentifier)
|
let connections = await persistentStorage.load(storedConnectionsIdentifier)
|
||||||
const requiresInitialization = !connections
|
const requiresInitialization = !connections
|
||||||
if (requiresInitialization) {
|
if (requiresInitialization) {
|
||||||
const migratedConnection = loadLegacyConnectionOptions()
|
const migratedConnection = loadLegacyConnectionOptions()
|
||||||
const defaultConnections = makeDefaultConnections()
|
const defaultConnections = makeDefaultConnections()
|
||||||
persistentStorage.store(storedConnectionsIdentifier, {
|
connections = {
|
||||||
...migratedConnection,
|
...migratedConnection,
|
||||||
...defaultConnections,
|
...defaultConnections,
|
||||||
})
|
}
|
||||||
|
await persistentStorage.store(storedConnectionsIdentifier, connections)
|
||||||
|
|
||||||
clearLegacyConnectionOptions()
|
clearLegacyConnectionOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate connections, rewrite dictionary to "keep" it "ordered" (dictionaries do not have a guaranteed order)
|
||||||
|
const mayNeedMigrations = connections && connections['iot.eclipse.org']
|
||||||
|
if (connections && mayNeedMigrations) {
|
||||||
|
let newConnections = {}
|
||||||
|
for (const connection of Object.values(connections)) {
|
||||||
|
addMigratedConnection(newConnections, connection)
|
||||||
|
}
|
||||||
|
|
||||||
|
await persistentStorage.store(storedConnectionsIdentifier, newConnections)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMigratedConnection(newConnections: { [key: string]: ConnectionOptions }, connection: ConnectionOptions) {
|
||||||
|
// The host has been renamed, only change the host if it has not been changed
|
||||||
|
if (connection.id === 'iot.eclipse.org' && connection.host === 'iot.eclipse.org') {
|
||||||
|
connection.id = 'mqtt.eclipse.org'
|
||||||
|
connection.host = 'mqtt.eclipse.org'
|
||||||
|
connection.name = 'mqtt.eclipse.org'
|
||||||
|
}
|
||||||
|
newConnections[connection.id] = connection
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,11 +65,12 @@ export function createEmptyConnection(): ConnectionOptions {
|
|||||||
|
|
||||||
export function makeDefaultConnections() {
|
export function makeDefaultConnections() {
|
||||||
return {
|
return {
|
||||||
'iot.eclipse.org': {
|
// remember: there was also iot.eclipse.org once
|
||||||
|
'mqtt.eclipse.org': {
|
||||||
...createEmptyConnection(),
|
...createEmptyConnection(),
|
||||||
id: 'iot.eclipse.org',
|
id: 'mqtt.eclipse.org',
|
||||||
name: 'iot.eclipse.org',
|
name: 'mqtt.eclipse.org',
|
||||||
host: 'iot.eclipse.org',
|
host: 'mqtt.eclipse.org',
|
||||||
},
|
},
|
||||||
'test.mosquitto.org': {
|
'test.mosquitto.org': {
|
||||||
...createEmptyConnection(),
|
...createEmptyConnection(),
|
||||||
|
|||||||
Reference in New Issue
Block a user