refactor: 将文件请求由app端转到server端
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m2s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m2s
This commit is contained in:
@ -122,6 +122,8 @@
|
||||
const errorText = computed(() => error.value?.message ?? null);
|
||||
const fileMeta = computed(() => props.file ?? data.value ?? null);
|
||||
|
||||
logger.debug('FilePreviewer - fileMeta:', fileMeta.value);
|
||||
|
||||
/** 预览源地址:支持在 file.url 上追加额外 query(如临时 token、inline) */
|
||||
const src = computed<string>(() => {
|
||||
if (!fileMeta.value) return '';
|
||||
|
||||
@ -1,19 +1,14 @@
|
||||
export const useDirectusFiles = () => {
|
||||
const config = useRuntimeConfig();
|
||||
const baseUrl = config.public.directus.url;
|
||||
|
||||
const getFileUrl = (
|
||||
id?: string | null,
|
||||
options?: Record<string, string | number | boolean>
|
||||
): string => {
|
||||
if (!id) return '';
|
||||
const query = options
|
||||
? '?' +
|
||||
new URLSearchParams(
|
||||
Object.entries(options).map(([key, value]) => [key, String(value)])
|
||||
).toString()
|
||||
: '';
|
||||
return `${baseUrl}/assets/${id}${query}`;
|
||||
|
||||
const params = new URLSearchParams(
|
||||
options as Record<string, string>
|
||||
).toString();
|
||||
return `/api/assets/${id}${params ? `?${params}` : ''}`;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
export const useDirectusImage = () => {
|
||||
const config = useRuntimeConfig();
|
||||
const baseUrl = config.public.directus.url;
|
||||
const token = config.public.directus.token;
|
||||
|
||||
type DirectusAssetParams = {
|
||||
width?: number;
|
||||
height?: number;
|
||||
@ -13,19 +9,11 @@ export const useDirectusImage = () => {
|
||||
|
||||
const getImageUrl = (id?: string | null, options?: DirectusAssetParams) => {
|
||||
if (!id) return '';
|
||||
const queryToken = token ? 'access_token=' + token : '';
|
||||
const queryOptions = options
|
||||
? new URLSearchParams(
|
||||
Object.fromEntries(
|
||||
Object.entries(options).map(([key, value]) => [key, String(value)])
|
||||
)
|
||||
).toString
|
||||
: '';
|
||||
const query =
|
||||
queryToken || queryOptions
|
||||
? `?${[queryToken, queryOptions].filter(Boolean).join('&')}`
|
||||
: '';
|
||||
return `${baseUrl}/assets/${id}${query}`;
|
||||
|
||||
const params = new URLSearchParams(
|
||||
options as Record<string, string>
|
||||
).toString();
|
||||
return `/api/assets/${id}${params ? `?${params}` : ''}`;
|
||||
};
|
||||
|
||||
return { getImageUrl };
|
||||
|
||||
Reference in New Issue
Block a user