switch from pre-signed to public image links
All checks were successful
/ Make image (push) Successful in 39s

This commit is contained in:
nquidox 2025-10-19 19:37:37 +03:00
parent bb40d17e6b
commit 72b0b00e44
3 changed files with 6 additions and 25 deletions

View file

@ -20,30 +20,16 @@ export const useMerchImagesApi = () => {
} }
} }
const cachedImages = new Map() // Map<uuid, { etag, url }>
const getImageUrl = async (uuid, type) => { const getImageUrl = async (uuid, type) => {
try { try {
const response = await apiClient.get(`/merch/images/${uuid}`, { type }) const response = await apiClient.get(`/merch/images/${uuid}`, { type })
console.log(response.data.link)
if (response.status !== 200) { if (response.status !== 200) {
throw new Error(`Get image failed: ${response.status}`) throw new Error(`Get image failed: ${response.status}`)
} }
const { link, ETag } = response.data return response.data.link
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 }
} catch (error) { } catch (error) {
console.error('Get image failed:', error) console.error('Get image failed:', error)
throw error throw error
@ -53,16 +39,11 @@ export const useMerchImagesApi = () => {
const deleteImage = async (uuid) => { const deleteImage = async (uuid) => {
try { try {
const response = await apiClient.delete(`/merch/images/${uuid}`) const response = await apiClient.delete(`/merch/images/${uuid}`)
if (response.status !== 200) { if (response.status !== 200) {
throw new Error(`Delete failed: ${response.status}`) 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 return true
} catch (error) { } catch (error) {
console.error('Delete image failed:', error) console.error('Delete image failed:', error)

View file

@ -15,7 +15,7 @@ const fileList = ref([])
onMounted(async () => { onMounted(async () => {
try { try {
const { imgUrl } = await getImageUrl(props.merch.merch_uuid, 'thumbnail') const imgUrl = await getImageUrl(props.merch.merch_uuid, 'thumbnail')
fileList.value = [ fileList.value = [
{ {
name: 'full.jpg', name: 'full.jpg',

View file

@ -1,6 +1,6 @@
<script setup> <script setup>
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import { NModal, NUpload, useMessage } from 'naive-ui' import { NModal, useMessage } from 'naive-ui'
import BoxIcon from '@/components/icons/BoxIcon.vue' import BoxIcon from '@/components/icons/BoxIcon.vue'
import { useMerchImagesApi } from '@/api/merchImages.js' import { useMerchImagesApi } from '@/api/merchImages.js'
@ -77,7 +77,7 @@ async function handleUpload({ fileList: newFileList }) {
onMounted(async () => { onMounted(async () => {
try { try {
const { imgUrl } = await getImageUrl(props.merchUuid, 'full') const imgUrl = await getImageUrl(props.merchUuid, 'full')
fileList.value = [ fileList.value = [
{ {
name: 'full.jpg', name: 'full.jpg',