signal-desktop/ts/util/attachmentPath.ts

23 lines
572 B
TypeScript
Raw Normal View History

2024-07-11 12:44:09 -07:00
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join } from 'node:path';
2025-09-19 13:05:51 -07:00
import lodash from 'lodash';
2024-07-11 12:44:09 -07:00
import { getRandomBytes } from '../Crypto.js';
import * as Bytes from '../Bytes.js';
2024-07-11 12:44:09 -07:00
2025-09-19 13:05:51 -07:00
const { isString } = lodash;
2024-07-11 12:44:09 -07:00
export const getRelativePath = (name: string): string => {
if (!isString(name)) {
throw new TypeError("'name' must be a string");
}
const prefix = name.slice(0, 2);
return join(prefix, name);
};
export const createName = (suffix = ''): string =>
`${Bytes.toHex(getRandomBytes(32))}${suffix}`;