mirror of
https://github.com/directus/directus.git
synced 2026-02-14 18:45:05 -05:00
Add missing download and token parameter in File interface (#14871)
* add missing download and token parameter * add download name * update all file download links (:download and :href), update icon, add single file drawer download * add filename_download to adjustFieldsForDisplays * add new computed use asset url logic * switch composable to utility function * switch to new URL and add tests * add getAssetUrl to file-image * Update app/src/interfaces/files/files.vue Co-authored-by: Nitwel <mail@nitwel.de> * update code style error * add download to drawer of file-image, fix wrong css selector and update preview download icon * Remove debugging database Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com> Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: ian <licitdev@gmail.com> Co-authored-by: Nitwel <mail@nitwel.de>
This commit is contained in:
committed by
GitHub
parent
b1106e183d
commit
212481ff07
31
app/src/utils/get-asset-url.test.ts
Normal file
31
app/src/utils/get-asset-url.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { test, expect, vi } from 'vitest';
|
||||
|
||||
import { cryptoStub } from '@/__utils__/crypto';
|
||||
vi.stubGlobal('crypto', cryptoStub);
|
||||
|
||||
import { addTokenToURL } from '@/api';
|
||||
import { getAssetUrl } from '@/utils/get-asset-url';
|
||||
|
||||
test('Get asset url', () => {
|
||||
global.window.location.href = 'https://directus.io/admin/test/';
|
||||
const output = getAssetUrl('test.jpg');
|
||||
expect(output).toBe(`https://directus.io${addTokenToURL('/assets/test.jpg')}`);
|
||||
});
|
||||
|
||||
test('Get asset url for download', () => {
|
||||
global.window.location.href = 'https://directus.io/admin/test/';
|
||||
const output = getAssetUrl('test.jpg', true);
|
||||
expect(output).toBe(`https://directus.io${addTokenToURL('/assets/test.jpg?download=')}`);
|
||||
});
|
||||
|
||||
test('Subdirectory Install: Get asset url', () => {
|
||||
global.window.location.href = 'https://directus.io/subdirectory/admin/test/';
|
||||
const output = getAssetUrl('test.jpg');
|
||||
expect(output).toBe(`https://directus.io/subdirectory${addTokenToURL('/assets/test.jpg')}`);
|
||||
});
|
||||
|
||||
test('Subdirectory Install: Get asset url for download', () => {
|
||||
global.window.location.href = 'https://directus.io/subdirectory/admin/test/';
|
||||
const output = getAssetUrl('test.jpg', true);
|
||||
expect(output).toBe(`https://directus.io/subdirectory${addTokenToURL('/assets/test.jpg?download=')}`);
|
||||
});
|
||||
12
app/src/utils/get-asset-url.ts
Normal file
12
app/src/utils/get-asset-url.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { addTokenToURL } from '@/api';
|
||||
import { getPublicURL } from '@/utils/get-root-path';
|
||||
|
||||
export function getAssetUrl(filename: string, isDownload?: boolean): string {
|
||||
const assetUrl = new URL(`assets/${filename}`, getPublicURL());
|
||||
|
||||
if (isDownload) {
|
||||
assetUrl.searchParams.set('download', '');
|
||||
}
|
||||
|
||||
return addTokenToURL(assetUrl.href);
|
||||
}
|
||||
Reference in New Issue
Block a user