1919using SmartImage . Lib . Searching ;
2020using SmartImage . Lib . Utilities ;
2121
22+ // ReSharper disable StringLiteralTypo
23+
2224namespace SmartImage . Lib . Engines . Impl
2325{
2426 public sealed class IqdbEngine : ClientSearchEngine
@@ -113,60 +115,32 @@ private static ImageResult ParseResult(IHtmlCollection<IElement> tr)
113115
114116 private IDocument GetDocument ( ImageQuery query )
115117 {
116- //return base.GetDocument(sr);
117-
118- /*MultipartFormDataContent form = new MultipartFormDataContent();
119-
120- form.Add(new StringContent("8388608"), "MAX_FILE_SIZE");
121-
122- for (int i = 1; i <= 13; i++)
123- {
124- if (new[] { 7, 8, 9, 12 }.Contains(i))
125- {
126- continue;
127- }
128-
129- form.Add(new StringContent(i.ToString()), "service[]");
130- }
131-
132- form.Add(new StreamContent(query.Stream), "file", "image.jpg");
133- form.Add(new StringContent(string.Empty), "url");
134-
118+ var rq = new RestRequest ( Method . POST ) ;
135119
136- var h = new HttpClient();
137- h.BaseAddress = new Uri(EndpointUrl);
138- var r=h.PostAsync("/", form);
139- r.Wait();*/
120+ const int MAX_FILE_SIZE = 8388608 ;
140121
141- var rq = new RestRequest ( Method . POST ) ;
142- rq . AddParameter ( "MAX_FILE_SIZE" , 8388608 , ParameterType . GetOrPost ) ;
122+ rq . AddParameter ( "MAX_FILE_SIZE" , MAX_FILE_SIZE , ParameterType . GetOrPost ) ;
143123 rq . AddHeader ( "Content-Type" , "multipart/form-data" ) ;
144124
145- byte [ ] rg = Array . Empty < byte > ( ) ;
146- object u = query . Value ;
125+ byte [ ] fileBytes = Array . Empty < byte > ( ) ;
126+ object uri = string . Empty ;
147127
148128 if ( query . IsFile ) {
149- rg = File . ReadAllBytes ( query . Value ) ;
150-
151-
129+ fileBytes = File . ReadAllBytes ( query . Value ) ;
130+ }
131+ else if ( query . IsUri ) {
132+ uri = query . Value ;
152133 }
153- else if ( query . IsUri ) { }
154134 else {
155135 throw new SmartImageException ( ) ;
156136 }
157137
158- rq . AddFile ( "file" , rg , "image.jpg" ) ;
159- rq . AddParameter ( "url" , u , ParameterType . GetOrPost ) ;
138+ rq . AddFile ( "file" , fileBytes , "image.jpg" ) ;
139+ rq . AddParameter ( "url" , uri , ParameterType . GetOrPost ) ;
160140
161141 //rq.AddParameter("service[]", new[] {1, 2, 3, 4, 5, 6, 11, 13}, ParameterType.GetOrPost);
162142
163143 var response = Client . Execute ( rq ) ;
164- Network . DumpResponse ( response ) ;
165- Debug . Assert ( response . IsSuccessful ) ;
166-
167- // var html2 = r.Result.Content.ReadAsStringAsync();
168- // html2.Wait();
169- // var html = html2.Result;
170144
171145 var parser = new HtmlParser ( ) ;
172146 return parser . ParseDocument ( response . Content ) ;
@@ -179,7 +153,6 @@ public override SearchResult GetResult(ImageQuery query)
179153 //var sr = base.GetResult(query);
180154 var sr = new SearchResult ( this ) ;
181155
182-
183156 try {
184157
185158 sr = Process ( query , sr ) ;
@@ -194,16 +167,10 @@ public override SearchResult GetResult(ImageQuery query)
194167
195168 protected override SearchResult Process ( ImageQuery query , SearchResult sr )
196169 {
197-
198- // var re = new RestRequest(Method.POST);
199- // re.AddFile("file", File.ReadAllBytes(q.Value), "image.jpg");
200-
201170 // Don't select other results
202171
203-
204172 var doc = GetDocument ( query ) ;
205173
206-
207174 var pages = doc . Body . SelectSingleNode ( "//div[@id='pages']" ) ;
208175 var tables = ( ( IHtmlElement ) pages ) . SelectNodes ( "div/table" ) ;
209176
0 commit comments