Commit Graph

8028 Commits

Author SHA1 Message Date
evazion
f2ae9eeae0 Merge pull request #4528 from nonamethanks/fix_4520
Twitter: don't get api without a status id
2020-06-23 02:36:32 -05:00
evazion
5dbe08372b nicoseiga: remove accept_fetish_warning.
This should have been a cookie, but it doesn't matter because the
strategy still works without it.
2020-06-23 00:49:38 -05:00
evazion
7f5e87568a danbooru::http: raise exception on failed downloads.
Restore behavior from a6994cd4d, it breaks tests when they try to the
response body from a fake 599 response.
2020-06-22 22:51:36 -05:00
evazion
31802fb666 nijie: fix parallel test failures.
Nijie tests fail often under parallel testing. This is because every
test needs to login to Nijie first, but Nijie rate-limits the login
endpoint, so eventually we hit the limit and tests start failing.

This is made worse by a thundering herd problem. Eight test processes
try to login to Nijie at the same time, but only one succeeds, so the
rest sleep and try again, but they all wakeup and try again at the same
time, hitting the rate limits again.

The workaround is to set the retry limit ridiculously high, higher than
we would ideally like in production. Another workaround would be to
serialize the Nijie tests in the test suite. This can be done with
lockfiles and flock(2). This helps, but we can still hit the rate limit
even under serialized execution.
2020-06-22 22:21:17 -05:00
evazion
a6994cd4d7 media file: fix exception on empty files.
This may happen if a user uploads from a source that returns an error
HTTP response with no data.
2020-06-22 18:49:36 -05:00
evazion
8c6759bbd7 nicoseiga: fix login endpoint.
* Update the login endpoint. The old endpoint returns 404 now.

  POST https://account.nicovideo.jp/api/v1/login ->
  POST https://account.nicovideo.jp/login/redirector?site=seiga

* Let Danbooru::Http cache the login request instead of caching it manually.

* Let Danbooru::Http automatically follow redirects instead of dealing
  with the Location header manually.
2020-06-22 18:46:47 -05:00
evazion
95fee75d9a nicoseiga: fix uploads not working for certain direct image urls.
Fix Nicoseiga strategy to work with certain direct image urls that we
can't otherwise extract any information from.

Examples:

* https://dic.nicovideo.jp/oekaki/52833.png
2020-06-22 16:53:50 -05:00
evazion
db3407caa3 uploads: fix uploading from source not working.
ref: 26ad844bbe (r40077579).
2020-06-22 15:32:48 -05:00
evazion
bd25be95f5 danbooru::http: factor out cache feature.
Fixes a bug with cookies stored by the `session` feature not being sent
with cached requests.
2020-06-21 18:28:37 -05:00
evazion
f85eef9bcd nijie: fix bug with retries returning cached responses.
Bug: if a Nijie login failed with a 429 Too Many Requests error, the
error would get cached, so when we retried the request, we would just
get our own cached response back every time. The 429 error would
eventually be passed up to the Nijie strategy, which caused random
methods to fail because they couldn't get the html page.

Fix: add the `retriable` feature *after* the `cache` feature so that
retries don't go through the cache. This is a hack. We want retries to
go at the bottom of the stack, below caching, but we can't enforce this
ordering.
2020-06-21 18:13:21 -05:00
evazion
a4efeb2260 gems: drop Mechanize, HTTParty, and Sinatra gems. 2020-06-21 15:13:42 -05:00
evazion
5c7843bd3d scripts: refactor mocked services.
Replace the mocked services in scripts/mocked_services with Rails-level
mocked services.

The scripts in scripts/mocked_services were a set of stub Sinatra
servers used to mock the Reportbooru, Recommender, and IQDBs services
during development. They return fake data so you can test pages that use
these services.

Implementing these services in Rails makes it easier to run them. It
also lets us drop a dependency on Sinatra and drop a use of HTTParty.

To use these services, set the following configuration in danbooru_local_config.rb
or .env.local:

* reportbooru_server: http://localhost:3000/mock/reportbooru
* recommender_server: http://localhost:3000/mock/recommender
* iqdbs_server: http://localhost:3000/mock/iqdb

where `http://localhost:300` is the url for your local Danbooru server
(may need to be changed depending on your configuration).
2020-06-21 15:11:56 -05:00
evazion
29a5f7dfc8 image proxy: replace HTTParty with Danbooru::Http. 2020-06-21 15:11:56 -05:00
evazion
7e471fe223 sources: replace HTTParty with Danbooru::Http in http_exists?. 2020-06-21 15:11:56 -05:00
evazion
3ad8c708c5 pixiv: replace HTTParty with Danbooru::Http. 2020-06-21 15:11:56 -05:00
evazion
5604ab0079 pixiv: remove fanbox support.
This is broken and it needs to be rewritten as a separate source
strategy anyway.
2020-06-21 11:59:51 -05:00
evazion
2da8174ce2 hentai foundry: replace HTTParty with Danbooru::Http. 2020-06-21 05:22:57 -05:00
evazion
6e6ce6e62f nijie: replace Mechanize with Danbooru::Http.
The Nijie login process works like this:

* First we submit our `email` and `password` to `https://nijie.info/login_int.php`.
* Then we save the NIJIEIEID session cookie from the response.
* We optionally retry if login failed. Nijie returns 429 errors with a
  `Retry-After: 5` header if we send too many login requests. This can
  happen during parallel testing.
* We cache the login cookies for only 1 hour so we don't have to worry
  about them becoming invalid if we cache them too long.

Cookies and retrying errors on failure are handled transparently by Danbooru::Http.
2020-06-21 05:22:57 -05:00
evazion
05d7355ebb danbooru::http: support automatically following redirects.
Replace http.rb's builtin redirect following option with our own
redirect follower. This fixes an issue with http.rb losing cookies after
following a redirect.
2020-06-21 05:22:57 -05:00
evazion
71b0bc6c0f danbooru::http: support tracking cookies between requests.
Allow cookies to be saved and sent back when making several requests in
a row. Usage:

    http = Danbooru::Http.use(:session)

    # saves the foo=42 cookie sent by the response.
    http.get("https://httpbin.org/cookies/set/foo/42")

    # sends back the foo=42 cookie from the previous request.
    http.get("https://httpbin.org/cookies")
2020-06-21 05:22:56 -05:00
evazion
87ed882234 danbooru::http: support automatically retrying 429 errors. 2020-06-21 05:22:30 -05:00
evazion
a929f3134e danbooru::http: parse html responses. 2020-06-21 05:22:27 -05:00
nonamethanks
79a59e52ec Twitter: don't get api without a status id 2020-06-20 15:08:49 +02:00
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
7a1efc2744 Fix #4522: Sidebar doesn't show most searched tags at certain times of day.
Revert back to previous workaround of fetching previous day if current
day returns no result. A terrible hack, really we should convert dates
to Reportbooru's timezone, but that has other complications.
2020-06-19 14:00:50 -05:00
evazion
67a52dbc2d tumblr: support new va.media.tumblr.com urls. 2020-06-19 13:53:35 -05:00
evazion
05f78f9bef saved searches: fix call to redis.exists?
https://github.com/redis/redis-rb/blob/master/CHANGELOG.md#421
2020-06-19 13:53:35 -05:00
evazion
491a53ffe3 Update mock_redis. 2020-06-19 02:25:28 -05:00
evazion
213766fac9 posts: fix "view original" not working on mobile.
ref: 38f385d1ca (r40000777)
2020-06-18 12:25:45 -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
f790a1aeed http: increase default timeout to 10 seconds.
Three seconds was little tight and might have caused timeouts in source
strategies sometimes.
2020-06-18 00:56:42 -05:00
evazion
d5a7eef53d uploads: fix remote file size not appearing. 2020-06-17 04:13:16 -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
91beb288b6 reportbooru: cache post views endpoint.
Cache most viewed posts endpoint for /explore/posts/viewed page.
2020-06-17 00:57:55 -05:00
evazion
b551e3634f Fix misc rubocop warnings. 2020-06-16 21:36:15 -05:00
evazion
a572a6614d popular/missed searches: fix blank views.
Fix missing call to `.each`.
2020-06-16 13:09:05 -05:00
evazion
101e8a13b8 /posts: fix blank tag sidebars.
Fix the sidebar on the /posts index page sometimes being blank. This
could happen when either the related tag calculation was too slow and
timed out, or when Reporbooru was unavailable and we couldn't fetch the
list of popular tags.

In the tag list would otherwise be blank, we fall back to frequent tags
(the most common tags on the current page of results).

Also change it so that if Reportbooru is unconfigured, we fail
gracefully by returning blank results instead of failing with an
exception. This is so we can still view the popular searches and missed
searches pages during testing (even though they'll be blank).
2020-06-16 12:58:41 -05:00
evazion
ed152a780b Upgrade ruby gems and yarn packages. 2020-06-16 00:38:09 -05:00
evazion
1aa0f65187 sources: fix rubocop warnings. 2020-06-16 00:10:37 -05:00
evazion
7868e5045e nicoseiga: fix regression with http redirects.
3cdf67920 changed it so that Danbooru::Http follows redirects by
default. This broke some things in the Nico Seiga strategy, so disable
following redirects in the Nico Seiga API client for now.

Also change it so that Danbooru::Http follows redirects after a POST
request (by setting `strict: false`). Nico Seiga needs this because it
sends a redirect after we POST the login form.
2020-06-15 22:13:28 -05:00
evazion
962e60f4f1 Merge pull request #4496 from nonamethanks/refactor_nicoseiga
Refactor nicoseiga
2020-06-15 21:05:10 -05:00
evazion
19727ab5c4 Merge pull request #4505 from nonamethanks/pixiv_digital_tags
Pixiv: don't blacklist digital tools anymore
2020-06-15 20:56:56 -05:00
nonamethanks
5b186f3072 Support for new nicoseiga cdn domain 2020-06-15 04:01:34 +02:00
nonamethanks
6fc4d3ec44 Nicoseiga: Add support for drm-served manga 2020-06-15 03:37:51 +02:00
nonamethanks
260bc997f6 NicoSeiga: Add preview urls 2020-06-15 03:37:51 +02:00
nonamethanks
9f0e85e1b5 Refactor nicoseiga strategy
* Get rid of mechanize, fully switch to Danbooru::Http
* Switch to mobile api, improving speed
* Merge main and manga clients
* Add full support for manga pages
* Add support for anonymous and r-15 images
* Don't fail when attempting to upload oekaki direct links
* Various misc fixes
2020-06-15 03:37:51 +02:00
evazion
3cdf679202 http: automatically follow redirects.
* Automatically follow redirects (up to 5, return a synthetic 598 error after that).
* Add `put` and `timeout` methods.
* Add tests.
2020-06-14 01:39:55 -05:00
evazion
cd501fe27b iqdb: switch to Danbooru::Http. 2020-06-14 01:06:51 -05:00
evazion
a4df18e650 Refactor Reportbooru API clients.
* Combine MissedSearchService, PostViewCountService, and
  PopularSearchService into single ReportbooruService class.
* Use Danbooru::Http for these services instead of HTTParty.
2020-06-14 00:32:42 -05:00
evazion
1846133cd6 post view count service: switch to Danbooru::Http. 2020-06-13 21:50:06 -05:00