fix(posting): clarify direct file links

This commit is contained in:
Tommaso Casaburi
2026-05-01 18:03:04 +07:00
parent 9d2f9445a3
commit bc213ecea2
6 changed files with 77 additions and 12 deletions
@@ -11,6 +11,7 @@ vi.mock('../clipboard-utils', () => ({
import {
copyShareLinkToClipboard,
getHostname,
getPublishURLFilename,
is5chanLink,
isPrivateNetworkHostname,
isValidCrossboardPattern,
@@ -57,6 +58,8 @@ describe('url-utils', () => {
expect(isValidPublishURL('https://i.imgur.com/YpB7qfa.jpg')).toBe(true);
expect(isValidPublishURL('ftp://example.com/file.jpg')).toBe(false);
expect(isValidPublishURL('not-a-url')).toBe(false);
expect(getPublishURLFilename('https://example.com/images/file%20name.jpg?size=large')).toBe('file name.jpg');
expect(getPublishURLFilename('not-a-url')).toBeNull();
});
it('copies share links for threads and catalog pages using the production fallback base url', async () => {
+18
View File
@@ -75,6 +75,24 @@ export const isValidPublishURL = (url: string) => {
}
};
export const getPublishURLFilename = (url: string): string | null => {
if (!isValidPublishURL(url)) {
return null;
}
const parsedUrl = new URL(normalizePublishURL(url));
const filename = parsedUrl.pathname.split('/').filter(Boolean).pop();
if (!filename) {
return null;
}
try {
return decodeURIComponent(filename);
} catch {
return filename;
}
};
const CHAN_5_HOSTNAMES = ['5chan.app', '5chan.eth.limo', '5chan.eth.link', '5chan.eth.sucks', '5chan.netlify.app'];
function getShareBaseUrl(): string {