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:
Jonathan Schneider
2022-09-12 22:30:43 +02:00
committed by GitHub
parent b1106e183d
commit 212481ff07
6 changed files with 161 additions and 98 deletions

View 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=')}`);
});

View 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);
}