Commit Graph

8009 Commits

Author SHA1 Message Date
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
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
nonamethanks
e83d07ea7b Pixiv: don't blacklist digital tools anymore 2020-06-12 04:15:20 +02:00
evazion
45b3370d49 models: fix exception in api_attributes.
Fixup bug in eacb4d4df when calling `api_attributes` on an object that
doesn't have a policy (its policy inherited from ApplicationPolicy).
2020-06-10 18:16:58 -05:00
evazion
8a2ae91ff2 tests: skip video file tests if ffmpeg isn't installed. 2020-06-10 18:07:54 -05:00
evazion
15799f8af7 Fix #4260: Unable to replace cdn.donmai.us images?
Bug: Replacing posts hosted on cdn.donmai.us didn't work.

Cause: Original files on cdn.donmai.us are hosted under /var/www/danbooru/original/, but replacements
were trying to store them directly under /var/www/danbooru, which failed with a permission error.
We were trying to store them in the wrong directory because we didn't respect the `original_subdir`
option when generating file paths.
2020-06-09 15:57:43 -05:00
evazion
8b5ffb4c43 uploads: allow admins to upload videos more than 2 minutes long.
At some point the ability for admins to bypass the video length
restriction got lost.

ref: https://danbooru.donmai.us/forum_topics/14647
2020-06-09 03:08:06 -05:00
evazion
d002701bc1 Merge pull request #4494 from nonamethanks/fix_deviantart_api_downloads
Deviantart: fix api downloads
2020-06-09 01:37:03 -05:00
evazion
1ea0141ae1 Merge pull request #4499 from BrokenEagle/fix-4408
Fix notes having absolute coordinates upon creation
2020-06-09 01:36:44 -05:00
evazion
38f385d1ca js, css: fix eslint and stylelint warnings. 2020-06-09 01:35:44 -05:00
evazion
eacb4d4df3 models: factor out api_attributes to policies.
Refactor models so that we define attribute API permissions in policy
files instead of directly in models.

This is cleaner because a) permissions are better handled by policies
and b) which attributes are visible to the API is an API-level concern
that models shouldn't have to care about.

This fixes an issue with not being able to precompile CSS/JS assets
unless the database was up and running. This was a problem when building
Docker images because we don't have a database at build time. We needed
the database because `api_attributes` was a class-level macro in some
places, which meant it ran at boot time, but this triggered a database
call because api_attributes used database introspection to get the list
of allowed API attributes.
2020-06-08 18:38:02 -05:00
evazion
b6ed63841d footer: fix exception if git hash isn't defined.
The git hash may be undefined when running in a Docker container.
2020-06-08 18:12:32 -05:00
BrokenEagle
6f7530533a Fix notes having absolute coordinates upon creation
Notes are not given percent coordinates when created, however moving
or resizing would update the coordinates to percentage. This is why
it was appearing as if the type of coordinates given were random.
2020-06-05 21:53:00 +00:00
evazion
82c09858f2 Remove unused data attributes from <body> tag.
Fixup for 647556761.
2020-06-03 11:51:21 -05:00
evazion
647556761b Fix antiproxying (again).
Fuck it, just hardcode it. They rewrite certain parts of our markup so
we can't rely on anything in the html.
2020-06-02 23:30:15 -05:00
evazion
bfa76abb56 layouts/default: move <script> tag from header to footer.
* Inline Javascript in the <head> is a minor bottleneck because it
  blocks page rendering.
* Fix antiproxying protection (proxy sites like to strip <script> tags
  from the header).
2020-06-02 22:09:44 -05:00
evazion
91640447c0 Fix antiproxying config options.
Don't embed config options directly in Javascript. Including them in the
Javascript forces us to recompile the Javascript whenever these options
change, which requires us to redeploy the entire site instead of just
restarting the app server.
2020-06-02 20:50:39 -05:00
evazion
276f23ba8d config: refactor remove_tag_after_replacement? config option. 2020-06-02 18:25:45 -05:00
evazion
47e6821a31 config: remove customize_new_user config option. 2020-06-02 18:25:45 -05:00
evazion
484eacfd3b config: remove is_unlimited_metatag? config option. 2020-06-02 18:25:42 -05:00
evazion
9997db44d8 config: remove banned_ip_for_download? option.
* Remove `banned_ip_for_download?` config option. This isn't something that usually needs
  to be configured.
* Replace the `ipaddress` gem with `ipaddress_2`. The `ipaddress` gem has several methods
  we need (`link_local?`, etc) that are only available in master because the gem hasn't had
  an official release in several years. `ipaddress_2` is a fork that is more actively
  maintained.
2020-06-02 15:32:19 -05:00