Passive UUID support
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
f64ca0ed21
commit
a90246cbe5
49 changed files with 2226 additions and 776 deletions
25
preload.js
25
preload.js
|
@ -6,6 +6,7 @@ try {
|
|||
const electron = require('electron');
|
||||
const semver = require('semver');
|
||||
const curve = require('curve25519-n');
|
||||
const _ = require('lodash');
|
||||
const { installGetter, installSetter } = require('./preload_utils');
|
||||
|
||||
const { deferredToPromise } = require('./js/modules/deferred_to_promise');
|
||||
|
@ -254,6 +255,30 @@ try {
|
|||
window.loadImage = require('blueimp-load-image');
|
||||
window.getGuid = require('uuid/v4');
|
||||
|
||||
window.isValidGuid = maybeGuid =>
|
||||
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(
|
||||
maybeGuid
|
||||
);
|
||||
// https://stackoverflow.com/a/23299989
|
||||
window.isValidE164 = maybeE164 => /^\+?[1-9]\d{1,14}$/.test(maybeE164);
|
||||
|
||||
window.normalizeUuids = (obj, paths, context) => {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
paths.forEach(path => {
|
||||
const val = _.get(obj, path);
|
||||
if (val) {
|
||||
if (!window.isValidGuid(val)) {
|
||||
window.log.warn(
|
||||
`Normalizing invalid uuid: ${val} at path ${path} in context "${context}"`
|
||||
);
|
||||
}
|
||||
_.set(obj, path, val.toLowerCase());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
window.React = require('react');
|
||||
window.ReactDOM = require('react-dom');
|
||||
window.moment = require('moment');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue