Commit Graph

2122 Commits

Author SHA1 Message Date
evazion
dd857c6695 popular searches: fix blank search counts on /explore/posts/searches. 2020-06-27 02:09:09 -05:00
evazion
ff096b8adc Fix #4508: Specific tag not showing a wiki.
Fix the wiki excerpt not appearing when searching for a tag that doesn't
exist in the tag list. This could happen if someone created a wiki for a
tag that has never been used on a post.
2020-06-27 02:01:34 -05:00
evazion
883856d4af simple form: refactor DText form fields to use SimpleForm.
* Refactors DText form fields to use a custom SimpleForm input instead
  of manually generated html. This fixes it so that DText fields use the
  same markup as normal SimpleForm fields, which lets us apply browser
  maxlength validations to DText input fields.

* Fixes autocomplete for @-mentions only working in comments and forum posts.
  Now @-mention autocomplete works in all DText fields, including dmails.
  Known bug: it applies in artist commentary fields when it shouldn't.
2020-06-25 16:28:09 -05:00
evazion
44f826d8fa nicoseiga: optimize image_url method.
The image_url method makes a request to `https://seiga.nicovideo.jp/images/source/:image_id`
to see where this URL redirects to. Before we did a GET request, which caused it to download
the full image. This could fail with a timeout error if the download took too long. We also
cached the request, which caused the full image to be cached, even though we only need the
headers. Change it to a HEAD request so we don't have to download the entire image just to
check the URL.
2020-06-24 22:54:04 -05:00
evazion
5af50b7fcd danbooru::http: factor out Cloudflare Polish bypassing.
* Factor out the Cloudflare Polish bypass code to a standalone feature.

* Add `http_downloader` method to the base source strategy. This is a
  HTTP client that should be used for downloading images or making
  requests to images. This client ensures that referrer spoofing and
  Cloudflare bypassing are performed.

This fixes a bug with the upload page reporting the polished filesize
instead of the original filesize when uploading ArtStation images.
2020-06-24 22:54:04 -05:00
evazion
d3bb5c67ee danbooru::http: factor out referrer spoofing.
Factor out referrer spoofing so that it can be used outside of downloading
files. We also need to spoof the referrer when determining the remote
filesize of images on the uploads page.
2020-06-24 21:46:59 -05:00
evazion
f84ceb3938 image proxy: raise image download timeout.
Possible fix for large Pixiv previews on the upload page sometimes
returning HTTP 500 errors.
2020-06-24 19:31:47 -05:00
evazion
4074cc99f9 uploads: fix incorrect remote sizes on pixiv uploads.
Bug: the uploads page showed a remote size of 146 bytes for Pixiv uploads.

Cause: we didn't spoof the Referer header when making the HEAD request
for the image, causing Pixiv to return a 403 error.

Also fix the case where the Content-Length header is absent.
2020-06-24 03:02:45 -05:00
evazion
85f58bf2f6 newgrounds: fix style nitpicks. 2020-06-24 00:25:45 -05:00
evazion
42c06b0f1e Merge pull request #4516 from nonamethanks/add_newgrounds_support
Add NewGrounds support
2020-06-24 00:20:16 -05:00
evazion
185693b99b Merge branch 'master' into fix-pixiv-profile-url 2020-06-24 00:06:55 -05:00
evazion
8ef2b7772d Merge pull request #4530 from BrokenEagle/parent-child-status-search
Add ability to search on status of parent/child
2020-06-23 23:53:57 -05:00
evazion
bb765f55d5 Eliminate misc dead code. 2020-06-23 23:37:56 -05:00
evazion
8a21c9a8db Merge pull request #4523 from nonamethanks/revert_pixiv_tools
Revert "Pixiv: don't blacklist digital tools"
2020-06-23 02:39:18 -05:00
evazion
617211f405 Merge pull request #4521 from nonamethanks/zerochan_png
Zerochan: Normalize png links
2020-06-23 02:38:39 -05:00
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
BrokenEagle
4acd89838b Add ability to search on status of parent/child 2020-06-21 22:39:21 +00:00
evazion
a4efeb2260 gems: drop Mechanize, HTTParty, and Sinatra gems. 2020-06-21 15:13:42 -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
nonamethanks
0a396c8b95 Revert "Pixiv: don't blacklist digital tools"
This reverts commit e83d07ea7b.

It was worth a try, but unfortunately it seems that once
someone sets tools in a Pixiv upload, they become defaults and
are applied to all of their subsequent uploads, so we get some
posts with two or three different digital tags.
2020-06-19 08:08:46 +02:00
nonamethanks
8a06d3a744 Zerochan: Normalize png links 2020-06-18 08:07:45 +02: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
nonamethanks
7a41ee9c34 Add NewGrounds support 2020-06-18 03:22:30 +02: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
BrokenEagle
158a4aa916 Fix Pixiv user profile URL to use the latest format
This will only affect new artist and commentary records going forward.
2020-06-17 07:07:33 +00: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