fix: contain malformed metadata and stale discovery
This commit is contained in:
+28
-5
@@ -1,6 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
(function exposeDeviceTree(globalScope) {
|
||||
const { toWellFormedString } = typeof module !== 'undefined' && module.exports
|
||||
? require('./well-formed-string')
|
||||
: globalScope.AptWellFormedString;
|
||||
const SPECIAL = Object.freeze({
|
||||
ORPHAN_SITE: '__orphaned__',
|
||||
UNGROUPED: '__ungrouped__',
|
||||
@@ -9,7 +12,7 @@
|
||||
});
|
||||
|
||||
function text(value) {
|
||||
return value === null || value === undefined ? '' : String(value).trim();
|
||||
return value === null || value === undefined ? '' : toWellFormedString(value).trim();
|
||||
}
|
||||
|
||||
function normalized(value) {
|
||||
@@ -17,7 +20,7 @@
|
||||
}
|
||||
|
||||
function keyPart(value) {
|
||||
const encoded = encodeURIComponent(String(value));
|
||||
const encoded = encodeURIComponent(toWellFormedString(value));
|
||||
return `${encoded.length}:${encoded}`;
|
||||
}
|
||||
|
||||
@@ -109,7 +112,11 @@
|
||||
const site = makeSite(identity.uniqueId, text(safe.name) || identity.canonicalId, ordinal, {
|
||||
canonicalId: identity.canonicalId,
|
||||
pendingDeletion: safe.pendingDeletion === true || Boolean(text(safe.pendingDeletionStart)),
|
||||
source: safe,
|
||||
source: {
|
||||
id: identity.canonicalId,
|
||||
name: text(safe.name),
|
||||
pendingDeletionStart: text(safe.pendingDeletionStart) || null,
|
||||
},
|
||||
});
|
||||
sites.push(site);
|
||||
registerRow(site);
|
||||
@@ -144,7 +151,12 @@
|
||||
canonicalId: identity.canonicalId,
|
||||
rawParentId: parentId,
|
||||
pendingDeletion: safe.pendingDeletion === true || Boolean(text(safe.pendingDeletionStart)),
|
||||
source: safe,
|
||||
source: {
|
||||
id: identity.canonicalId,
|
||||
name: text(safe.name),
|
||||
parentId,
|
||||
pendingDeletionStart: text(safe.pendingDeletionStart) || null,
|
||||
},
|
||||
});
|
||||
site.groups.push(group);
|
||||
registerRow(group);
|
||||
@@ -206,10 +218,21 @@
|
||||
}
|
||||
|
||||
const name = text(safe.name) || identity.canonicalId;
|
||||
const source = {
|
||||
id: identity.canonicalId,
|
||||
name,
|
||||
type: text(safe.type) || null,
|
||||
model: text(safe.model) || null,
|
||||
address: text(safe.address) || null,
|
||||
siteId: directSiteId || null,
|
||||
deviceGroupId: requestedGroupId || null,
|
||||
displayStatus: text(safe.displayStatus) || null,
|
||||
localStorage: typeof safe.localStorage === 'boolean' ? safe.localStorage : null,
|
||||
};
|
||||
const camera = {
|
||||
kind: 'camera', id: identity.uniqueId, canonicalId: identity.canonicalId,
|
||||
key: cameraKey, name, normalizedName: normalized(name), ordinal,
|
||||
parentKey: group.key, site, group, hierarchyStatus, source: safe,
|
||||
parentKey: group.key, site, group, hierarchyStatus, source,
|
||||
};
|
||||
camera.searchCorpus = normalized([
|
||||
name, identity.canonicalId, safe.model, safe.type, safe.address, site.name, group.name,
|
||||
|
||||
Reference in New Issue
Block a user