mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(posting): clarify direct file links
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user