Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
1.3 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

import type {MediaProxyNsfwMode} from '@app/api/infrastructure/IMediaService';
import type {MessageEmbedResponse} from '@fluxer/schema/src/domains/message/EmbedSchemas';

export interface UnfurlResult {
	embeds: Array<MessageEmbedResponse>;
	cacheTtlSeconds: number | null;
}

export interface UnfurlOptions {
	signal?: AbortSignal;
	bypassCache?: boolean;
	cacheOnly?: boolean;
}

export interface ExternalFetchRequest {
	method: string;
	url: string;
	headers: Array<[string, string]>;
	body: string | null;
}

export interface ExternalFetchResponse {
	status: number;
	headers: Array<[string, string]>;
	body: string;
}

export abstract class IUnfurlerService {
	async unfurl(
		url: string,
		nsfwMode?: MediaProxyNsfwMode,
		options: UnfurlOptions = {},
	): Promise<Array<MessageEmbedResponse>> {
		return (await this.unfurlWithCachePolicy(url, nsfwMode, options)).embeds;
	}

	abstract unfurlWithCachePolicy(
		url: string,
		nsfwMode?: MediaProxyNsfwMode,
		options?: UnfurlOptions,
	): Promise<UnfurlResult>;

	abstract verifyDomain(domain: string, token: string): Promise<boolean>;

	abstract fetchExternal(request: ExternalFetchRequest): Promise<ExternalFetchResponse>;

	abstract resolveTxt(name: string): Promise<Array<string>>;

	abstract activityPubPublicKey(): Promise<string | null>;
}