Improvements to the media editor
This commit is contained in:
parent
e8eb7638c4
commit
d0296ececa
61 changed files with 1124 additions and 969 deletions
42
ts/util/normalizeAci.ts
Normal file
42
ts/util/normalizeAci.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { AciString } from '../types/ServiceId';
|
||||
import type { LoggerType } from '../types/Logging';
|
||||
import * as log from '../logging/log';
|
||||
import { isAciString } from './isAciString';
|
||||
|
||||
export function normalizeAci(
|
||||
rawAci: string,
|
||||
context: string,
|
||||
logger?: Pick<LoggerType, 'warn'>
|
||||
): AciString;
|
||||
|
||||
export function normalizeAci(
|
||||
rawAci: string | undefined | null,
|
||||
context: string,
|
||||
logger?: Pick<LoggerType, 'warn'>
|
||||
): AciString | undefined;
|
||||
|
||||
export function normalizeAci(
|
||||
rawAci: string | undefined | null,
|
||||
context: string,
|
||||
logger: Pick<LoggerType, 'warn'> = log
|
||||
): AciString | undefined {
|
||||
if (rawAci == null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const result = rawAci.toLowerCase();
|
||||
|
||||
if (!isAciString(result)) {
|
||||
logger.warn(
|
||||
`Normalizing invalid serviceId: ${rawAci} to ${result} in context "${context}"`
|
||||
);
|
||||
|
||||
// Cast anyway we don't want to throw here
|
||||
return result as AciString;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue