MCPcopy Create free account
hub / github.com/FxEmbed/FxEmbed / formatImageUrl

Function formatImageUrl

src/helpers/utils.ts:80–97  ·  view source on GitHub ↗
(url: string, name = 'orig')

Source from the content-addressed store, hash-verified

78};
79
80export const formatImageUrl = (url: string, name = 'orig') => {
81 try {
82 const urlObj = new URL(url);
83 // remove existing name in url in case of conflicting
84 // e.g. https://pbs.twimg.com/media/foobar.jpg:orig
85 urlObj.pathname = urlObj.pathname.replace(/:\w+$/, '');
86
87 if (name) {
88 // add name parameter to url
89 urlObj.searchParams.set('name', name);
90 } else {
91 urlObj.searchParams.delete('name');
92 }
93 return urlObj.toString();
94 } catch (_e) {
95 return url;
96 }
97};
98
99/**
100 * Wraps foreign links through our API to prevent Telegram Instant View from crawling them directly.

Callers 1

handleStatusFunction · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected