Capture draft attachment's dimensions
This commit is contained in:
parent
951796a389
commit
86d09917a3
3 changed files with 26 additions and 0 deletions
|
@ -113,6 +113,8 @@ export type AttachmentDraftType =
|
||||||
caption?: string;
|
caption?: string;
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
} & BaseAttachmentDraftType)
|
} & BaseAttachmentDraftType)
|
||||||
| {
|
| {
|
||||||
contentType: MIME.MIMEType;
|
contentType: MIME.MIMEType;
|
||||||
|
|
|
@ -34,6 +34,8 @@ export function resolveDraftAttachmentOnDisk(
|
||||||
'fileName',
|
'fileName',
|
||||||
'path',
|
'path',
|
||||||
'size',
|
'size',
|
||||||
|
'width',
|
||||||
|
'height',
|
||||||
]),
|
]),
|
||||||
pending: false,
|
pending: false,
|
||||||
url,
|
url,
|
||||||
|
|
|
@ -6,6 +6,10 @@ import type {
|
||||||
InMemoryAttachmentDraftType,
|
InMemoryAttachmentDraftType,
|
||||||
AttachmentDraftType,
|
AttachmentDraftType,
|
||||||
} from '../types/Attachment';
|
} from '../types/Attachment';
|
||||||
|
import { isImageAttachment } from '../types/Attachment';
|
||||||
|
import { getImageDimensions } from '../types/VisualAttachment';
|
||||||
|
import * as Errors from '../types/errors';
|
||||||
|
import * as logger from '../logging/log';
|
||||||
|
|
||||||
export async function writeDraftAttachment(
|
export async function writeDraftAttachment(
|
||||||
attachment: InMemoryAttachmentDraftType
|
attachment: InMemoryAttachmentDraftType
|
||||||
|
@ -24,10 +28,28 @@ export async function writeDraftAttachment(
|
||||||
)
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
let dimensions: { width?: number; height?: number } = {};
|
||||||
|
if (isImageAttachment(attachment)) {
|
||||||
|
const url = window.Signal.Migrations.getAbsoluteDraftPath(path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
dimensions = await getImageDimensions({
|
||||||
|
objectUrl: url,
|
||||||
|
logger,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
'writeDraftAttachment: failed to capture image dimensions',
|
||||||
|
Errors.toLogFormat(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...omit(attachment, ['data', 'screenshotData']),
|
...omit(attachment, ['data', 'screenshotData']),
|
||||||
path,
|
path,
|
||||||
screenshotPath,
|
screenshotPath,
|
||||||
pending: false,
|
pending: false,
|
||||||
|
...dimensions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue