Move get asset function into same API file
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getAssetUrlKey } from '$utils/helpers'
|
import { getAssetUrlKey } from '$utils/api'
|
||||||
|
|
||||||
export let src: string = undefined
|
export let src: string = undefined
|
||||||
export let id: string = undefined
|
export let id: string = undefined
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
import { onMount, tick } from 'svelte'
|
import { onMount, tick } from 'svelte'
|
||||||
import { fade, scale } from 'svelte/transition'
|
import { fade, scale } from 'svelte/transition'
|
||||||
import { quartOut } from 'svelte/easing'
|
import { quartOut } from 'svelte/easing'
|
||||||
import { getAssetUrlKey } from '$utils/helpers'
|
import { fetchAPI, getAssetUrlKey } from '$utils/api'
|
||||||
import { fetchAPI } from '$utils/api'
|
|
||||||
import { previousPage } from '$utils/stores'
|
import { previousPage } from '$utils/stores'
|
||||||
import { throttle } from '$utils/functions'
|
import { throttle } from '$utils/functions'
|
||||||
import { swipe } from '$utils/interactions/swipe'
|
import { swipe } from '$utils/interactions/swipe'
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
import { timeline } from 'motion'
|
import { timeline } from 'motion'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime.js'
|
import relativeTime from 'dayjs/plugin/relativeTime.js'
|
||||||
import { getAssetUrlKey } from '$utils/helpers'
|
|
||||||
import { quartOut } from '$animations/easings'
|
import { quartOut } from '$animations/easings'
|
||||||
import { fetchAPI } from '$utils/api'
|
import { fetchAPI, getAssetUrlKey } from '$utils/api'
|
||||||
import { DELAY, DURATION } from '$utils/contants'
|
import { DELAY, DURATION } from '$utils/contants'
|
||||||
import { photoFields } from '.'
|
import { photoFields } from '.'
|
||||||
// Components
|
// Components
|
||||||
|
|||||||
@@ -27,4 +27,38 @@ export const fetchAPI = async (query: string) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
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}`
|
||||||
|
// }
|
||||||
@@ -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}`
|
|
||||||
// }
|
|
||||||
Reference in New Issue
Block a user