Commit Graph

12015 Commits

Author SHA1 Message Date
evazion
c133866cb7 users: don't allow users to choose reserved names.
Don't allow users to choose names that conflict with search syntax, like `any` or `none`, or names
that impersonate user levels, like `Admin`, `Moderator`, `Anonymous`, etc.
2022-11-06 16:00:07 -06:00
evazion
8bd60e41a1 Fix #4555: Invalidate sessions for deleted users
Fix three exploits that allowed one to keep using their account after it was deleted:

* It was possible to use session cookies from another computer to login after you deleted your account.
* It was possible to use API keys to make API requests after you deleted your account.
* It was possible to request a password reset, delete your account, then use the password reset link
  to change your password and login to your deleted account.
2022-11-06 14:58:08 -06:00
evazion
6f08e1427b users: set is_deleted flag when account is deleted.
* Set the `is_deleted` flag when the user is deleted.
* Return the `is_deleted` flag in the /users.json API.
2022-11-06 13:18:49 -06:00
nonamethanks
0a78a6188d Reddit: support user galleries and embedded images 2022-11-06 15:04:05 +01:00
evazion
f083f29c3b users: add is_deleted flag.
Add is_deleted flag to users table in preparation for fixing #4555.
2022-11-06 01:41:14 -05:00
evazion
b43a913ad7 users: delete more data when user deactivates their account.
* Don't delete the user's favorites unless private favorites are enabled. The general rule is that
  public account activity is kept and private account activity is deleted.
* Delete the user's API keys, forum topics visits, private favgroups, downvotes, and upvotes (if
  privacy is enabled).
* Reset all of the user's account settings to default. This means custom CSS is deleted, where it
  wasn't before.
* Delete everything but the user's name and password asynchronously.
* Don't log the current user out if it's the owner deleting another user's account.
* Fix #5067 (Mod actions sometimes not created for user deletions) by wrapping the deletion process
  in a transaction.
2022-11-06 00:05:18 -05:00
evazion
3ffde5b23d users: move account deletion endpoint to /users/:id/deactivate.
Move the account deletion endpoint from /maintenance/users/deletion to either:

* https://danbooru.donmai.us/users/deactivate
* https://danbooru.donmai.us/users/:id/deactivate

This incidentally allows the Owner-level user to deactivate accounts belonging to other users. This
is meant for things like deactivating inactive accounts with invalid or abusive names. This is
limited to accounts below Gold level for security.
2022-11-05 19:09:56 -05:00
evazion
59872d2ed5 comments: fix N+1 query when loading comment votes.
Doing both `@comments.includes(:votes)` and `comment.votes.active` forced votes to be loaded twice.
2022-11-05 19:09:56 -05:00
evazion
3f99b1093a editorconfig: set max line length to 120. 2022-11-05 19:09:56 -05:00
evazion
21a3763f0f users: set archives DB timeout on profile pages.
Fixes profile pages potentially hanging for 60+ seconds if the archives
database is slow to respond.
2022-11-05 19:09:56 -05:00
evazion
4ae3ebf845 artists: add SQL script to find incorrect artist URLs. 2022-11-05 19:09:56 -05:00
evazion
af9e570419 skeb: parse www.skeb.jp URLs. 2022-11-05 19:09:56 -05:00
evazion
ab08ad24e6 baraag: parse https://baraag.net/web/@{name} URLs. 2022-11-05 19:09:56 -05:00
evazion
fcb68048e3 fanbox: parse https://pixiv.net/fanbox URLs. 2022-11-05 19:09:56 -05:00
evazion
f5b003fc94 furaffinity: parse https://www.furaffinity.net/stats/{name} URLs. 2022-11-05 19:09:56 -05:00
nonamethanks
9f3f302328 Lofter: support another theme
Fixes #5334.
2022-11-06 00:03:15 +01:00
nonamethanks
758b14ad46 Remove superfluous site name definitions and update artist url order 2022-11-05 20:03:07 +01:00
evazion
c1623f3fcc posts: don't remove sound tag from Flash posts.
Fix a bug in 28237e2e0 where editing a Flash post would automatically remove the `sound` tag.
2022-11-05 02:26:11 -05:00
evazion
60efde0e68 reddit: fix exception when work_id is nil. 2022-11-05 01:26:47 -05:00
evazion
28237e2e09 posts: automatically tag videos with sound.
Automatically add the `sound` tag if the post has sound. Remove the tag if the post doesn't have sound.

