Commit Graph

12028 Commits

Author SHA1 Message Date
evazion
d2c520035b media assets: fix regenerating AI tags for flash files.
Fix it so that trying to regenerate AI tags for a Flash file doesn't
fail because Flash files have no image preview.

Also let `MediaFile.open` take a block argument.
2022-11-01 16:30:50 -05:00
evazion
29b3b83c9a github: update github actions versions. 2022-11-01 15:37:58 -05:00
evazion
2d74bc60db github: temp disable ARM build. 2022-11-01 14:53:14 -05:00
evazion
124af2808a docker: upgrade libvips to 8.13.3.
Followup to f9b7811f8. Better fix for #5323. libvips-8.13.3 has been
released so we can use that instead of compiling from HEAD.
2022-11-01 11:26:05 -05:00
evazion
f9b7811f8c Fix #5323: New samples and thumbnails have wrong colors
Caused by a bug in libvips-8.13.2 that was fixed in libvips issue 3027.
See libvips issue 3129 for details.

The fix is to build libvips from master until 8.13.3 is released.
2022-11-01 01:47:22 -05:00
evazion
ad998a8127 media assets: add image redirect routes.
Add URLs that redirect from a media asset to the image:

* https://danbooru.donmai.us/media_assets/6961761/original -> https://cdn.donmai.us/original/2c/4f/2c4ff193b0fc7106e59b2f6696a68a02.jpg
* https://danbooru.donmai.us/media_assets/6961761/sample   -> https://cdn.donmai.us/sample/2c/4f/sample-2c4ff193b0fc7106e59b2f6696a68a02.jpg
* https://danbooru.donmai.us/media_assets/6961761/720x720  -> https://cdn.donmai.us/180x180/2c/4f/2c4ff193b0fc7106e59b2f6696a68a02.webp
* https://danbooru.donmai.us/media_assets/6961761/360x360  -> https://cdn.donmai.us/180x180/2c/4f/2c4ff193b0fc7106e59b2f6696a68a02.jpg
* https://danbooru.donmai.us/media_assets/6961761/180x180  -> https://cdn.donmai.us/180x180/2c/4f/2c4ff193b0fc7106e59b2f6696a68a02.jpg

This is useful if you have a media asset ID and want to get to the image
without looking up the image URL in the API.

This endpoint is rate-limited to 5 requests per second. It's not meant
to be used for things like thumbnail galleries or bulk scraping images.
2022-11-01 01:47:18 -05:00
evazion
b41b67af6c media assets: add dynamically-generated thumbnails (owner-only).
Add ability to dynamically generate thumbnails with:

* https://danbooru.donmai.us/media_assets/6961761.jpg?width=180&height=180

This is currently restricted to the Owner-level user because it's slow.
2022-11-01 01:36:38 -05:00
evazion
acc511ab7d media assets: fix dimensions of flash files.
Use ExifTool to get the dimensions of Flash files instead of calculating
it ourselves. Avoids copying third-party code.

Fixes a bug where Flash files with fractional dimensions (e.g. 607.6 x 756.6)
had their dimensions rounded down instead of rounded up.

Fixes another bug where Flash files could return negative dimensions.
This happened for two files:

* https://danbooru.donmai.us/media_assets/228662 (-179.2 x -339.2)
* https://danbooru.donmai.us/media_assets/228664 (-179.2 x -339.2)

Now we round these up to 1x1. This is still wrong, but it's less wrong than before.
2022-10-31 17:30:40 -05:00
evazion
2f2c73eebb media assets: fix dimensions of corrupt GIFs.
Fix certain corrupt GIFs returning dimensions of 0x0. This happened
when the GIF was too corrupt for libvips to read. Fixed by using
ExifTool to read the dimensions instead.

Also add validations to ensure that it's not possible to have media
assets with a width or height of 0.
2022-10-31 15:18:02 -05:00
evazion
e6ebc54b6c media assets: include image width, height, and file type in EXIF metadata.
Previously the width, height, and file type fields returned by ExifTool
weren't saved in the media metadata because they were already saved in
the media asset. However, in some cases, it can be useful to compare
ExifTool's version of these fields with our own. This can be useful when
an image is corrupt and libvips can't get the width or height, or when
it's a video and we want to make sure we detected the correct type of video.

script/files/123_refresh_media_metatadata.rb needs to be run after this
to update the metadata.
2022-10-31 15:17:35 -05:00
nonamethanks
e294e1193e Add reddit support 2022-10-31 15:10:27 +01:00
evazion
2341d8341d posts: fix flagged posts not having red thumbnail borders for approvers. 2022-10-31 02:39:45 -05:00
evazion
27e4ae3d33 script/fixes/123_refresh_media_metadata.rb: don't wrap in transaction.
Don't wrap the metadata refresh script in a transaction because it could
be a very long running operation and it's not good to leave a transaction
open that long.
2022-10-31 02:29:07 -05:00
evazion
dfd19f3ad4 media file: fix exception when getting frame count of corrupted gif.
Fix a `gifload: no frames in GIF` error from libvips when trying to read
the frame count for https://danbooru.donmai.us/media_assets/1141668.
2022-10-31 02:27:26 -05:00
evazion
214a877c3c users: fix typo in contributor/approver migration script.
Fixup for #5306.
2022-10-30 21:19:05 -05:00
evazion
3846584540 mastodon: fix exception when fetching data for deleted posts.
Fix a `OAuth2::Error: Record not found` exception when trying to fetch
source data for a deleted Pawoo or Baraag post.
2022-10-30 17:26:43 -05:00
evazion
c76e0bd4c1 gelbooru: fix normalization of old image URLs. 2022-10-30 17:26:43 -05:00
evazion
30b286a030 Fix #5241: Source extractors not using 60s timeout.
Raise the default HTTP timeout from 10 seconds to 20 seconds.
2022-10-30 17:26:42 -05:00
evazion
042863b2a6 tests: fix broken tests. 2022-10-30 17:26:42 -05:00
evazion
eff82c43d2 emails: fix validation of undeliverable email addresses.
* Fix bug where bogus domains weren't found because we checked for `nil?` instead of `blank?`.
* Fix bug where bogus names weren't found because we used a nonexistent variable in the
  RCPT TO check (`to_address` instead of `address`).
2022-10-30 14:49:12 -05:00
evazion
d65a35d4ae media assets: add fix script to refresh metadata.
Add a script to go through every media asset and check the metadata
(width, height, duration, filesize, md5, EXIF metadata) and update it
if it's changed. This is necessary after upgrading ExifTool because the
metadata it returns may have changed.
2022-10-30 14:49:12 -05:00
evazion
5456a2ea29 Merge pull request #5306 from nonamethanks/new-roles
Users: add Contributor and Approver user levels
2022-10-30 03:27:18 -05:00
evazion
af7c40d98e Merge pull request #5316 from nottalulah/patch-2
uploads: link to the media asset from the upload page
2022-10-28 23:44:07 -05:00
evazion
d9c982fdaa Merge pull request #5315 from nottalulah/patch-1
user actions: fix password change causing empty entry
2022-10-28 23:43:49 -05:00
evazion
dab239929a Merge pull request #5314 from eltociear/patch-2
tests: fix typo in application_controller_test.rb
2022-10-28 23:43:36 -05:00
evazion
83ba91425f uploads: fix .mp4 filetype detection.
Fix a bug where MP4 files with major brand "iso4" weren't detected as
MP4, so they couldn't be uploaded.

This switches our MP4 detection code to something very similar to Firefox's
MP4 sniffing algorithm. Ours is slightly wrong because a) we only check
the major_brand, not the minor_brands, and b) we falsely detect certain 3GP
videos as MP4. 3GP is a very similar format to MP4, close enough that it
can be played by Chrome (but not Firefox), but it's technically not MP4
and should not have a .mp4 file extension. We leave it alone because we
have two existing 3GP media assets that were falsely detected as MP4.

https://danbooru.donmai.us/forum_topics/22356
https://github.com/mozilla/gecko-dev/blob/master/toolkit/components/mediasniffer/nsMediaSniffer.cpp#L78
https://mimesniff.spec.whatwg.org/#signature-for-mp4
2022-10-28 03:51:46 -05:00
evazion
6e685cdd42 uploads: disallow more video formats not supported by all browsers.
Disallow uploading videos with 10-bit color or 4:4:4 chroma subsampling.
Neither of these features are supported by Firefox.

Only 8 such videos have been uploaded to Danbooru:

* https://danbooru.donmai.us/media_assets/3070695 (4:4:4)
* https://danbooru.donmai.us/media_assets/3070697 (4:4:4)
* https://danbooru.donmai.us/media_assets/3292518 (4:4:4)
* https://danbooru.donmai.us/media_assets/3358659 (10-bit)
* https://danbooru.donmai.us/media_assets/3358660 (10-bit)
* https://danbooru.donmai.us/media_assets/3730866 (10-bit)
* https://danbooru.donmai.us/media_assets/5056665 (10-bit)
* https://danbooru.donmai.us/media_assets/5479605 (4:4:4)

Note that Exiftool doesn't output this information, so it's not in the
EXIF metadata. We have to reply on ffprobe at upload time instead.

Followup to #3615.
2022-10-28 01:21:34 -05:00
Lily
15d749d4c0 uploads: link to the media asset from the upload page
Similar to how there's a link on the post page. For convenience of checking metadata.
2022-10-27 16:50:42 -03:00
Lily
e553381405 user actions: fix password change causing empty entry 2022-10-27 11:44:47 -03:00
Ikko Ashimine
df88a92fc4 tests: fix typo in application_controller_test.rb
overriden -> overridden
2022-10-27 20:39:26 +09:00
evazion
57316dc622 css: fix autoprefixer warning about flex-end. 2022-10-27 04:17:45 -05:00
evazion
36b82f2b35 Fix #5118: has_large in posts API responses is sometimes nil 2022-10-27 04:06:47 -05:00
evazion
7953c2f091 irb: really disable autocomplete.
Fixup for c0afce18b.
2022-10-27 02:56:44 -05:00
evazion
e09f990a60 uploads: raise default max upload limit to 100MB.
The previous upload limit was 50MB, to discourage uploading excessively
large images. But for videos this can be too low, especially for long
videos at high resolutions.

The upload limit really should be around 200MB to allow for a ~10Mbps
bitrate at the maximum upload length of 2:20. However, the maximum
upload limit under Cloudflare is 100MB, so if we raised the upload limit
beyond this, it would only work when uploading a file from a source URL,
not from your computer. To get around this, we would have to put the
upload endpoint outside of Cloudflare, or allow uploading files in
chunks.
2022-10-27 02:33:21 -05:00
evazion
a9d586e93a Fix #3615: Unsupported video codecs.
Don't allow uploading videos with unsupported video codecs.

The only video codecs we allow for MP4 files are H.264 and VP9. Other
codecs, including H.265 (aka HEVC), MPEG-4 part 2, and AV1, are
disallowed because they're not universally supported by browsers.
Firefox doesn't support H.265 or MPEG-4 part 2, and Safari doesn't
support AV1.

Additionally, don't allow videos with multiple video tracks, multiple
audio tracks, or no video tracks. Multiple video and audio tracks are
disallowed because they're rare and for moderation purposes, we don't
want people hiding content in extra tracks.

These restrictions really only apply to MP4 videos, since WebM files
don't support multiple video or audio tracks and only support a limited
number of codecs (VP8 and VP9 for videos, Vorbis and Opus for audio).

There are currently 22 posts with unsupported video codecs:

* https://danbooru.donmai.us/posts?tags=video+is:mp4+-exif:Track1:CompressorID=avc1+-exif:Track2:CompressorID=avc1+-exif:Track1:CompressorID=vp09+-exif:Track2:CompressorID=vp09 # AVC1 is H.264

There is one post that has multiple audio tracks:

* https://danbooru.donmai.us/posts/2382057
2022-10-27 01:43:33 -05:00
evazion
48ecb80d6b Fix #5230: video upload 500 error (StatementInvalid) & empty error panel on page
Fix StatementInvalid exception when uploading https://files.catbox.moe/vxoe2p.mp4.

This was a result of multiple bugs:

* First, generating thumbnails for the video failed. This was because
  the video uses the AV1 codec, which FFmpeg failed to decode. It failed
  because our version of FFmpeg was built without the `--enable-libdav1d`
  flag, so it uses the builtin AV1 decoder, which apparently can't
  handle this particular video (it spews a bunch of errors about "Failed
  to get pixel format" and "missing sequence header" and "failed to get
  reference frame").

* Because generating the thumbnails failed, an exception was raised. We
  tried to save the error message in the upload_media_assets.error
  field. However, this also failed because the error message was 77kb
  long (it contained the entire output of the ffmpeg command), but the
  `upload_media_assets` table had a btree index on the `error` column,
  which meant the maximum length of the error column was limited to
  ~2.7kb. This lead to a StatementInvalid exception being raised.

* Because the StatementInvalid exception was raised while we were trying
  to set the upload media asset's status to `failed`, the upload was
  left stuck in the `processing` state rather than being set to the
  `failed` state.

* Because the upload was stuck in the `processing` state, the upload
  page would hang forever waiting for the upload to complete.

The fixes are to:

* Build FFmpeg with `--enable-libdav1d` to use libdav1d for decoding AV1
  videos instead of the builtin AV1 decoder.

* Remove the index on the `upload_media_assets.error` column so that
  setting overly long error messages won't fail.

* Catch unexpected exceptions in ProcessUploadMediaAssetJob so we can
  mark uploads as failed, even if `process_upload!` itself fails because
  it raises an unexpected exception inside its own exception handler.

* Check that the video is playable with `MediaFile::Video#is_corrupt?` before
  allowing it to be uploaded. This way we can return a better error
  message if we can't generate thumbnails because the video isn't
  playable. This requires decoding the entire video, so it means uploads
  may take several seconds longer for long videos. It's also a security
  risk in case ffmpeg has any bugs.

* Define `MediaAsset#preview!` as raising an exception on error, so
  it's clear that generating thumbnails can fail. Define `MediaAsset#preview`
  as returning nil on error for when we don't care about the cause of
  the error.
2022-10-26 22:49:55 -05:00
evazion
33e9e5b3f0 db: apply good_jobs migrations
Apply a couple of migrations from `bin/rails generate good_job:update`.
2022-10-26 04:15:37 -05:00
evazion
f90db34323 Update Ruby gems. 2022-10-26 04:15:37 -05:00
evazion
c0afce18b8 irb: disable autocomplete. 2022-10-26 04:15:37 -05:00
evazion
81d9cf4b96 uploads: add .avif and .webp extensions to file picker dialog. 2022-10-26 04:15:37 -05:00
evazion
9c811611c6 media assets: add full variant for .avif and .webp files.
Add a JPEG conversion for .avif and .webp files. The `full` variant is
the .avif or .webp file converted to JPEG format, with the same
resolution as the original file (full resolution).

Known bug: When converting an HDR .avif file to .jpeg, the resulting
image is too bright compared to the original image as rendered by
Firefox or Chrome.
2022-10-26 04:09:59 -05:00
evazion
7bfdf5cfbe Merge pull request #5303 from nonamethanks/fix-structure
Update structure.sql to the one generated by db:migrate
2022-10-26 03:57:05 -05:00
evazion
7e99be0b2e searchable: better fix for #5312.
Simplify fix for #5312. Fixes an exception when searching `has_one`
associations like `/wiki_pages?search[artist][is_banned]=true`.
2022-10-25 23:30:57 -05:00
evazion
9e2aff874f tests: fix strategy_should_work to not perform API calls outside of tests.
Fix strategy_should_work to not perform API calls outside of `should`
blocks. This could cause the whole test suite to crash if a source test
raised an unexpected exception.
2022-10-25 22:41:36 -05:00
evazion
acea0d5553 Fix #5065: .webp images upload support
Add ability to upload .webp images.

Animated WebP images aren't supported. This is because they aren't
supported by FFmpeg yet[1], so generating thumbnails and samples for
them would be more complicated than for other formats.

[1]: https://trac.ffmpeg.org/ticket/4907
2022-10-25 22:41:36 -05:00
evazion
df0e9bc4a7 uploads: fix it being possible to upload .mkv files as .webm.
Fix it being possible to upload arbitrary .mkv files and have them
be treated as .webm. This was possible because WebM uses the Matroska
container format, and we only checked for the Matroska header, not that
the file was actually a WebM.

There were only 6 such files in production:

* https://danbooru.donmai.us/posts?tags=exif:Matroska:DocType=matroska
* https://danbooru.donmai.us/posts/5522036
* https://danbooru.donmai.us/posts/4743498
* https://danbooru.donmai.us/posts/3925427
* https://danbooru.donmai.us/posts/3147897
* https://danbooru.donmai.us/posts/2965862
* https://danbooru.donmai.us/posts/2430436

These videos are playable in Chrome, but not in Firefox, since Firefox
doesn't support .mkv files (it supports some, depending on which codecs
are used, but not .mkv files in general).
2022-10-25 19:32:31 -05:00
evazion
6413b9abcd Fix #5312: StatementInvalid Error When Querying the media_assets Attribute of Uploads 2022-10-25 16:48:16 -05:00
evazion
c96d60a840 uploads: add support for uploading .avif files.
Features of AVIF include:

* Lossless and lossy compression.
* High dynamic range (HDR) images
* Wide color gamut images (i.e. 10- and 12-bit color depths)
* Transparency (through alpha planes).
* Animations (with an optional cover image).
* Auxiliary image sequences, where the file contains a single primary
  image and a short secondary video, like Apple's Live Photos.
* Metadata rotation, mirroring, and cropping.

The AVIF format is still relatively new and some of these features aren't well
supported by browsers or other software:

* Animated AVIFs aren't supported by Firefox or by libvips.
* HDR images aren't supported by Firefox.
* Rotated, mirrored, and cropped AVIFs aren't supported by Firefox or Chrome.
* Image grids, where the file contains multiple images that are tiled
  together into one big image, aren't supported by Firefox.
* AVIF as a whole has only been supported for a year or two by Chrome
  and Firefox, and less than a year by Safari.

For these reasons, only basic AVIFs that don't use animation, rotation,
cropping, or image grids can be uploaded.
2022-10-25 03:29:58 -05:00
evazion
420ff2f2f5 docker: update base image dependencies.
* Update base Ubuntu image from 22.04 to 22.10.
* Update FFmpeg from 4.4.1 to 5.1.2
* Update MozJPEG from 4.0.3 to 4.1.1.
* Update ExifTool from 12.30 to 12.42.

The FFmpeg upgrade is necessary for .avif file support. Older versions
of ffprobe don't handle .avif files correctly. It either returns an
error, or in certain cases it can interpret a static .avif image as a
video (since .avif files are basically .mp4 files in disguise).
2022-10-24 20:03:37 -05:00
evazion
5b19e544cf Fix #5310: "Details" on disapproval dropdown leads to a broken url. 2022-10-24 01:58:28 -05:00