Descriptive error messages for video stories
This commit is contained in:
parent
c038c07b06
commit
4549291b7b
16 changed files with 289 additions and 179 deletions
46
ts/types/AttachmentSize.ts
Normal file
46
ts/types/AttachmentSize.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as log from '../logging/log';
|
||||
import { parseIntOrThrow } from '../util/parseIntOrThrow';
|
||||
import type * as RemoteConfig from '../RemoteConfig';
|
||||
|
||||
export const KIBIBYTE = 1024;
|
||||
const MEBIBYTE = 1024 * 1024;
|
||||
const DEFAULT_MAX = 100 * MEBIBYTE;
|
||||
|
||||
export const getMaximumAttachmentSizeInKb = (
|
||||
getValue: typeof RemoteConfig.getValue
|
||||
): number => {
|
||||
try {
|
||||
return (
|
||||
parseIntOrThrow(
|
||||
getValue('global.attachments.maxBytes'),
|
||||
'preProcessAttachment/maxAttachmentSize'
|
||||
) / KIBIBYTE
|
||||
);
|
||||
} catch (error) {
|
||||
log.warn(
|
||||
'Failed to parse integer out of global.attachments.maxBytes feature flag'
|
||||
);
|
||||
return DEFAULT_MAX / KIBIBYTE;
|
||||
}
|
||||
};
|
||||
|
||||
export function getRenderDetailsForLimit(limitKb: number): {
|
||||
limit: string;
|
||||
units: string;
|
||||
} {
|
||||
const units = ['kB', 'MB', 'GB'];
|
||||
let u = -1;
|
||||
let limit = limitKb * KIBIBYTE;
|
||||
do {
|
||||
limit /= KIBIBYTE;
|
||||
u += 1;
|
||||
} while (limit >= KIBIBYTE && u < units.length - 1);
|
||||
|
||||
return {
|
||||
limit: limit.toFixed(0),
|
||||
units: units[u],
|
||||
};
|
||||
}
|
|
@ -35,7 +35,6 @@ export enum ToastType {
|
|||
StoryReact = 'StoryReact',
|
||||
StoryReply = 'StoryReply',
|
||||
StoryVideoError = 'StoryVideoError',
|
||||
StoryVideoTooLong = 'StoryVideoTooLong',
|
||||
StoryVideoUnsupported = 'StoryVideoUnsupported',
|
||||
TapToViewExpiredIncoming = 'TapToViewExpiredIncoming',
|
||||
TapToViewExpiredOutgoing = 'TapToViewExpiredOutgoing',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue