Skip to content

Commit

Permalink
Асинхронная обработка видоса
Browse files Browse the repository at this point in the history
  • Loading branch information
Spliterash committed Oct 16, 2024
1 parent fd55cfe commit 9e48c84
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package ru.spliterash.vkVideoUnlocker.video.service

import com.github.benmanes.caffeine.cache.Caffeine
import jakarta.inject.Singleton
import kotlinx.coroutines.launch
import ru.spliterash.vkVideoUnlocker.common.CoroutineHelper.scope
import ru.spliterash.vkVideoUnlocker.common.InputStreamSource
import ru.spliterash.vkVideoUnlocker.longpoll.message.RootMessage
import ru.spliterash.vkVideoUnlocker.message.editableMessage.EditableMessage
import ru.spliterash.vkVideoUnlocker.video.api.VideosCommons
import ru.spliterash.vkVideoUnlocker.video.exceptions.VideoSaveExpireException
import ru.spliterash.vkVideoUnlocker.video.service.dto.VideoSaveEntry
import ru.spliterash.vkVideoUnlocker.vk.actor.GroupUser
import ru.spliterash.vkVideoUnlocker.vk.api.VkApi
import java.util.*
import java.util.concurrent.TimeUnit

@Singleton
class VideoSaveService(
private val commons: VideosCommons,
@GroupUser private val group: VkApi
) {
private val pending = Caffeine
.newBuilder()
Expand Down Expand Up @@ -44,11 +43,13 @@ class VideoSaveService(

suspend fun processUrl(id: UUID, uploadUrl: String) {
val entry = pending.remove(id) ?: throw VideoSaveExpireException()
try {
val savedId = commons.upload(uploadUrl, entry.accessor)
entry.message.sendOrUpdate("Успешно", "video${entry.userId}_$savedId")
} catch (ex: Exception) {
entry.message.sendOrUpdate("Ошибка при загрузке(${ex.javaClass.simpleName}): ${ex.localizedMessage}")
scope.launch {
try {
val savedId = commons.upload(uploadUrl, entry.accessor)
entry.message.sendOrUpdate("Успешно", "video${entry.userId}_$savedId")
} catch (ex: Exception) {
entry.message.sendOrUpdate("Ошибка при загрузке(${ex.javaClass.simpleName}): ${ex.localizedMessage}")
}
}
}
}

0 comments on commit 9e48c84

Please sign in to comment.