ConversationView: Improve types

This commit is contained in:
Scott Nonnenberg 2021-08-30 14:32:56 -07:00 committed by GitHub
parent c765d3202c
commit dcf29078f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1101 additions and 941 deletions

View file

@ -73,28 +73,55 @@ export type DownloadedAttachmentType = AttachmentType & {
data: ArrayBuffer;
};
type BaseAttachmentDraftType = {
export type BaseAttachmentDraftType = {
blurHash?: string;
contentType: MIME.MIMEType;
fileName: string;
path: string;
screenshotContentType?: string;
screenshotSize?: number;
size: number;
};
export type InMemoryAttachmentDraftType = {
data?: ArrayBuffer;
screenshotData?: ArrayBuffer;
} & BaseAttachmentDraftType;
export type InMemoryAttachmentDraftType =
| ({
data?: ArrayBuffer;
pending: false;
screenshotData?: ArrayBuffer;
} & BaseAttachmentDraftType)
| {
contentType: MIME.MIMEType;
fileName: string;
path: string;
pending: true;
};
export type OnDiskAttachmentDraftType = {
path?: string;
screenshotPath?: string;
} & BaseAttachmentDraftType;
export type OnDiskAttachmentDraftType =
| ({
caption?: string;
pending: false;
screenshotPath?: string;
} & BaseAttachmentDraftType)
| {
contentType: MIME.MIMEType;
fileName: string;
path: string;
pending: true;
};
export type AttachmentDraftType = {
url: string;
} & BaseAttachmentDraftType;
export type AttachmentDraftType =
| ({
url: string;
screenshotPath?: string;
caption?: string;
pending: false;
} & BaseAttachmentDraftType)
| {
contentType: MIME.MIMEType;
fileName: string;
path: string;
pending: true;
};
export type ThumbnailType = {
height: number;

View file

@ -69,9 +69,13 @@ export function findLinks(text: string, caretLocation?: number): Array<string> {
);
}
export function getDomain(href: string): string | undefined {
export function getDomain(href: string): string {
const url = maybeParseUrl(href);
return url ? url.hostname : undefined;
if (!url || !url.hostname) {
throw new Error('getDomain: Unable to extract hostname from href');
}
return url.hostname;
}
// See <https://tools.ietf.org/html/rfc3986>.