Skip to content

Commit

Permalink
Access fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Spliterash committed Dec 7, 2024
1 parent 291749f commit 08a2a90
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ interface Videos {
name: String,
private: Boolean,
accessor: VideoAccessor,
progressMeter: ProgressMeter = ProgressMeter { _, _ -> }
progressMeter: ProgressMeter = ProgressMeter { _, _ -> },
): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,56 @@ class VideosImpl(
return video
}

private suspend fun fixAccess(id: String, private: Boolean) {
val split = id.split("_")

VkConst.requestBuilder()
.get()
.addHeader(
"user-agent",
USER_AGENT
)
.url(
VkConst.urlBuilder("video.add")
.addQueryParameter("target_id", split[0])
.addQueryParameter("owner_id", split[0])
.addQueryParameter("video_id", split[1])
.build()
)
.build()
.executeAsync(client)
.readResponse(helper, object : TypeReference<Unit>() {})
VkConst.requestBuilder()
.get()
.addHeader(
"user-agent",
USER_AGENT
)
.url(
VkConst.urlBuilder("video.edit")
.addQueryParameter("owner_id", split[0])
.addQueryParameter("video_id", split[1])
.addQueryParameter("privacy_view", if (private) "3" else "0")
.build()
)
.build()
.executeAsync(client)
.readResponse(helper, object : TypeReference<Unit>() {})
}

override suspend fun upload(
groupId: Long,
name: String,
private: Boolean,
accessor: VideoAccessor,
progressMeter: ProgressMeter
progressMeter: ProgressMeter,
): String {
val url = VkConst.requestBuilder()
.get()
.url(
VkConst.urlBuilder("video.save")
.addQueryParameter("name", name)
.addQueryParameter("privacy_view", if (private) "3" else "0")
.addQueryParameter("privacy_view", "0")
.addQueryParameter("group_id", groupId.toString())
.addQueryParameter("target", "post")
.build()
Expand All @@ -69,7 +106,10 @@ class VideosImpl(
.uploadUrl
val id = commons.upload(url, accessor, progressMeter)

return "-${groupId}_${id}"
val videoId = "-${groupId}_${id}"
fixAccess(videoId, private)

return videoId
}

companion object {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/spliterash/vkVideoUnlocker/vk/VkHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VkHelper(

fun <T> readResponse(response: Response, type: TypeReference<T>): T {
val node = checkAndGetResponse(response)

if (type.type == Unit::class.java) return Unit as T
return try {
mapper.convertValue(node, type)
} catch (ex: IllegalArgumentException) {
Expand Down

0 comments on commit 08a2a90

Please sign in to comment.