load images
This commit is contained in:
parent
a38f5ad12c
commit
8e35d2ecb5
|
@ -69,7 +69,7 @@ class TgBot:
|
||||||
text = await TgBot.app.bot.get_file(item.text)
|
text = await TgBot.app.bot.get_file(item.text)
|
||||||
TgBotUpdater.return_values[item.text] = text.file_path
|
TgBotUpdater.return_values[item.text] = text.file_path
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
TgBotUpdater.return_values[item.text] = 'error'
|
||||||
|
|
||||||
async def set_handlers(self):
|
async def set_handlers(self):
|
||||||
TgBot.app.add_handler(
|
TgBot.app.add_handler(
|
||||||
|
|
|
@ -16,7 +16,7 @@ watch(imagesStore, () => {
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<template v-if="img.result">
|
<template v-if="img.status == 'success'">
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<Icon name="i-mdi-image" @click="openImage" />
|
<Icon name="i-mdi-image" @click="openImage" />
|
||||||
</a>
|
</a>
|
||||||
|
@ -24,4 +24,13 @@ watch(imagesStore, () => {
|
||||||
<img :src="img.result" />
|
<img :src="img.result" />
|
||||||
</UModal>
|
</UModal>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="img.status == 'error'">
|
||||||
|
<Icon name="i-mdi-close-circle-outline" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="img.status == 'pending'">
|
||||||
|
<Icon name="i-mdi-reload" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="img.status == 'idle'">
|
||||||
|
<Icon name="i-mdi-progress-question" />
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
|
@ -11,10 +11,35 @@ export const useImagesStore = defineStore('images', {
|
||||||
if (!this.list[name]) {
|
if (!this.list[name]) {
|
||||||
this.list[name] = {
|
this.list[name] = {
|
||||||
status: 'idle',
|
status: 'idle',
|
||||||
result: 'https://media.istockphoto.com/id/1490517357/photo/scientists-are-researching-and-analyzing-harmful-contaminants-in-the-laboratory.webp?s=170667a&w=0&k=20&c=Fh4t-P_b-a1QxwyBUzUa0AuLp8FLNyLy4hl4HUm82Ao='
|
// result: 'https://media.istockphoto.com/id/1490517357/photo/scientists-are-researching-and-analyzing-harmful-contaminants-in-the-laboratory.webp?s=170667a&w=0&k=20&c=Fh4t-P_b-a1QxwyBUzUa0AuLp8FLNyLy4hl4HUm82Ao='
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!Object.entries(this.list).filter(el => el[1].status == 'pending').length &&
|
||||||
|
Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
|
||||||
|
this.loadImages()
|
||||||
|
}
|
||||||
return this.list[name]
|
return this.list[name]
|
||||||
},
|
},
|
||||||
|
async loadOneImage(name: string) {
|
||||||
|
const file_url_data = await apiCall<string[]>(`tgbot/items/get_image/${name}/`)
|
||||||
|
|
||||||
|
if (file_url_data.length > 0 && file_url_data[0] !== 'error') {
|
||||||
|
this.list[name].status = 'success'
|
||||||
|
this.list[name].result = file_url_data[0]
|
||||||
|
} else {
|
||||||
|
this.list[name].status = 'error'
|
||||||
|
}
|
||||||
|
if (Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
|
||||||
|
this.loadImages()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadImages() {
|
||||||
|
const elements = Object.entries(this.list).filter(el => el[1].status == 'idle')
|
||||||
|
elements.slice(0, 2).map(el => {
|
||||||
|
this.list[el[0]].status = 'pending'
|
||||||
|
this.loadOneImage(el[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
Loading…
Reference in New Issue