Commit Graph

15 Commits

Author SHA1 Message Date
evazion
26ad844bbe downloads: refactor Downloads::File into Danbooru::Http.
Remove the Downloads::File class. Move download methods to
Danbooru::Http instead. This means that:

* HTTParty has been replaced with http.rb for downloading files.

* Downloading is no longer tightly coupled to source strategies. Before
  Downloads::File tried to automatically look up the source and download
  the full size image instead if we gave it a sample url. Now we can
  do plain downloads without source strategies altering the url.

* The Cloudflare Polish check has been changed from checking for a
  Cloudflare IP to checking for the CF-Polished header. Looking up the
  list of Cloudflare IPs was slow and flaky during testing.

* The SSRF protection code has been factored out so it can be used for
  normal http requests, not just for downloads.

* The Webmock gem can be removed, since it was only used for stubbing
  out certain HTTParty requests in the download tests. The Webmock gem
  is buggy and caused certain tests to fail during CI.

* The retriable gem can be removed, since we no longer autoretry failed
  downloads. We assume that if a download fails once then retrying
  probably won't help.
2020-06-20 00:20:39 -05:00
evazion
459f67c431 iqdb: fix 599 timeout errors.
Increase timeout to 30 seconds when uploading files to IQDB. Previously
we used the default timeout of 3 seconds, which could cause 599 timeout
errors sometimes if the upload took too long.
2020-06-18 00:57:51 -05:00
evazion
b8b5c8d6a0 iqdb: fix error with file uploads.
Fix "cannot determine size of body" errors on upload page. Caused by
exception during IQDB lookup. We were posting the form data wrong, we
need to wrap the file with HTTP::FormData::File and pass it through the
`form` parameter.
2020-06-17 02:28:16 -05:00
evazion
cd501fe27b iqdb: switch to Danbooru::Http. 2020-06-14 01:06:51 -05:00
BrokenEagle
b9b1177832 Adds suport for using the image_url parameter with IQDB
This was only halfways supported, as the download module does not
have an image_url function. So for this, it just uses the url function,
which is just the original URL passed into the download function.

Additionally, it adds support to grab the largest available image,
which it does by using the file_url function of the downloads module.

- Fixes image_url parameter
- Adds file_url parameter
2020-05-24 00:58:46 +00:00
evazion
d946a84480 iqdb: download files inside danbooru, not inside iqdb.
Instead of sending IQDB the image url and letting it download the file,
download the file on Danbooru's end and send IQDB the downloaded file.

This fixes several issues:

* Some sites need the referer header set to avoid hotlink protection
  when downloading the file. Danbooru knows how to deal with this but
  IQDB doesn't.

* We need to enforce certain restrictions when downloading files,
  including setting max filesize limits, setting max timeouts, and not
  allowing downloads from forbidden IPs (to avoid SSRF attacks).
  Danbooru knows how to handle these things but IQDB doesn't.
2019-10-26 15:02:07 -05:00
evazion
ecfeaca7d4 iqdb: fix handling of error responses.
Handle JSON error responses returned by IQDB: `{ "error": <message> }`.
2019-10-26 13:01:08 -05:00
evazion
abee048de5 iqdb: use preview image url for iqdb lookups.
* Fix the IQDB lookup to handle error messages returned by IQDB.

* Fix `undefined method `>=' for nil:NilClass` error when trying to upload
  ugoiras. Using the preview image for IQDB lookups should be faster and
  give the same results as the full image, plus it should work with things
  like ugoiras and videos that IQDB can't handle.

  Also add an image_url param so that API users can continue using the
  full image if needed.
2019-10-22 13:07:21 -05:00
evazion
d2c6d6d17b iqdb: hide low similarity results behind "show" link. 2019-10-16 23:53:09 -05:00
evazion
958ba0f8b7 iqdb: delete leftover unused code.
* Delete unused Iqdb::Download module.
* Fix N+1 query in decorate_posts.
* /iqdb_queries: Raise max value of `limit` param to 1000.
2019-10-16 23:52:39 -05:00
evazion
ae521e600e iqdb: proxy iqdb searches through danbooru.
Previously the search form on the /iqdb_queries page submitted directly
to the iqdb service (karasuma.donmai.us), which redirected back to
Danbooru with the search results.

This was different than API requests, which submitted to
/iqdb_queries.json which proxied the call to iqdb through Danbooru.
Because of this, searches on the /iqdb_queries page had different
behavior than API requests. Things like filesize limits and referrer
spoofing were handled differently.

Now searches on the /iqdb_queries page submit directly to Danbooru. This
is simpler and it means that API requests and HTML requests have the
same behavior.
2019-10-14 21:16:04 -05:00
evazion
fa37b1edcd iqdb: lower similarity cutoff, return more results (fix #4190).
* Change cutoffs on upload page to max 5 results, min. 20% similarity.
* Change cutoffs on standalone /iqdb_queries page to max 20 results, min. 0% similarity.
* /iqdb_queries.json: add `limit` and `similarity` params to change default cutoffs.
2019-10-14 21:16:04 -05:00
r888888888
62235e215e iqdb fixes 2018-06-23 11:15:14 -07:00
r888888888
8f2f418613 fix iqdbproxy 2018-06-23 11:09:03 -07:00
r888888888
3ba5c6fb51 refactor iqdb endpoints 2018-06-23 10:59:04 -07:00