|
9 | 9 | Imports SCrawler.API.Base |
10 | 10 | Imports SCrawler.Plugin |
11 | 11 | Imports SCrawler.Plugin.Attributes |
| 12 | +Imports System.Reflection |
12 | 13 | Imports PersonalUtilities.Tools.Web.Clients |
13 | 14 | Imports PersonalUtilities.Tools.Web.Clients.Base |
14 | 15 | Imports PersonalUtilities.Tools.Web.Documents.JSON |
@@ -58,6 +59,48 @@ Namespace API.Reddit |
58 | 59 | Return {AuthUserName.Value, AuthPassword.Value, ApiClientID.Value, ApiClientSecret.Value}.All(Function(v$) Not v.IsEmptyString) |
59 | 60 | End Get |
60 | 61 | End Property |
| 62 | + <PropertiesDataChecker({NameOf(AuthUserName), NameOf(AuthPassword), NameOf(ApiClientID), NameOf(ApiClientSecret), |
| 63 | + NameOf(UseTokenForTimelines), NameOf(UseCookiesForTimelines)})> |
| 64 | + Private Function OAuthCredentialsChecker(ByVal p As IEnumerable(Of PropertyData)) As Boolean |
| 65 | + Const msgTitle$ = "OAuth credentials" |
| 66 | + If p.ListExists Then |
| 67 | + Dim useToken As Boolean = False, useCookies As Boolean = False |
| 68 | + Dim d$ = String.Empty |
| 69 | + Dim dCount As Byte = 0 |
| 70 | + Dim members As IEnumerable(Of MemberInfo) = GetObjectMembers(Me) |
| 71 | + Dim getPropText As Func(Of String, String) = Function(name) members.First(Function(m) m.Name = name).GetCustomAttribute(Of PropertyOption).ControlText |
| 72 | + Dim dataStr As Action(Of String, String) = Sub(dd, name) If dd.IsEmptyString Then d.StringAppendLine(getPropText(name)) : dCount += 1 |
| 73 | + For Each pp As PropertyData In p |
| 74 | + Select Case pp.Name |
| 75 | + Case NameOf(AuthUserName) : dataStr(pp.Value, NameOf(AuthUserName)) |
| 76 | + Case NameOf(AuthPassword) : dataStr(pp.Value, NameOf(AuthPassword)) |
| 77 | + Case NameOf(ApiClientID) : dataStr(pp.Value, NameOf(ApiClientID)) |
| 78 | + Case NameOf(ApiClientSecret) : dataStr(pp.Value, NameOf(ApiClientSecret)) |
| 79 | + Case NameOf(UseTokenForTimelines) : useToken = pp.Value |
| 80 | + Case NameOf(UseCookiesForTimelines) : useCookies = pp.Value |
| 81 | + Case Else : Throw New ArgumentException($"Property name '{pp.Name}' is not implemented", "Property Name") |
| 82 | + End Select |
| 83 | + Next |
| 84 | + If d.IsEmptyString Then |
| 85 | + If useToken And useCookies Then |
| 86 | + Return True |
| 87 | + Else |
| 88 | + If Not useToken Then d.StringAppendLine(getPropText(NameOf(UseTokenForTimelines))) |
| 89 | + If Not useCookies Then d.StringAppendLine(getPropText(NameOf(UseCookiesForTimelines))) |
| 90 | + MsgBoxE({$"You need to check the following options:{vbCr}{d}", msgTitle}, vbCritical) |
| 91 | + Return False |
| 92 | + End If |
| 93 | + ElseIf dCount = 4 Then |
| 94 | + Return MsgBoxE({$"You haven't configured OAuth. It's highly recommended to use OAuth.{vbCr}Do you still want to continue?", msgTitle}, |
| 95 | + vbExclamation,,, {"Process", "Cancel"}) = 0 |
| 96 | + Else |
| 97 | + MsgBoxE({$"You haven't filled in the following fields:{vbCr}{d}.{vbCr}{vbCr}" & |
| 98 | + "To use OAuth authorization, you must fill in all authorization fields.", msgTitle}, vbCritical) |
| 99 | + Return False |
| 100 | + End If |
| 101 | + End If |
| 102 | + Return True |
| 103 | + End Function |
61 | 104 | #End Region |
62 | 105 | #Region "Other" |
63 | 106 | <PropertyOption(ControlText:="Use M3U8", ControlToolTip:="Use M3U8 or mp4 for Reddit videos", IsAuth:=False), PXML, PClonable> |
@@ -233,23 +276,6 @@ Namespace API.Reddit |
233 | 276 | End Sub |
234 | 277 | #End Region |
235 | 278 | #Region "Token" |
236 | | - <PropertiesDataChecker({NameOf(AuthUserName), NameOf(AuthPassword), NameOf(ApiClientID), NameOf(ApiClientSecret)})> |
237 | | - Private Function TokenPropertiesChecker(ByVal p As IEnumerable(Of PropertyData)) As Boolean |
238 | | - If p.ListExists Then |
239 | | - Dim wrong As New List(Of String) |
240 | | - For i% = 0 To p.Count - 1 |
241 | | - If CStr(p(i).Value).IsEmptyString Then wrong.Add(p(i).Name) |
242 | | - Next |
243 | | - If wrong.Count > 0 And wrong.Count <> 4 Then |
244 | | - MsgBoxE({$"You have not completed the following fields: {wrong.ListToString}." & vbCr & |
245 | | - "To use OAuth authorization, all authorization fields must be filled in.", "Validate token fields"}, vbCritical) |
246 | | - Return False |
247 | | - Else |
248 | | - Return True |
249 | | - End If |
250 | | - End If |
251 | | - Return False |
252 | | - End Function |
253 | 279 | Private Function UpdateTokenIfRequired() As Boolean |
254 | 280 | UpdateRedGifsToken() |
255 | 281 | If (CBool(UseTokenForTimelines.Value) Or CBool(UseTokenForSavedPosts.Value)) AndAlso CredentialsExists Then |
|
0 commit comments