mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
export const MEDIA_PROXY_METADATA_REQUEST_VERSION = 2 as const;
|
|
|
|
export type MediaProxyNsfwMode = 'block' | 'flag' | 'allow';
|
|
|
|
export function mediaProxyMetadataPolicy(nsfw: MediaProxyNsfwMode): MediaProxyMetadataPolicy {
|
|
return {
|
|
version: MEDIA_PROXY_METADATA_REQUEST_VERSION,
|
|
nsfw,
|
|
};
|
|
}
|
|
|
|
interface MediaProxyMetadataPolicy {
|
|
version?: typeof MEDIA_PROXY_METADATA_REQUEST_VERSION;
|
|
nsfw: MediaProxyNsfwMode;
|
|
}
|
|
|
|
type MediaProxyMetadataExternalRequest = {
|
|
type: 'external';
|
|
url: string;
|
|
with_base64?: boolean;
|
|
} & MediaProxyMetadataPolicy;
|
|
type MediaProxyMetadataUploadRequest = {
|
|
type: 'upload';
|
|
upload_filename: string;
|
|
filename?: string;
|
|
} & MediaProxyMetadataPolicy;
|
|
type MediaProxyMetadataBase64Request = {
|
|
type: 'base64';
|
|
base64: string;
|
|
} & MediaProxyMetadataPolicy;
|
|
type MediaProxyMetadataS3Request = {
|
|
type: 's3';
|
|
bucket: string;
|
|
key: string;
|
|
with_base64?: boolean;
|
|
} & MediaProxyMetadataPolicy;
|
|
export type MediaProxyMetadataRequest =
|
|
| MediaProxyMetadataExternalRequest
|
|
| MediaProxyMetadataUploadRequest
|
|
| MediaProxyMetadataBase64Request
|
|
| MediaProxyMetadataS3Request;
|
|
|
|
export interface MediaProxyMetadataOptions {
|
|
sizeBytes?: number;
|
|
}
|
|
|
|
export interface MediaProxyMetadataResponse {
|
|
format: string;
|
|
content_type: string;
|
|
content_hash: string;
|
|
size: number;
|
|
width?: number | null;
|
|
height?: number | null;
|
|
duration?: number;
|
|
placeholder?: string;
|
|
base64?: string;
|
|
animated?: boolean;
|
|
nsfw: boolean;
|
|
nsfw_probability?: number;
|
|
}
|
|
|
|
export interface MediaProxySniffResponse {
|
|
content_type: string | null;
|
|
}
|
|
|
|
export abstract class IMediaService {
|
|
abstract getMetadata(
|
|
request: MediaProxyMetadataRequest,
|
|
options?: MediaProxyMetadataOptions,
|
|
): Promise<MediaProxyMetadataResponse | null>;
|
|
|
|
abstract getExternalMediaProxyURL(url: string): string;
|
|
|
|
abstract sniffUpload(uploadFilename: string): Promise<MediaProxySniffResponse | null>;
|
|
}
|