OAuth: subscribe/unsubscribe (#603)
* OAuth: subscribe/unsubscribe * Lint fix * Cancel fetch status when subscribe button is clicked * tweak * error handling --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
e821464451
commit
918b763384
10 files changed
+366
-91
No files matched your search
+100
@@ -583,6 +583,8 @@ namespace Http
|
||||
|
||||
if route.StartsWith("/playlet-invidious-backend/api/v1/auth/history/")
|
||||
return m.AuthMarkVideoWatched(context)
|
||||
else if route.StartsWith("/playlet-invidious-backend/api/v1/auth/subscriptions/")
|
||||
return m.SubscribeToChannel(context)
|
||||
end if
|
||||
|
||||
return false
|
||||
@@ -797,6 +799,104 @@ namespace Http
|
||||
return false
|
||||
end function
|
||||
|
||||
function SubscribeToChannel(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
route = request.route
|
||||
|
||||
accessToken = request.headers["authorization"]
|
||||
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||
response.Json({
|
||||
"error": "Missing or invalid 'Authorization' header"
|
||||
})
|
||||
response.http_code = 403
|
||||
return true
|
||||
end if
|
||||
|
||||
channelId = route.Mid("/playlet-invidious-backend/api/v1/auth/subscriptions/".Len())
|
||||
if channelId.InStr("?") > 0
|
||||
channelId = channelId.Left(channelId.InStr("?"))
|
||||
end if
|
||||
|
||||
if StringUtils.IsNullOrEmpty(channelId)
|
||||
response.Json({
|
||||
"error": "Missing 'channelId' path parameter"
|
||||
})
|
||||
response.http_code = 400
|
||||
return true
|
||||
end if
|
||||
|
||||
options = {
|
||||
"accessToken": accessToken.Mid("Bearer ".Len())
|
||||
}
|
||||
|
||||
result = InnertubeService.SubscribeToChannel(channelId, options)
|
||||
|
||||
if result.success <> true
|
||||
response.Json(result)
|
||||
response.http_code = 500
|
||||
return true
|
||||
end if
|
||||
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function
|
||||
|
||||
@delete("*")
|
||||
function DeleteAll(context as object) as boolean
|
||||
request = context.request
|
||||
route = request.route
|
||||
|
||||
if route.StartsWith("/playlet-invidious-backend/api/v1/auth/subscriptions/")
|
||||
return m.UnsubscribeFromChannel(context)
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
function UnsubscribeFromChannel(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
route = request.route
|
||||
|
||||
accessToken = request.headers["authorization"]
|
||||
if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ")
|
||||
response.Json({
|
||||
"error": "Missing or invalid 'Authorization' header"
|
||||
})
|
||||
response.http_code = 403
|
||||
return true
|
||||
end if
|
||||
|
||||
channelId = route.Mid("/playlet-invidious-backend/api/v1/auth/subscriptions/".Len())
|
||||
if channelId.InStr("?") > 0
|
||||
channelId = channelId.Left(channelId.InStr("?"))
|
||||
end if
|
||||
|
||||
if StringUtils.IsNullOrEmpty(channelId)
|
||||
response.Json({
|
||||
"error": "Missing 'channelId' path parameter"
|
||||
})
|
||||
response.http_code = 400
|
||||
return true
|
||||
end if
|
||||
|
||||
options = {
|
||||
"accessToken": accessToken.Mid("Bearer ".Len())
|
||||
}
|
||||
|
||||
result = InnertubeService.UnsubscribeFromChannel(channelId, options)
|
||||
|
||||
if result.success <> true
|
||||
response.Json(result)
|
||||
response.http_code = 500
|
||||
return true
|
||||
end if
|
||||
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function
|
||||
|
||||
@get("/playlet-invidious-backend/watch")
|
||||
function RedirectWatch(context as object) as boolean
|
||||
request = context.request
|
||||
|
||||
Reference in new issue
Block a user