mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
Rationalize openObjectRLInNewTab
This commit is contained in:
@@ -26,23 +26,6 @@ export type CommonImageMimeTypes = 'image/png' | 'image/jpeg' | 'image/webp';
|
||||
export type LLMImageResizeMode = 'openai-low-res' | 'openai-high-res' | 'google' | 'anthropic' | 'thumbnail-128' | 'thumbnail-256';
|
||||
|
||||
|
||||
/**
|
||||
* Opens a blob URL in a new tab
|
||||
* @returns true if window.open succeeded, false otherwise
|
||||
*/
|
||||
export function showBlobObjectURLInNewTab(blobURL: string): boolean {
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
return window.open(blobURL, '_blank', 'noopener,noreferrer') !== null;
|
||||
} catch (error) {
|
||||
console.warn('showBlobURLInNewTab: Failed to open new tab.', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts an SVG string to a PNG Blob via an intermediate canvas.
|
||||
*/
|
||||
|
||||
@@ -105,6 +105,23 @@ export function extractUrlsFromText(text: string): string[] {
|
||||
return text.match(urlRegex) || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a blob URL in a new tab
|
||||
* @deprecated minimize this usage, prefer to open in the app instead, so we can handle URL revocation properly
|
||||
* @returns true if window.open succeeded, false otherwise
|
||||
*/
|
||||
export function openObjectRLInNewTab(blobURL: string): boolean {
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
return window.open(blobURL, '_blank', 'noopener,noreferrer') !== null;
|
||||
} catch (error) {
|
||||
console.warn('showBlobURLInNewTab: Failed to open new tab.', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// added for future in-app routing
|
||||
// export namespace SearchParams {
|
||||
|
||||
@@ -12,7 +12,7 @@ import { useDBAsset } from '~/modules/dblobs/dblobs.hooks';
|
||||
|
||||
import type { DMessageContentFragment, DMessageDataRef } from '~/common/stores/chat/chat.fragments';
|
||||
import { addSnackbar } from '~/common/components/snackbar/useSnackbarsStore';
|
||||
import { showBlobObjectURLInNewTab } from '~/common/util/imageUtils';
|
||||
import { openObjectRLInNewTab } from '~/common/util/urlUtils';
|
||||
|
||||
import { RenderImageURL, RenderImageURLVariant } from './RenderImageURL';
|
||||
|
||||
@@ -33,7 +33,7 @@ export async function showImageDataRefInNewTab(dataRef: DMessageDataRef) {
|
||||
|
||||
// notify the user that the image has been opened in a new tab (for Safari when it's blocking by default)
|
||||
addSnackbar({ key: 'opened-image-in-new-tab', message: 'Image opened in a New Tab.', type: 'success', closeButton: false, overrides: { autoHideDuration: 1600 } });
|
||||
return showBlobObjectURLInNewTab(imageBlobURL);
|
||||
return openObjectRLInNewTab(imageBlobURL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user