New attachment storage system
This commit is contained in:
parent
273e1ccb15
commit
28664a606f
161 changed files with 2418 additions and 1562 deletions
|
@ -228,6 +228,10 @@ export type StickerType = Readonly<{
|
|||
|
||||
width: number;
|
||||
height: number;
|
||||
|
||||
version: 1 | 2;
|
||||
localKey?: string;
|
||||
size?: number;
|
||||
}>;
|
||||
|
||||
export const StickerPackStatuses = [
|
||||
|
@ -806,6 +810,9 @@ export type DataInterface = {
|
|||
) => Promise<void>;
|
||||
updateStickerPackInfo: (info: StickerPackInfoType) => Promise<void>;
|
||||
createOrUpdateSticker: (sticker: StickerType) => Promise<void>;
|
||||
createOrUpdateStickers: (
|
||||
sticker: ReadonlyArray<StickerType>
|
||||
) => Promise<void>;
|
||||
updateStickerLastUsed: (
|
||||
packId: string,
|
||||
stickerId: number,
|
||||
|
|
|
@ -210,6 +210,9 @@ type StickerRow = Readonly<{
|
|||
lastUsed: number;
|
||||
path: string;
|
||||
width: number;
|
||||
version: 1 | 2;
|
||||
localKey: string | null;
|
||||
size: number | null;
|
||||
}>;
|
||||
|
||||
// Because we can't force this module to conform to an interface, we narrow our exports
|
||||
|
@ -409,6 +412,7 @@ const dataInterface: ServerInterface = {
|
|||
updateStickerPackStatus,
|
||||
updateStickerPackInfo,
|
||||
createOrUpdateSticker,
|
||||
createOrUpdateStickers,
|
||||
updateStickerLastUsed,
|
||||
addStickerPackReference,
|
||||
deleteStickerPackReference,
|
||||
|
@ -542,6 +546,9 @@ function rowToSticker(row: StickerRow): StickerType {
|
|||
...row,
|
||||
isCoverOnly: Boolean(row.isCoverOnly),
|
||||
emoji: dropNull(row.emoji),
|
||||
version: row.version || 1,
|
||||
localKey: dropNull(row.localKey),
|
||||
size: dropNull(row.size),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1655,7 +1662,7 @@ function saveConversationSync(db: Database, data: ConversationType): void {
|
|||
).run({
|
||||
id,
|
||||
json: objectToJSON(
|
||||
omit(data, ['profileLastFetchedAt', 'unblurredAvatarPath'])
|
||||
omit(data, ['profileLastFetchedAt', 'unblurredAvatarUrl'])
|
||||
),
|
||||
|
||||
e164: e164 || null,
|
||||
|
@ -1726,7 +1733,7 @@ function updateConversationSync(db: Database, data: ConversationType): void {
|
|||
).run({
|
||||
id,
|
||||
json: objectToJSON(
|
||||
omit(data, ['profileLastFetchedAt', 'unblurredAvatarPath'])
|
||||
omit(data, ['profileLastFetchedAt', 'unblurredAvatarUrl'])
|
||||
),
|
||||
|
||||
e164: e164 || null,
|
||||
|
@ -5385,10 +5392,20 @@ async function clearAllErrorStickerPackAttempts(): Promise<void> {
|
|||
`
|
||||
).run();
|
||||
}
|
||||
async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
|
||||
const db = await getWritableInstance();
|
||||
const { emoji, height, id, isCoverOnly, lastUsed, packId, path, width } =
|
||||
sticker;
|
||||
function createOrUpdateStickerSync(db: Database, sticker: StickerType): void {
|
||||
const {
|
||||
emoji,
|
||||
height,
|
||||
id,
|
||||
isCoverOnly,
|
||||
lastUsed,
|
||||
packId,
|
||||
path,
|
||||
width,
|
||||
version,
|
||||
localKey,
|
||||
size,
|
||||
} = sticker;
|
||||
|
||||
if (!isNumber(id)) {
|
||||
throw new Error(
|
||||
|
@ -5411,7 +5428,10 @@ async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
|
|||
lastUsed,
|
||||
packId,
|
||||
path,
|
||||
width
|
||||
width,
|
||||
version,
|
||||
localKey,
|
||||
size
|
||||
) values (
|
||||
$emoji,
|
||||
$height,
|
||||
|
@ -5420,7 +5440,10 @@ async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
|
|||
$lastUsed,
|
||||
$packId,
|
||||
$path,
|
||||
$width
|
||||
$width,
|
||||
$version,
|
||||
$localKey,
|
||||
$size
|
||||
)
|
||||
`
|
||||
).run({
|
||||
|
@ -5432,8 +5455,25 @@ async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
|
|||
packId,
|
||||
path,
|
||||
width,
|
||||
version: version || 1,
|
||||
localKey: localKey || null,
|
||||
size: size || null,
|
||||
});
|
||||
}
|
||||
async function createOrUpdateSticker(sticker: StickerType): Promise<void> {
|
||||
const db = await getWritableInstance();
|
||||
return createOrUpdateStickerSync(db, sticker);
|
||||
}
|
||||
async function createOrUpdateStickers(
|
||||
stickers: ReadonlyArray<StickerType>
|
||||
): Promise<void> {
|
||||
const db = await getWritableInstance();
|
||||
db.transaction(() => {
|
||||
for (const sticker of stickers) {
|
||||
createOrUpdateStickerSync(db, sticker);
|
||||
}
|
||||
})();
|
||||
}
|
||||
async function updateStickerLastUsed(
|
||||
packId: string,
|
||||
stickerId: number,
|
||||
|
|
35
ts/sql/migrations/1110-sticker-local-key.ts
Normal file
35
ts/sql/migrations/1110-sticker-local-key.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export const version = 1110;
|
||||
|
||||
export function updateToSchemaVersion1110(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1110) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
ALTER TABLE stickers
|
||||
ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
ALTER TABLE stickers
|
||||
ADD COLUMN localKey TEXT;
|
||||
|
||||
ALTER TABLE stickers
|
||||
ADD COLUMN size INTEGER;
|
||||
`);
|
||||
})();
|
||||
|
||||
db.pragma('user_version = 1110');
|
||||
|
||||
logger.info('updateToSchemaVersion1110: success!');
|
||||
}
|
|
@ -85,10 +85,11 @@ import { updateToSchemaVersion1060 } from './1060-addressable-messages-and-sync-
|
|||
import { updateToSchemaVersion1070 } from './1070-attachment-backup';
|
||||
import { updateToSchemaVersion1080 } from './1080-nondisappearing-addressable';
|
||||
import { updateToSchemaVersion1090 } from './1090-message-delete-indexes';
|
||||
import { updateToSchemaVersion1100 } from './1100-optimize-mark-call-history-read-in-conversation';
|
||||
import {
|
||||
updateToSchemaVersion1100,
|
||||
updateToSchemaVersion1110,
|
||||
version as MAX_VERSION,
|
||||
} from './1100-optimize-mark-call-history-read-in-conversation';
|
||||
} from './1110-sticker-local-key';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2041,7 +2042,9 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1070,
|
||||
updateToSchemaVersion1080,
|
||||
updateToSchemaVersion1090,
|
||||
|
||||
updateToSchemaVersion1100,
|
||||
updateToSchemaVersion1110,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue