add user id
This commit is contained in:
parent
b231676736
commit
c36f21b819
|
@ -70,6 +70,13 @@ class TgBot:
|
|||
TgBotUpdater.return_values[item.text] = text.file_path
|
||||
except Exception as e:
|
||||
TgBotUpdater.return_values[item.text] = None
|
||||
if name == 'admin_get_name':
|
||||
item = queryset[0]
|
||||
try:
|
||||
text = await TgBot.app.bot.get_chat(item)
|
||||
TgBotUpdater.return_values[item] = text.effective_name
|
||||
except Exception as e:
|
||||
TgBotUpdater.return_values[item] = None
|
||||
|
||||
async def set_handlers(self):
|
||||
TgBot.app.add_handler(
|
||||
|
|
|
@ -37,6 +37,20 @@ class TmcFieldViewset(viewsets.ModelViewSet):
|
|||
serializer_class = TmcFieldSerializer
|
||||
http_method_names = ["get"]
|
||||
|
||||
@action(detail=False, methods=["get"], url_path=r"get_name/(?P<chat_id>[^/.]+)")
|
||||
def get_name(self, request, chat_id):
|
||||
TgBotUpdater.my_queue.put({"name": "admin_get_name", "queryset": [chat_id]})
|
||||
response = []
|
||||
timer = 30
|
||||
while timer > 0:
|
||||
sleeping = 1
|
||||
timer -= sleeping
|
||||
time.sleep(sleeping)
|
||||
if chat_id in TgBotUpdater.return_values:
|
||||
response.append(TgBotUpdater.return_values[chat_id])
|
||||
del TgBotUpdater.return_values[chat_id]
|
||||
break
|
||||
return Response(response)
|
||||
@action(detail=False, methods=["get"], url_path=r"get_image/(?P<field_id>[^/.]+)")
|
||||
def get_image(self, request, field_id):
|
||||
if TmcField.objects.filter(id=field_id).exists():
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<script setup lang="ts">
|
||||
import { useAuthorsStore } from '~/store/authors';
|
||||
|
||||
const props = defineProps(['user_id'])
|
||||
const authorStore = useAuthorsStore()
|
||||
|
||||
const author = ref(authorStore.getItem(props.user_id))
|
||||
const isOpen = ref(false)
|
||||
|
||||
watch(authorStore, () => {
|
||||
author.value = authorStore.getItem(props.user_id)
|
||||
}, { deep: true })
|
||||
</script>
|
||||
<template>
|
||||
<template v-if="author.status == 'success'">
|
||||
{{ author.result }}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ props.user_id }}
|
||||
</template>
|
||||
</template>
|
|
@ -53,6 +53,9 @@ const columns = [
|
|||
</ul>
|
||||
</template>
|
||||
</template>
|
||||
<template #user_id-data="{ row }">
|
||||
<GetAuthor :user_id="row.user_id" />
|
||||
</template>
|
||||
</UTable>
|
||||
<UPagination v-model="page" v-bind="pagination" />
|
||||
</div>
|
||||
|
|
|
@ -4,40 +4,39 @@ interface imagesList {
|
|||
result?: string
|
||||
}
|
||||
}
|
||||
export const useImagesStore = defineStore('images', {
|
||||
export const useAuthorsStore = defineStore('authors', {
|
||||
state: () => ({ list: {} as imagesList }),
|
||||
actions: {
|
||||
getImage(name: string) {
|
||||
getItem(name: string) {
|
||||
if (!this.list[name]) {
|
||||
this.list[name] = {
|
||||
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='
|
||||
}
|
||||
}
|
||||
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()
|
||||
this.loadItems()
|
||||
}
|
||||
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] !== null) {
|
||||
async loadOneItem(name: string) {
|
||||
const result_data = await apiCall<string[]>(`tgbot/items/get_name/${name}/`)
|
||||
if (result_data.length > 0 && result_data[0] !== null) {
|
||||
this.list[name].status = 'success'
|
||||
this.list[name].result = file_url_data[0]
|
||||
this.list[name].result = result_data[0]
|
||||
} else {
|
||||
this.list[name].status = 'error'
|
||||
}
|
||||
if (Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
|
||||
this.loadImages()
|
||||
this.loadItems()
|
||||
}
|
||||
},
|
||||
loadImages() {
|
||||
loadItems() {
|
||||
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])
|
||||
this.loadOneItem(el[0])
|
||||
})
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue