Commit Graph

8889 Commits

Author SHA1 Message Date
evazion
ad523b3745 Fix #4895: Deleted forum topics visible by default in index.
The bug was that since search parameters normally come from URL request
parameters, a string value is expected here.
2021-10-01 17:14:48 -05:00
evazion
6c7fbb96b3 news updates: use relative time instead of date.
Use relative time on site updates to show when a site update was posted
("5m ago"), instead of the date ("Oct 1").
2021-10-01 05:15:40 -05:00
evazion
1335639298 Merge pull request #4894 from nonamethanks/add-million-scale
Add million scale to humanized number helper
2021-10-01 04:43:50 -05:00
evazion
33f3a12dd1 Update Ruby gems and Yarn packages. 2021-09-30 08:24:51 -05:00
nonamethanks
13741d88b5 Add million scale to humanized number helper 2021-09-30 14:14:40 +02:00
evazion
c99d0523bb /media_assets: add basic index and show pages.
* Add a basic index page at https://danbooru.donmai.us/media_assets.
* Add a basic show page at https://danbooru.donmai.us/media_assets/1.
* Add ability to search /media_assets.json by metadata. Example:
** https://danbooru.donmai.us/media_assets.json?search[metadata][File:ColorComponents]=3
* Add a "»" link next to the filesize on posts linking to the metadata page.

Known issues:

* Sometimes the MD5 links on the /media_assets page return "That record
  was not found" errors. These are unfinished uploads that haven't been
  made into posts yet.
* No good way to search for custom metadata fields in the search form.
* Design is ugly.
2021-09-29 07:46:11 -05:00
evazion
95fc3a207c /status: fix formatting of table cells.
Make the table cells on the /status page centered instead of
top-aligned, and make the labels fit on one line.
2021-09-29 06:36:10 -05:00
evazion
f9d25660b8 Fixup regression in 2eb89a835.
Fix regression in 2eb89a835 that broke the modqueue page because the
arguments to `paginated_search` changed and weren't updated here.

Also fix incorrect YARD documentation syntax.
2021-09-29 06:28:53 -05:00
evazion
627e8e1013 cron: fix undefined variable in exception handler (again)
Fixup for a1d4408c2.
2021-09-29 06:04:28 -05:00
evazion
2eb89a8354 Fix #4601: Hide deleted pools by default in pool search.
* On /pools, hide deleted pools by default in HTML responses. Don't
  filter out deleted pools in API responses.

* API change: on /forum_topics, only hide deleted forum topics by
  default for HTML responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/forum_topics.json?search[is_deleted]=false
  to filter out deleted topics.

* API change: on /tags, only hide empty tags by default for HTML
  responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/tags.json?search[is_empty]=false to filter
  out empty tags.

* API change: on /pools, default to 20 posts per page for API responses,
  not 40.

* API change: add `search[is_empty]` param to /tags.json endpoint.
  `search[hide_empty]=true` is deprecated in favor of `search[is_empty]=false`.

* On /pools, add option to show/hide deleted pools in search form.

* Fix the /forum_topics page putting `search[order]=sticky&limit=40` in
  the URL when browsing past page 1.
2021-09-29 05:44:59 -05:00
evazion
4a525c7473 cron: fix maintenance tasks failing to run.
Fix maintenance tasks failing to run in production. In production they
were losing the database connection and not re-establishing it, so they
couldn't queue jobs. `ApplicationRecord.verify!` will check if the
connection is lost and re-establish it if it is.

The database connection was being lost because in production we use a
Kubernetes service IP for the database IP, which is essentially a
virtual IP that maps to the real IP. This mapping is implemented with
IPVS[1][2], which has a default idle connection timeout of 5 minutes. If
the connection isn't used for more than 5 minutes, then it's closed.
Since maintenance only runs once an hour, the database connection would
be lost because it was idle for too long.

1: https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs
2: https://kubernetes.io/blog/2018/07/09/ipvs-based-in-cluster-load-balancing-deep-dive/
2021-09-28 18:06:57 -05:00
evazion
a1d4408c29 cron: fix undefined variable in exception handler. 2021-09-28 16:34:05 -05:00
evazion
126046cb69 posts: remove rating, note, and status locks.
Remove the ability for users to lock ratings, note, and post statuses.

Historically the majority of locked posts were from 10+ years ago when
certain users habitually locked ratings and notes on every post they
touched for no reason. Nowadays most posts have been unlocked. Only a
handful of locked posts are left, none of which deserve to be locked.

The is_rating_locked, is_note_locked, and is_status_locked columns still
exist in the database, but aren't used.
2021-09-27 22:32:30 -05:00
evazion
738be825ff twitter: include artist name in source URLs on post pages.
Show Twitter sources on post pages like this:

    https://twitter.com/BOW999/status/1261877313349640194

and not like this:

    https://twitter.com/i/web/status/1261877313349640194

We originally removed the artist name because the link would be broken
when the artist changed their name. This is no longer the case.
2021-09-27 11:07:25 -05:00
evazion
4477984d2d navbar: remove ?group_by=post from comments link
Remove the `group_by=post` param from the `https://danbooru.donmai.us/comments?group_by=post`
link in the main navbar. This is unnecessary since it's the default mode
for `https://danbooru.donmai.us/comments`.
2021-09-27 10:48:07 -05:00
evazion
3835a63771 cron: fix tasks not being logged.
Fix maintenance tasks not being logged by the cron daemon because
in production the log level defaulted to `error` instead of `info`.
2021-09-27 10:43:06 -05:00
evazion
ec9e844ab3 jobs: disable timeouts by default for all jobs.
Fix a regression in 52bf4a3a6 that caused certain jobs to timeout.
2021-09-27 09:17:50 -05:00
evazion
0e901b2f84 media file: get duration of animated GIFs, PNGs, and ugoiras.
Add methods to MediaFile to calculate the duration, frame count, and
frame rate of animated GIFs, PNGs, Ugoiras, and videos.

Some considerations:

* It's possible to have a GIF or PNG that's technically animated but
  just has one frame. These are treated as non-animated images.

* It's possible to have an animated GIF that has an unspecified
  frame rate. In this case we assume the frame rate is 10 FPS; this is
  browser dependent and may not be correct.

* Animated GIFs, PNGs, and Ugoiras all support variable frame rates.
  Technically, each frame has a separate delay, and the delays can be
  different frame-to-frame. We report only the average frame rate.

* Getting the duration of an APNG is surprisingly hard. Most tools don't
  have good support for APNGs since it's a rare and non-standardized
  format. The best we can do is get the frame count using ExifTool and the
  frame rate using ffprobe, then calculate the duration from that.
2021-09-27 05:18:25 -05:00
evazion
79fdfa86ae Fix various rubocop warnings. 2021-09-27 00:46:13 -05:00
evazion
a2a4ab887d newrelic: insert browser timing header manually.
Insert the <script> tag that monitors browser timing into the <head>
manually. This is to avoid this error:

    Skipping RUM instrumentation. Unable to find <body> tag in first 50000 bytes of document.

See also https://docs.newrelic.com/docs/agents/ruby-agent/features/new-relic-browser-ruby-agent/#manual_instrumentation
2021-09-27 00:46:13 -05:00
evazion
f8d52e6758 /status: add more information to /status page.
Add the following:

* Container name, machine name, worker id.
* Container uptime, puma uptime, worker uptime.
* Number of requests processed by current worker.
* ExifTool version.

Also change /status page to show information in tables instead of lists.
2021-09-26 23:11:08 -05:00
evazion
52bf4a3a6b maintenance: break maintenance tasks into individual jobs.
Break the hourly/daily/weekly/monthly maintenance tasks down into
individual delayed jobs. This way if one task fails, it won't prevent
other tasks from running. Also, jobs can be run in parallel, and can be
individually retried if they fail.
2021-09-26 20:38:30 -05:00
evazion
7d3e491dc6 posts: stop autotagging huge_filesize.
https://danbooru.donmai.us/forum_topics/19526
2021-09-26 18:26:38 -05:00
evazion
1075277d36 posts: remove unused methods. 2021-09-26 08:15:17 -05:00
evazion
01cdc7da7f media assets: add status column. 2021-09-26 08:06:13 -05:00
evazion
ab3f35580f metadata: move metadata parsing into ExifTool::Metadata.
Move the metadata parsing code from MediaAsset to ExifTool::Metadata so
we can use it outside the context of a MediaAsset, in particular when
dealing with a MediaFile that hasn't been saved to disk yet.
2021-09-26 07:19:36 -05:00
evazion
960817e9fe posts: don't send cookies for thumbnail requests.
Set `crossorigin="anonymous"` on the <img> tag for thumbnails. This
makes it so we don't send session cookies in requests for thumbnails.
Since images are served from cdn.donmai.us, and since session cookies
are set on *.donmai.us, session cookies are sent by default with every
thumbnail request.

Not sending cookies saves up to 1kb of overhead per thumbnail request
(in reality, it's less than this because of HTTP/2 multiplexing and
header compression).
2021-09-26 07:19:36 -05:00
evazion
7d3eebaced posts: purge all cached URLs when post is regenerated
Fix not all URLs being purged from Cloudflare when a post is
regenerated.
2021-09-26 01:21:32 -05:00
evazion
04cd6d0d3f newrelic: log screen resolution and pixel density.
Log the user's screen resolution and pixel density so we can make better
decisions about which screen sizes to support.
2021-09-25 06:46:25 -05:00
evazion
51bc953383 post preview component: remove workaround for blank width/height.
Remove workaround for old posts that had a null width or height. These
posts were fixed a while ago.
2021-09-25 06:34:15 -05:00
evazion
6f02918676 Merge pull request #4887 from nonamethanks/update-artist-finder
Update artist finder blacklist
2021-09-24 08:54:48 -05:00
evazion
463e6d7b49 artists: fix deadlock when banning artists.
Caused by d854bf6b. Banning an artist would deadlock because it was
performed in a transaction, which didn't work with the `parallel_each`
inside the "create an implication to banned_artist" step.
2021-09-24 08:40:33 -05:00
evazion
e8a09bc400 js: fix eslint warnings. 2021-09-24 08:40:33 -05:00
nonamethanks
16f76fe396 Update artist finder blacklist 2021-09-24 14:50:19 +02:00
evazion
74b03a7bd0 posts: fix incorrect exif rotation for PNGs.
Fix a bug where where PNG images could be incorrectly detected as
exif-rotated. This would happen when a PNG contained the
IFD0:Orientation flag. It's technically possible for a PNG to contain
this flag, but it's ignored by libvips and by browsers.

post #3762340 (nsfw) is an example of a PNG like this.

The fix is to use `autorot` to let libvips apply the rotation instead of
trying to interpret the exif data ourselves. Note that libvips-8.9 has a
bug where it doesn't strip the orientation flag after applying
`autorot`, which leads to the image being incorrectly rotated a second
time when generating the thumbnail. Use libvips-8.11 instead.
2021-09-23 00:10:00 -05:00
evazion
e7a455ea44 Merge pull request #4884 from nonamethanks/remove_long_image
Posts: stop autotagging long_image
2021-09-22 23:09:08 -05:00
evazion
ee5cd8330d uploads: fix exception when pruning expired uploads.
Hourly pruning of expired uploads was failing because of nil deference
errors in `media_asset.destroy!`. There are various cases where an
upload doesn't have a media asset, for example when the source url
fails to download or when the upload is of an invalid filetype.
2021-09-22 13:24:27 -05:00
evazion
6740ef17ab posts: fix detection of exif_rotation tag.
`IFD0:Orientation` is the orientation of the main image.
`IFD1:Orientation` is the orientation of the embedded thumbnail, if it
has one. Using `IFD1:Orientation` was incorrect here because some images
have a non-rotated main image but a rotated thumbnail. Post #1023563 is
an example.
2021-09-22 11:17:28 -05:00
evazion
b378785582 Fix #3692: Rotate pictures based on metadata
Rotate the image based on the EXIF orientation flag when generating
thumbnails and samples.