A video is considered to have sound if its peak loudness is greater than -70 dB. The current quietest post
on Danbooru has a peak loudness of -62 dB (post #3470668), but it's possible to have audible sound at
-80 dB or possibly even lower. It's hard to draw a clear line between "silent" and "barely audible".
2022-11-05 01:02:29 -05:00
evazion
4a241ac6b5 media assets: don't round volume levels.
At first we rounded loudness values to 4 decimal places to make them
easier to compare. This meant the lowest level was 0.0001, or -80 dB,
but it's possible for volume levels to go even lower than that.
2022-11-05 00:29:44 -05:00
evazion
e005520ad8 media assets: save audio volume levels in media metadata.
For videos with sound, save information about audio volume levels in the
media asset's metadata. These values are stored:

* FFmpeg:AudioPeakLoudness       The peak loudness of the audio track, from 0.0 (silent) to 1.0 (max volume)
* FFmpeg:AudioAverageLoudness    The average loudness of the audio track, from 0.0 (silent) to 1.0 (max volume).
* FFmpeg:AudioLoudnessRange      The difference between the quietest and loudest sounds in the audio track (in decibels).
* FFmpeg:AudioSilencePercentage  The percentage of the video that is silent (1.0 is completely silent, 0.5 is 50% silence, 0.0 is no silence).

These values are calculated based on the EBU R 128 standard, using the ffmpeg command below:

  ffmpeg -i file.mp4 -af silencedetect=duration=0.05:noise=0.0001,ebur128=metadata=1:peak=true:dualmono=true -f null /dev/null

See the links below for details:

* https://en.wikipedia.org/wiki/EBU_R_128
* https://www.ffmpeg.org/ffmpeg-filters.html#ebur128-1
* https://tech.ebu.ch/loudness
* https://tech.ebu.ch/docs/tech/tech3341.pdf
2022-11-04 18:06:30 -05:00
nonamethanks
fc4d620002 Add bilibili support 2022-11-04 12:11:08 +01:00
evazion
a244ec5a3b Merge pull request #5325 from nonamethanks/feat-reddit
Add reddit support
2022-11-04 02:28:29 -05:00
evazion
45c9c03c96 Merge pull request #5327 from NamelessContributor/feat-count-search
post counts: add search field.
2022-11-04 02:16:36 -05:00
evazion
4c0f62254e script/fixes/123_refresh_media_metadata.rb: refresh metadata in parallel. 2022-11-03 22:09:24 -05:00
evazion
cb35bad237 media assets: fix incorrect frame counts for certain .webm files.
Fix calculating incorrect frame counts for certain .webm files. An
example is https://danbooru.donmai.us/media_assets/5968481.

Caused by ffmpeg printing multiple `frame= NNN` lines, and us taking the
first one instead of the last one:

    frame=    1 fps=0.0 q=-0.0 size=N/A time=00:00:00.08 bitrate=N/A speed=2.07x    
[null @ 0x56046ff4e440] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 321 >= 321
    [null @ 0x56046ff4e440] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 321 >= 321
    frame=  395 fps=0.0 q=-0.0 size=N/A time=00:00:06.66 bitrate=N/A speed=12.3x    
frame=  791 fps=759 q=-0.0 size=N/A time=00:00:13.26 bitrate=N/A speed=12.7x    
frame= 1193 fps=772 q=-0.0 size=N/A time=00:00:19.94 bitrate=N/A speed=12.9x    
frame= 1374 fps=780 q=-0.0 Lsize=N/A time=00:00:22.86 bitrate=N/A speed=  13x
    video:719kB audio:4288kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
2022-11-03 22:01:51 -05:00
evazion
5f8fefccaa media assets: fix .webm files not including video/audio bit rates in metadata.
Fix .webm files not including the `FFmpeg:VideoBitRate` and `FFmpeg:AudioBitRate`
fields in the media_metadata table. This was because the .webm format
doesn't include the video or audio bit rates in the metadata, and
ffprobe doesn't calculate them either, so we have to calculate them
ourselves by hand.

Fixup for 523d7afdd.
2022-11-03 21:06:08 -05:00
evazion
c21146f94d media file: fix error when calculating dimensions of corrupt gif.
Fix exception when `MediaFile::Image#dimensions` calls `metadata.width`.
Caused by the `ExifTool::Metadata#merge` method returning a Hash instead
of a new `ExifTool::Metadata` instance.
2022-11-03 04:08:26 -05:00
evazion
523d7afdd1 media assets: save more metadata for videos.
Include the following metadata tags for videos:

* FFmpeg:MajorBrand (e.g. mp42)
* FFmpeg:PixFmt (e.g. yuv420p. Indicates bit depth and color subsampling mode)
* FFmpeg:FrameCount (e.g. total number of frames in the video)
* FFmpeg:VideoCodec (e.g. h264)
* FFmpeg:VideoProfile (e.g. Main)
* FFmpeg:AudioCodec (e.g. AAC)
* FFmpeg:AudioProfile (e.g. LC)
* FFmpeg:AudioLayout (e.g. stereo)
* FFmpeg:AudioBitRate (e.g. 128kb/s)
2022-11-02 21:57:19 -05:00
evazion
3172031caa media assets: track corrupted files in media metadata.
If a media asset is corrupt, include the error message from libvips or
ffmpeg in the "Vips:Error" or "FFmpeg:Error" fields in the media
metadata table.

Corrupt files can't be uploaded nowadays, but they could be in the past,
so we have some old corrupted files that we can't generate thumbnails
for. This lets us mark these files in the metadata so they're findable
with the tag search `exif:Vips:Error`.

Known bug: Vips has a single global error buffer that is shared between
threads and that isn't cleared between operations. So we can't reliably
get the actual error message because it may pick up errors from other
threads, or from previous operations in the same thread.
2022-11-02 20:48:15 -05:00
evazion
19c091d81c dmcas: add rate limit and email validation to DMCA form. 2022-11-02 20:47:22 -05:00
NamelessContributor
79a4fcd08a post counts: add search field. 2022-11-02 13:46:46 +01:00
evazion
e849d8f1c2 posts: optimize filetype: searches.
When searching posts by width, height, file size, or file extension, use the
values from the media_assets table rather than the posts table.

This makes filetype: searches faster because the file_ext is indexed on
the media assets table, but not on the posts table.

This paves the way for getting rid of the width, height, file_size, and
file_ext indexes on the posts table in the future. It's wasteful to
index these columns on both the posts table and the media assets table.
2022-11-02 02:03:14 -05:00
evazion
3ecc389995 Fix #5313: Exception in -duration:>0. 2022-11-02 00:03:31 -05:00
evazion
0317ced63a media assets: fix unsafe redirect error in /media_assets/:id/:variant
Fix error when redirecting to image hosted on separate domain.
2022-11-01 18:03:58 -05:00
evazion
69d88568a6 media assets: allow assets to be regenerated.
Add a `MediaAsset#regenerate!` method that regenerates everything about
the asset, including the metadata, thumbnails, IQDB, cached Cloudflare
URLs, and AI tags.

Fixes it so that a) it's possible to regenerate media assets that aren't
attached to posts and b) regenerating a post regenerates everything. Before
it didn't regenerate the metadata, AI tags, or all of the cached URLs.
2022-11-01 17:32:40 -05:00
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