New attachment storage system

This commit is contained in:
Fedor Indutny 2024-07-11 12:44:09 -07:00 committed by GitHub
parent 273e1ccb15
commit 28664a606f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
161 changed files with 2418 additions and 1562 deletions

View file

@ -7,12 +7,10 @@ import { join, normalize, basename } from 'path';
import fse from 'fs-extra';
import getGuid from 'uuid/v4';
import { getRandomBytes } from '../Crypto';
import * as Bytes from '../Bytes';
import { isPathInside } from '../util/isPathInside';
import { writeWindowsZoneIdentifier } from '../util/windowsZoneIdentifier';
import OS from '../util/os/osMain';
import { getRelativePath, createName } from '../util/attachmentPath';
export * from '../../app/attachments';
@ -32,7 +30,7 @@ try {
window.SignalContext.log?.info('x-attr dependency did not load successfully');
}
export const createReader = (
export const createPlaintextReader = (
root: string
): ((relativePath: string) => Promise<Uint8Array>) => {
if (!isString(root)) {
@ -53,18 +51,6 @@ export const createReader = (
};
};
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}`;
export const copyIntoAttachmentsDirectory = (
root: string
): ((sourcePath: string) => Promise<{ path: string; size: number }>) => {
@ -128,7 +114,7 @@ export const createWriterForNew = (
};
};
export const createWriterForExisting = (
const createWriterForExisting = (
root: string
): ((options: { data?: Uint8Array; path?: string }) => Promise<string>) => {
if (!isString(root)) {