Skip to content

Commit

Permalink
Отключение работы с закрытыми группами
Browse files Browse the repository at this point in the history
  • Loading branch information
Spliterash committed Mar 16, 2024
1 parent 6f3ef14 commit 6c68f71
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
// `java-library`
kotlin("jvm") version "1.9.0"
kotlin("kapt") version "1.9.0"
kotlin("jvm") version "1.9.23"
kotlin("kapt") version "1.9.23"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.minimal.application") version "4.0.2"
id("io.micronaut.minimal.application") version "4.3.4"
}

group = "ru.spliterash"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
micronautVersion=4.0.3
micronautVersion=4.3.4
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.spliterash.vkVideoUnlocker.group

import io.micronaut.context.annotation.Value
import jakarta.inject.Singleton
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand All @@ -13,7 +14,9 @@ import ru.spliterash.vkVideoUnlocker.vk.api.VkApi

@Singleton
class WorkUserGroupService(
@WorkUser private val user: VkApi
@WorkUser private val user: VkApi,
@Value("\${vk-unlocker.private-groups:false}") private val privateGroupWork: Boolean

) {
private val groups = hashMapOf<Int, GroupInfo>()
private val lock = Mutex()
Expand Down Expand Up @@ -46,6 +49,7 @@ class WorkUserGroupService(
try {
when (actualInfo.groupStatus) {
GroupStatus.CLOSE -> {
if (!privateGroupWork) return GroupStatus.CLOSE
when (actualInfo.memberStatus) {
MemberStatus.NO -> {
user.groups.join(groupId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.spliterash.vkVideoUnlocker.video.exceptions

import ru.spliterash.vkVideoUnlocker.common.exceptions.VkUnlockerException

class PrivateVideoDisabledException : VkUnlockerException() {
override fun messageForUser() = "Видео из закрытых групп временно отключены"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.spliterash.vkVideoUnlocker.video.service

import io.micronaut.context.annotation.Value
import jakarta.inject.Singleton
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import ru.spliterash.vkVideoUnlocker.common.CoroutineHelper
import ru.spliterash.vkVideoUnlocker.video.entity.VideoEntity
import ru.spliterash.vkVideoUnlocker.video.exceptions.PrivateVideoDisabledException
import ru.spliterash.vkVideoUnlocker.video.exceptions.SelfVideoException
import ru.spliterash.vkVideoUnlocker.video.exceptions.VideoOpenException
import ru.spliterash.vkVideoUnlocker.video.holder.VideoContentHolder
Expand All @@ -23,6 +25,7 @@ class VideoReUploadService(
private val videoRepository: VideoRepository,
@WorkUser private val workUser: VkApi,
@GroupUser private val groupUser: VkApi,
@Value("\${vk-unlocker.private-groups:false}") private val privateGroupWork: Boolean
) {
private val inProgress = Collections.synchronizedMap(hashMapOf<String, Deferred<UnlockResult>>())
private val scope = CoroutineHelper.scope
Expand Down Expand Up @@ -71,8 +74,10 @@ class VideoReUploadService(
val fullVideo = holder.fullVideo()

val originalAttachmentId = holder.attachmentId
val videoAccessor = fullVideo.toAccessor()
val private = fullVideo.shouldBeLocked()
if (private && !privateGroupWork) throw PrivateVideoDisabledException()

val videoAccessor = fullVideo.toAccessor()

val reUploadedId = workUser.videos.upload(
groupUser.id,
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ vk-unlocker:
token: action_user_token
# Пользователь для "тыканья" видосов на наличие блокировки
poke-user:
token: poke_user_token
token: poke_user_token
private-groups: false

0 comments on commit 6c68f71

Please sign in to comment.