Also fix the width and height to be calculated correctly for rotated
images. Vips gives us the unrotated width and height of the image; we
have to detect whether the image is rotated and swap the width and
height manually to correct them. For example, if an image with the
"Rotate 90 CW" flag is 100x500 before rotation, then after rotation it's
500x100. This should fix #4883 (Exif rotation breaks Javascript fit-to-window)

We also have to fix it so that regenerating a post updates the width and
height of the post, in the event that it's a rotated image.

Finally we set `image-orientation: from-image;` even though it's
probably not necessary.
2021-09-22 11:12:50 -05:00
nonamethanks
ce8c8e1ab7 Posts: stop autotagging long_image 2021-09-22 11:16:52 +02:00
evazion
8738d8a645 Remove deletion appeal thread updater.
It was already disabled before, remove it completely now.
2021-09-22 01:57:45 -05:00
evazion
28d2753c53 BURs: don't allow builders to edit or reject BURs by other users.
Only admins can edit or reject BURs by other users now. The BUR creator
can still edit or reject their own BURs.
2021-09-22 00:34:44 -05:00
evazion
5af21f03de versions: default ARCHIVE_DATABASE_URL to DATABASE_URL.
Make it so that when ARCHIVE_DATABASE_URL isn't set, it defaults to
DATABASE_URL. In other words, if you don't have a separate archive
database configured, then default to using the main database for
post/pool versions.

Fixes an issue where running the test suite would fail if you didn't
explicitly set ARCHIVE_DATABASE_URL because it tried to use
`archive_test` as the post/pool versions database name.
2021-09-22 00:34:28 -05:00
evazion
c69ba54b5a Fix #4442: Autotag image metadata.
Autotag `greyscale`, `non-repeating_animation`, and `exif_rotation`.

Note that this does not detect all (or even most) greyscale images.
Artists often save greyscale images as RGB instead of as greyscale.
2021-09-21 11:18:06 -05:00
evazion
d5981754c4 posts: automatically tag animated_gif & animated_png on tag edit.
Automatically tag animated_gif and animated_png when a post is edited.
Add them back if the user tries to remove them from an animated post,
or remove them if the user tries to add them to a non-animated post.

Before we added these tags at upload time, but it was possible for users
to remove them after upload, or to incorrectly add them to non-animated
posts. They were added at upload time because we couldn't afford to open
the file and parse the metadata on every tag edit. Now that we save the
metadata in the database, we can do this.

This also makes it so you can't tag ugoira on non-ugoira files.

Known bug: it's possible to have an animated GIF where every frame is
identical. Post #3770975 is an example. This will be detected as an
animated GIF even though visually it doesn't appear to be animated.

Fixes #4041: Animated_gif tag not added to preprocessed uploads
2021-09-21 08:26:02 -05:00
evazion
4d0580b160 MediaFile: remove old libvips compatibility code.
Remove code for working with older versions of libvips. This makes
libvips 8.10+ a hard requirement. Older versions were already broken and
failed certain tests in the test suite.
2021-09-21 07:47:48 -05:00
evazion
ae7d964bf1 MediaFile: replace APNGInspector with ExifTool.
Replace our own handwritten APNG parser with ExifTool. This makes
ExifTool a hard requirement for handling APNGs.
2021-09-21 07:47:45 -05:00
evazion
c6bf3e7934 BURs: don't automatically retry failed BURs.
If a bulk update job fails, don't automatically retry it. Retrying it
will clobber the original error message if it fails again.
2021-09-20 16:33:23 -05:00
evazion
1d8a3bf09f BURs: allow failed BURs to be reapproved.
Fix it so that you can reapprove a failed BUR to run it again. Before
this would fail because it would end up trying to create the aliases
or implications again, which would fail because they already existed.
Now it ignores when an alias or implication already exists. It will
however finish tagging the posts if they haven't been fully moved.
2021-09-20 16:29:38 -05:00
evazion
98b3c82ac5 tests: fix deadlock during artist ban test.
The artist ban tests deadlocked because of a weird interaction between
threads and database transactions when tagging posts in parallel. Add a
hack to work around it.
2021-09-20 02:09:14 -05:00