mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post-form): hide filename for non-file media links
Only show pasted link filenames when the URL resolves to publishable file media, so bare paths like imgur album IDs are not shown as files.
This commit is contained in:
@@ -309,7 +309,7 @@ vi.mock('../../../hooks/use-file-upload', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('../../loading-ellipsis', () => ({
|
||||
vi.mock('../../loading-ellipsis/loading-ellipsis', () => ({
|
||||
default: ({ string }: { string: string }) => createElement('span', { 'data-testid': 'loading-ellipsis' }, string),
|
||||
}));
|
||||
|
||||
@@ -331,19 +331,26 @@ vi.mock('../../../lib/utils/media-utils', () => {
|
||||
return {
|
||||
getDisplayMediaInfoType: (type: string, t: (key: string) => string) => t(type),
|
||||
getLinkMediaInfo: (link: string) => {
|
||||
const path = (() => {
|
||||
try {
|
||||
return new URL(link).pathname;
|
||||
} catch {
|
||||
return link;
|
||||
}
|
||||
})();
|
||||
if (getTwimgMediaFilePublishUrl(link)) {
|
||||
return { type: 'image', url: link };
|
||||
}
|
||||
if (link.endsWith('.gif')) {
|
||||
if (path.endsWith('.gif')) {
|
||||
return { type: 'gif', url: link };
|
||||
}
|
||||
if (link.endsWith('.jpg') || link.endsWith('.jpeg') || link.endsWith('.png')) {
|
||||
if (path.endsWith('.jpg') || path.endsWith('.jpeg') || path.endsWith('.png')) {
|
||||
return { type: 'image', url: link };
|
||||
}
|
||||
if (link.endsWith('.mp4')) {
|
||||
if (path.endsWith('.mp4')) {
|
||||
return { type: 'video', url: link };
|
||||
}
|
||||
if (link.endsWith('.mp3')) {
|
||||
if (path.endsWith('.mp3')) {
|
||||
return { type: 'audio', url: link };
|
||||
}
|
||||
if (link.includes('youtube.com')) {
|
||||
@@ -1306,6 +1313,23 @@ describe('PostForm', () => {
|
||||
expect(table?.textContent).toContain('file name.jpg');
|
||||
});
|
||||
|
||||
it('does not show a pasted non-file path segment next to the upload button', async () => {
|
||||
testState.uploadedFileName = null;
|
||||
|
||||
await renderPostForm('/all');
|
||||
await clickByText(container, 'start_new_thread');
|
||||
|
||||
const table = container.querySelector('table');
|
||||
const textInputs = table?.querySelectorAll<HTMLInputElement>('input[type="text"]') || [];
|
||||
const linkInput = textInputs[3];
|
||||
|
||||
await dispatchInput(linkInput as HTMLInputElement, 'https://imgur.com/8EJ2T76');
|
||||
|
||||
expect(table?.textContent).toContain('not_a_file');
|
||||
expect(table?.textContent).toContain('no_file_chosen');
|
||||
expect(table?.textContent).not.toContain('8EJ2T76');
|
||||
});
|
||||
|
||||
it('shows the rules and FAQ prompt at the bottom of the form with a board-specific rules link', async () => {
|
||||
testState.resolvedCommunityAddress = 'music-posting.eth';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user