Move get asset function into same API file

This commit is contained in:
2022-08-14 12:12:30 +02:00
parent f504b45957
commit fa74e5bf7f
5 changed files with 38 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { getAssetUrlKey } from '$utils/helpers'
import { getAssetUrlKey } from '$utils/api'
export let src: string = undefined
export let id: string = undefined

View File

@@ -9,8 +9,7 @@
import { onMount, tick } from 'svelte'
import { fade, scale } from 'svelte/transition'
import { quartOut } from 'svelte/easing'
import { getAssetUrlKey } from '$utils/helpers'
import { fetchAPI } from '$utils/api'
import { fetchAPI, getAssetUrlKey } from '$utils/api'
import { previousPage } from '$utils/stores'
import { throttle } from '$utils/functions'
import { swipe } from '$utils/interactions/swipe'

View File

@@ -8,9 +8,8 @@
import { timeline } from 'motion'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime.js'
import { getAssetUrlKey } from '$utils/helpers'
import { quartOut } from '$animations/easings'
import { fetchAPI } from '$utils/api'
import { fetchAPI, getAssetUrlKey } from '$utils/api'
import { DELAY, DURATION } from '$utils/contants'
import { photoFields } from '.'
// Components

View File

@@ -28,3 +28,37 @@ export const fetchAPI = async (query: string) => {
console.error(error)
}
}
/**
* Get a Directus asset URL from parameters
*/
export const getAssetUrlKey = (
id: string,
key: string
) => {
if (!id || !key) return null
return `${API_URL}/assets/${id}?key=${key}`
}
/**
* Get a Directus asset URL from parameters
*/
// export const getAssetUrl = (
// id: string,
// width: number,
// height: number,
// quality?: number,
// fit: string = 'inside',
// format?: string
// ) => {
// let args = ''
// // Add arguments to URL if specified
// if (quality) args += `&quality=${quality}`
// if (format) args += `&format=${format}`
// return `${API_URL}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
// }

View File

@@ -1,33 +0,0 @@
import { API_URL } from '$utils/api'
/**
* Get a Directus asset URL from parameters
*/
export const getAssetUrlKey = (
id: string,
key: string
) => {
return `${API_URL}/assets/${id}?key=${key}`
}
/**
* Get a Directus asset URL from parameters
*/
// export const getAssetUrl = (
// id: string,
// width: number,
// height: number,
// quality?: number,
// fit: string = 'inside',
// format?: string
// ) => {
// let args = ''
// // Add arguments to URL if specified
// if (quality) args += `&quality=${quality}`
// if (format) args += `&format=${format}`
// return `${API_URL}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
// }