fix: presentUnfurl

This commit is contained in:
Apoorv Mishra
2023-07-23 20:39:16 +05:30
parent 8b3c58a162
commit a30487c2d7
3 changed files with 20 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
import { Unfurl } from "@shared/types";
function presentUnfurl(data: any): Unfurl {
return {
url: data.url,
type: data.type,
title: data.title,
description: data.description,
thumbnailUrl: data.thumbnail_url,
meta: data.meta,
};
}
export default presentUnfurl;

View File

@@ -8,6 +8,7 @@ import validate from "@server/middlewares/validate";
import { Document, User } from "@server/models"; import { Document, User } from "@server/models";
import { authorize } from "@server/policies"; import { authorize } from "@server/policies";
import { presentDocument, presentMention } from "@server/presenters/unfurls"; import { presentDocument, presentMention } from "@server/presenters/unfurls";
import presentUnfurl from "@server/presenters/unfurls/unfurl";
import { APIContext } from "@server/types"; import { APIContext } from "@server/types";
import { RateLimiterStrategy } from "@server/utils/RateLimiter"; import { RateLimiterStrategy } from "@server/utils/RateLimiter";
import { Iframely } from "@server/utils/unfurl"; import { Iframely } from "@server/utils/unfurl";
@@ -62,7 +63,7 @@ router.post(
} }
const data = await Iframely.unfurl(url); const data = await Iframely.unfurl(url);
ctx.body = data; ctx.body = presentUnfurl(data);
} }
); );

View File

@@ -214,13 +214,15 @@ export enum UnfurlType {
Document = "document", Document = "document",
} }
export type Unfurl<T = unknown> = { export type OEmbedType = "photo" | "video" | "rich";
export type Unfurl<T = OEmbedType> = {
url?: string; url?: string;
type: T; type: T;
title: string; title: string;
description: string; description: string;
thumbnailUrl?: string | null; thumbnailUrl?: string | null;
meta: Record<string, string>; meta?: Record<string, string>;
}; };
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any