Compare commits
No commits in common. "0c576c078768bcb671360e360362f0d45d9b5d7f" and "72b0b00e4405addfad7f619f23a9995416c0a77b" have entirely different histories.
0c576c0787
...
72b0b00e44
6 changed files with 656 additions and 632 deletions
1178
package-lock.json
generated
1178
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +1,6 @@
|
||||||
import { apiClient } from '@/services/apiClient.js'
|
import { apiClient } from '@/services/apiClient.js'
|
||||||
import { useAuthStore } from '@/stores/authStore.js'
|
|
||||||
import { IMAGE_STORAGE_URL } from '@/main.js'
|
|
||||||
|
|
||||||
export const useMerchImagesApi = () => {
|
export const useMerchImagesApi = () => {
|
||||||
const authStore = useAuthStore()
|
|
||||||
|
|
||||||
const uploadImage = async (uuid, file) => {
|
const uploadImage = async (uuid, file) => {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
|
|
@ -17,30 +13,28 @@ export const useMerchImagesApi = () => {
|
||||||
throw new Error(`Upload failed: ${response.status}`)
|
throw new Error(`Upload failed: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { fullImage, thumbnail } = response.data
|
return response.data
|
||||||
|
|
||||||
return {
|
|
||||||
fullImage,
|
|
||||||
thumbnail,
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Upload failed:', error)
|
console.error('Upload failed:', error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getImageUrl = (merchUuid, type = 'full') => {
|
const getImageUrl = async (uuid, type) => {
|
||||||
const userUuid = authStore.userUuid;
|
try {
|
||||||
if (!userUuid) throw new Error('userUuid not found in store');
|
const response = await apiClient.get(`/merch/images/${uuid}`, { type })
|
||||||
|
console.log(response.data.link)
|
||||||
|
|
||||||
const allowedTypes = ['full', 'thumbnail'];
|
if (response.status !== 200) {
|
||||||
if (!allowedTypes.includes(type)) {
|
throw new Error(`Get image failed: ${response.status}`)
|
||||||
throw new Error(`Invalid type: ${type}. Allowed values: ${allowedTypes.join(', ')}`);
|
}
|
||||||
|
|
||||||
|
return response.data.link
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Get image failed:', error)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return `${IMAGE_STORAGE_URL}/merchImages/${userUuid}/${merchUuid}?type=${type}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const deleteImage = async (uuid) => {
|
const deleteImage = async (uuid) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ export const BASE_URL = 'https://api.nqws.ru/api/v2'
|
||||||
// export const BASE_URL = 'http://localhost:9090/api/v2'
|
// export const BASE_URL = 'http://localhost:9090/api/v2'
|
||||||
|
|
||||||
export const BASE_MANDARAKE_LINK = 'https://order.mandarake.co.jp/order/listPage/list?soldOut=1&keyword='
|
export const BASE_MANDARAKE_LINK = 'https://order.mandarake.co.jp/order/listPage/list?soldOut=1&keyword='
|
||||||
// export const IMAGE_STORAGE_URL = 'http://localhost:9280'
|
|
||||||
export const IMAGE_STORAGE_URL = 'https://images.nqws.ru'
|
|
||||||
|
|
||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,11 @@ import { computed, ref } from 'vue'
|
||||||
import { apiClient } from '@/services/apiClient'
|
import { apiClient } from '@/services/apiClient'
|
||||||
import router from '@/router/index.js'
|
import router from '@/router/index.js'
|
||||||
|
|
||||||
function parseJwt(token) {
|
|
||||||
try {
|
|
||||||
const base64Url = token.split('.')[1]
|
|
||||||
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
|
|
||||||
const jsonPayload = decodeURIComponent(
|
|
||||||
atob(base64)
|
|
||||||
.split('')
|
|
||||||
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
||||||
.join('')
|
|
||||||
)
|
|
||||||
return JSON.parse(jsonPayload)
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Invalid JWT:', e)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
// state
|
// state
|
||||||
const accessToken = ref(localStorage.getItem('accessToken'))
|
const accessToken = ref(localStorage.getItem('accessToken'))
|
||||||
const userUuid = ref(localStorage.getItem('userUuid') || null)
|
|
||||||
const user = ref(null)
|
const user = ref(null)
|
||||||
|
|
||||||
const activeTab = ref('signin')
|
const activeTab = ref('signin')
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
|
@ -33,20 +16,10 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
// actions
|
// actions
|
||||||
const setToken = (token) => {
|
const setToken = (token) => {
|
||||||
accessToken.value = token
|
accessToken.value = token
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
localStorage.setItem('accessToken', token)
|
localStorage.setItem('accessToken', token)
|
||||||
|
|
||||||
const decoded = parseJwt(token)
|
|
||||||
const uuid = decoded?.sub
|
|
||||||
if (uuid) {
|
|
||||||
userUuid.value = uuid
|
|
||||||
localStorage.setItem('userUuid', uuid)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('accessToken')
|
localStorage.removeItem('accessToken')
|
||||||
localStorage.removeItem('userUuid')
|
|
||||||
userUuid.value = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +68,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
const response = await apiClient.get('/user/')
|
const response = await apiClient.get('/user/')
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('User info error:', error)
|
console.error('Register error:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,13 +77,12 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
const response = await apiClient.get('/user/auth/current-session')
|
const response = await apiClient.get('/user/auth/current-session')
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Current session error:', error)
|
console.error('Register error:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessToken,
|
accessToken,
|
||||||
userUuid,
|
|
||||||
user,
|
user,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
activeTab,
|
activeTab,
|
||||||
|
|
|
||||||
|
|
@ -15,29 +15,22 @@ const fileList = ref([])
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const imgUrl = getImageUrl(props.merch.merch_uuid, 'thumbnail')
|
const imgUrl = await getImageUrl(props.merch.merch_uuid, 'thumbnail')
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const img = new Image()
|
|
||||||
img.src = imgUrl
|
|
||||||
img.onload = () => resolve(imgUrl)
|
|
||||||
img.onerror = () => reject(new Error('Image not found'))
|
|
||||||
})
|
|
||||||
|
|
||||||
fileList.value = [
|
fileList.value = [
|
||||||
{
|
{
|
||||||
name: 'thumbnail.jpg',
|
name: 'full.jpg',
|
||||||
url: imgUrl,
|
url: imgUrl,
|
||||||
status: 'finished',
|
status: 'finished',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fileList.value = []
|
fileList.value = []
|
||||||
if (!error.message.includes('404')) {
|
if (!error.message?.includes('404')) {
|
||||||
console.error('Error getting thumbnail: ', error)
|
console.error('Error getting image: ', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
|
|
@ -77,29 +77,21 @@ async function handleUpload({ fileList: newFileList }) {
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const imgUrl = getImageUrl(props.merchUuid, 'full');
|
const imgUrl = await getImageUrl(props.merchUuid, 'full')
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const img = new Image();
|
|
||||||
img.src = imgUrl;
|
|
||||||
img.onload = () => resolve(imgUrl);
|
|
||||||
img.onerror = () => reject(new Error('Image not found'));
|
|
||||||
});
|
|
||||||
|
|
||||||
fileList.value = [
|
fileList.value = [
|
||||||
{
|
{
|
||||||
name: 'full.jpg',
|
name: 'full.jpg',
|
||||||
url: imgUrl,
|
url: imgUrl,
|
||||||
status: 'finished',
|
status: 'finished',
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fileList.value = [];
|
fileList.value = []
|
||||||
if (!error.message.includes('404')) {
|
if (!error.message?.includes('404')) {
|
||||||
console.error('Error getting image: ', error);
|
console.error('Error getting image: ', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
const showConfirmDelete = ref(false)
|
const showConfirmDelete = ref(false)
|
||||||
|
|
||||||
|
|
@ -215,8 +207,7 @@ const cancelDelete = () => {
|
||||||
|
|
||||||
.preview-container {
|
.preview-container {
|
||||||
display: block;
|
display: block;
|
||||||
width: 50%;
|
width: 100%;
|
||||||
min-width: 250px;
|
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue