import classNames from "classnames"; import { Component } from "inferno"; import { UserService } from "../../services"; const iconThumbnailSize = 96; const thumbnailSize = 256; interface PictrsImageProps { src: string; alt?: string; icon?: boolean; banner?: boolean; thumbnail?: boolean; nsfw?: boolean; iconOverlay?: boolean; pushup?: boolean; } export class PictrsImage extends Component { constructor(props: any, context: any) { super(props, context); } render() { let user_blur_nsfw = true; if (UserService.Instance.myUserInfo) { user_blur_nsfw = UserService.Instance.myUserInfo?.local_user_view.local_user.blur_nsfw; } const blur_image = this.props.nsfw && user_blur_nsfw; return ( {this.alt()} ); } src(format: string): string { // sample url: // http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg const split = this.props.src.split("/pictrs/image/"); // If theres not multiple, then its not a pictrs image if (split.length === 1) { return this.props.src; } const host = split[0]; const path = split[1]; const params = { format }; if (this.props.thumbnail) { params["thumbnail"] = thumbnailSize; } else if (this.props.icon) { params["thumbnail"] = iconThumbnailSize; } const paramsStr = new URLSearchParams(params).toString(); const out = `${host}/pictrs/image/${path}?${paramsStr}`; return out; } alt(): string { if (this.props.icon) { return ""; } return this.props.alt || ""; } }