Fix URL for subfolder assets (#15126)

* Prevent duplicate rootPath for image in file-preview

* Add rootPath to file and file-image for downloading

* Revert change to v-image

* Patch rootPaths accordingly

* Fix missing file name on download
This commit is contained in:
ian
2022-08-18 02:03:29 +08:00
committed by GitHub
parent d6bfef40cc
commit 122f8cfed0
6 changed files with 15 additions and 9 deletions

View File

@@ -76,6 +76,7 @@ import api, { addTokenToURL } from '@/api';
import { useRelationM2O } from '@/composables/use-relation-m2o';
import { RelationQuerySingle, useRelationSingle } from '@/composables/use-relation-single';
import { formatFilesize } from '@/utils/format-filesize';
import { getRootPath } from '@/utils/get-root-path';
import { readableMimeType } from '@/utils/readable-mime-type';
import DrawerItem from '@/views/private/components/drawer-item.vue';
import FileLightbox from '@/views/private/components/file-lightbox.vue';
@@ -143,7 +144,7 @@ const ext = computed(() => (image.value ? readableMimeType(image.value.type, tru
const downloadSrc = computed(() => {
if (!image.value) return null;
return addTokenToURL('/assets/' + image.value.id);
return addTokenToURL(getRootPath() + 'assets/' + image.value.id);
});
const meta = computed(() => {

View File

@@ -46,7 +46,7 @@
<v-list>
<template v-if="file">
<v-list-item :download="file.filename_download" :href="assetURL">
<v-list-item :download="file.filename_download" :href="downloadURL">
<v-list-item-icon><v-icon name="get_app" /></v-list-item-icon>
<v-list-item-content>{{ t('download_file') }}</v-list-item-content>
</v-list-item>
@@ -141,7 +141,7 @@
import { useI18n } from 'vue-i18n';
import { ref, computed, toRefs } from 'vue';
import DrawerCollection from '@/views/private/components/drawer-collection.vue';
import api from '@/api';
import api, { addTokenToURL } from '@/api';
import { readableMimeType } from '@/utils/readable-mime-type';
import { unexpectedError } from '@/utils/unexpected-error';
import DrawerItem from '@/views/private/components/drawer-item.vue';
@@ -149,6 +149,7 @@ import { addQueryToPath } from '@/utils/add-query-to-path';
import { useRelationM2O } from '@/composables/use-relation-m2o';
import { useRelationSingle, RelationQuerySingle } from '@/composables/use-relation-single';
import { Filter } from '@directus/shared/types';
import { getRootPath } from '@/utils/get-root-path';
type FileInfo = {
id: string;
@@ -207,6 +208,10 @@ const assetURL = computed(() => {
return '/assets/' + id;
});
const downloadURL = computed(() => {
return addTokenToURL(getRootPath() + assetURL.value.slice(1));
});
const imageThumbnail = computed(() => {
if (file.value === null || props.value === null) return null;
if (file.value.type.includes('svg')) return assetURL.value;

View File

@@ -314,7 +314,7 @@ function onUpload(files: Record<string, any>[]) {
const downloadUrl = computed(() => {
if (relatedPrimaryKey.value === null || relationInfo.value?.relatedCollection.collection !== 'directus_files') return;
return addTokenToURL(getRootPath() + `assets/${relatedPrimaryKey.value}`);
return addTokenToURL(getRootPath() + `assets/${relatedPrimaryKey.value}?download`);
});
function getUrl(junctionRow: Record<string, any>, addDownload?: boolean) {