Chore: Migrate helpers/parseUrls to Typescript (#3735)

This commit is contained in:
Gleidson Daniel Silva 2022-02-16 12:17:25 -03:00 committed by GitHub
parent 78da41d4f7
commit 941a21dac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 11 deletions

View File

@ -5,13 +5,7 @@ import { IAttachment } from './IAttachment';
import { IEditedBy, IUserChannel, IUserMention, IUserMessage } from './IMessage';
import { IReaction } from './IReaction';
import { SubscriptionType } from './ISubscription';
export interface IUrl {
title: string;
description: string;
image: string;
url: string;
}
import { IUrl } from './IUrl';
interface IFileThread {
_id: string;

View File

@ -1,6 +1,49 @@
export interface IUrl {
_id: number;
title: string;
description: string;
image: string;
url: string;
}
export interface IUrlFromServer {
url: string;
meta: {
pageTitle: string;
description: string;
fbAppId: string;
twitterImageSrc: string;
twitterSite: string;
twitterCard: string;
twitterTitle: string;
twitterDescription: string;
ogImage: string;
ogImageAlt: string;
ogImageWidth: string;
ogImageHeight: string;
ogSiteName: string;
ogType: string;
ogTitle: string;
ogUrl: string;
ogDescription: string;
title: string;
oembedTitle: string;
oembedAuthorName: string;
twitterImage: string;
oembedThumbnailUrl: string;
};
headers: {
contentType: string;
};
parsedUrl: {
host: string;
hash: any;
pathname: string;
protocol: string;
port: any;
query: any;
search: any;
hostname: string;
};
ignoreParse: boolean;
}

View File

@ -23,6 +23,7 @@ export * from './ILoggedUser';
export * from './IServerHistory';
export * from './IRocketChat';
export * from './ICertificate';
export * from './IUrl';
export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
navigation: StackNavigationProp<T, S>;

View File

@ -1,8 +1,10 @@
export default urls =>
import { IUrl, IUrlFromServer } from '../../../definitions';
export default (urls: IUrlFromServer[]): IUrl[] =>
urls
.filter(url => url.meta && !url.ignoreParse)
.map((url, index) => {
const tmp = {};
.filter((url: IUrlFromServer) => url.meta && !url.ignoreParse)
.map((url: IUrlFromServer, index) => {
const tmp: IUrl = {} as any;
const { meta } = url;
tmp._id = index;
tmp.title = meta.ogTitle || meta.twitterTitle || meta.title || meta.pageTitle || meta.oembedTitle;