switch from pre-signed to public image links
All checks were successful
/ Make image (push) Successful in 39s
All checks were successful
/ Make image (push) Successful in 39s
This commit is contained in:
parent
bb40d17e6b
commit
72b0b00e44
3 changed files with 6 additions and 25 deletions
|
|
@ -20,30 +20,16 @@ export const useMerchImagesApi = () => {
|
|||
}
|
||||
}
|
||||
|
||||
const cachedImages = new Map() // Map<uuid, { etag, url }>
|
||||
const getImageUrl = async (uuid, type) => {
|
||||
try {
|
||||
const response = await apiClient.get(`/merch/images/${uuid}`, { type })
|
||||
console.log(response.data.link)
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Get image failed: ${response.status}`)
|
||||
}
|
||||
|
||||
const { link, ETag } = response.data
|
||||
|
||||
if (cachedImages.has(uuid) && cachedImages.get(uuid).etag === ETag) {
|
||||
return cachedImages.get(uuid)
|
||||
}
|
||||
|
||||
const res = await fetch(link)
|
||||
if (!res.ok) throw new Error(`Failed to load image: ${res.status}`)
|
||||
|
||||
const blob = await res.blob()
|
||||
const imgUrl = URL.createObjectURL(blob)
|
||||
|
||||
cachedImages.set(uuid, { imgUrl, etag: ETag })
|
||||
return { imgUrl, etag: ETag }
|
||||
|
||||
return response.data.link
|
||||
} catch (error) {
|
||||
console.error('Get image failed:', error)
|
||||
throw error
|
||||
|
|
@ -53,16 +39,11 @@ export const useMerchImagesApi = () => {
|
|||
const deleteImage = async (uuid) => {
|
||||
try {
|
||||
const response = await apiClient.delete(`/merch/images/${uuid}`)
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Delete failed: ${response.status}`)
|
||||
}
|
||||
|
||||
if (cachedImages.has(uuid)) {
|
||||
const cached = cachedImages.get(uuid)
|
||||
if (cached.imgUrl?.startsWith('blob:')) URL.revokeObjectURL(cached.imgUrl)
|
||||
cachedImages.delete(uuid)
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Delete image failed:', error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue