Commit Graph

10314 Commits

Author SHA1 Message Date
evazion
7bdec9b5fa config: whitelist ngrok.io for development.
Add ngrok.io (plus a few more domains) to the hostname whitelist so that
it can be used as a hostname in development. Useful for testing
webhooks.

* https://ngrok.com
2021-03-11 03:02:50 -06:00
evazion
81fe68d392 bans: change expires_at field to duration.
Changes:

* Change the `expires_at` field to `duration`.
* Make moderators choose from a fixed set of standard ban lengths,
  instead of allowing arbitrary ban lengths.
* List `duration` in seconds in the /bans.json API.
* Dump bans to BigQuery.

Note that some old bans have a negative duration. This is because their
expiration date was before their creation date, which is because in 2013
bans were migrated to Danbooru 2 and the original ban creation dates
were lost.
2021-03-11 02:59:58 -06:00
evazion
791b8c61f6 post disapprovals: fix disapprovers being visible in API. 2021-03-11 02:59:56 -06:00
evazion
5a790ee25a wiki pages: remove category_name field from API.
Remove the `category_name` field from the `/wiki_page.json` API. This
field was originally added only because it was needed by our autocomplete
Javascript. It was also misnamed, it wasn't the tag's category name, it
was the category's ID.

Users should use `https://danbooru.donmai.us/wiki_pages.json?only=title,tag`
instead if they need this.

This triggered a N+1 query pattern when dumping wiki pages to BigQuery,
which made dumping wiki pages very slow. It also meant this field was
included in the database dump, even though it wasn't a real database
column.
2021-03-10 03:08:49 -06:00
evazion
4320e2ef70 dtext links: fix links from mod-only forum posts being exposed.
Fix links from mod-only forum posts being publicly visible in the
/dtext_links page.
2021-03-10 03:08:49 -06:00
evazion
b169d60f64 Fix saved searces, news updates, ip bans being dumped to BigQuery.
Prevent saved searches, news updates, and ip bans from being publicly
dumped to BigQuery. They didn't override the `visible` method to
restrict their visibility for anonymous users.
2021-03-10 03:08:49 -06:00
evazion
f235b72b3f Export public database dumps to BigQuery.
* Export daily public database dumps to BigQuery and Google Cloud Storage.
* Only data visible to anonymous users is exported. Some tables have
  null or missing fields because of this.
* The bans table is excluded because some bans have an expires_at
  timestamp set beyond year 9999, which BigQuery doesn't support.
* The favorites table is excluded because it's too slow to dump (it
  doesn't have an id index, which is needed by find_each).
* Version tables are excluded because dumping them every day is
  inefficient, streaming insertions should be used instead.

Links:

* https://console.cloud.google.com/bigquery?project=danbooru1
* https://console.cloud.google.com/storage/browser/danbooru_public
* https://storage.googleapis.com/danbooru_public/data/posts.json
2021-03-10 02:52:16 -06:00
evazion
5623cfb145 Add max lengths to comments, dmails, and forum posts.
* Max comment length: 15,000 characters.
* Max forum post length: 200,000 characters.
* Max forum topic title length: 200 characters.
* Max dmail length: 50,000 characters.
* Max dmail title length: 200 characters.
2021-03-08 18:46:49 -06:00
evazion
0249c290fd skeb: remove skeb from site_name in base strategy.
Fixup a mistake with the way the merge conflict was resolved in 9dd903d21.
2021-03-08 03:56:44 -06:00
evazion
ba9313c0d7 gems: add benchmark-ips gem to development group. 2021-03-08 03:51:29 -06:00
evazion
242e5689b6 Merge pull request #4751 from nonamethanks/skeb
Add skeb support
2021-03-08 03:51:20 -06:00
evazion
9dd903d212 Merge branch 'master' into skeb 2021-03-08 03:43:15 -06:00
evazion
66af4986c6 Merge pull request #4754 from nonamethanks/lazymap
Optimize Sources::Strategies.find()
2021-03-08 03:40:28 -06:00
evazion
da2cbefbec users: add back promoter field.
Add back promoter field removed in 7ed674f68 (cf #4750).
2021-03-08 03:17:21 -06:00
evazion
921dde6522 users: don't set inviter field; clear inviter field for most users.
* Don't set the inviter field for newly promoted users, or for Gold/Plat
  upgrades.

* Clear the inviter field for paid Gold/Plat upgrades, and for users who
  have a feedback or a modaction listing who invited them. This leaves
  about 600 remaining users with an inviter field with no other record
  of who invited them.

See #4750.
2021-03-08 03:16:34 -06:00
evazion
d9d090af2b Merge pull request #4750 from smowtenshi/patch-1
Change "Inviter" to "Promoter"
2021-03-08 01:53:31 -06:00
evazion
64440757c1 Merge pull request #4737 from nonamethanks/fix-mastodon-page-url
Sources: get correct mastodon page url
2021-03-08 01:49:56 -06:00
evazion
224d4932bf Merge pull request #4745 from nonamethanks/twitter-common-regexes
Twitter: update common hashtag regexes
2021-03-08 01:49:30 -06:00
evazion
e17cefe3ab Merge pull request #4753 from nonamethanks/fix-baraag-regex
Baraag: fix image regex
2021-03-08 01:49:15 -06:00
evazion
d478d72e0b tests: fix ip geolocation test. 2021-03-08 01:30:02 -06:00
evazion
1716cc5bf9 artists: add more artist url icons. 2021-03-08 01:30:02 -06:00
evazion
869a99d9a3 nijie: clear session cookie if it's expired (#4665).
If we detect that the session cookie has expired (by the presence of the
`#login_illust` element on the page), then clear the cached session
cookie. The current source fetch will still fail, but the next fetch
will try to login again and hopefully succeed.
2021-03-08 01:30:02 -06:00
evazion
5e4865701c nijie: reduce login cookie cache duration to 60 minutes (#4665). 2021-03-08 01:30:02 -06:00
evazion
27e62de316 css: fix paginator position on most viewed posts page, top searches page.
Fix the paginator not being centered on the /explore/posts/viewed and
/explore/posts/searches pages.
2021-03-08 01:30:02 -06:00
evazion
53fdf66922 Fix #4755: No navigation bar (prev/next button) when favgroup in query.
Fix the favgroup navbar not being shown when doing a `favgroup:<id>`
search for a public favgroup belonging to another user.
2021-03-08 01:30:00 -06:00
evazion
28d101eaa7 bans: fix exception when username is blank.
Fix exception when submitting the ban form and the username is blank.
2021-03-07 21:19:32 -06:00
evazion
5b37ac3adb favgroups: validate that name is present. 2021-03-07 21:15:33 -06:00
evazion
52d76a4f22 artists: fix error messages for invalid artist names.
* When trying to create an artist entry for a non-artist tag, set the
  error on the name attribute so that the artist name gets marked
  as incorrect in the artist edit form.

* Fix a bad `Name '' cannot be blank` error message when the artist name
  is blank.

* Fix showing wiki pages of non-artist tags in the artist edit form when
  the artist name conflicts with a non-artist tag (e.g. if you try to
  create an artist named '1girl', don't show the wiki for 1girl in the
  artist edit form).
2021-03-07 21:07:44 -06:00
evazion
fee7ed506b comments: put sticky option in popup menu instead of in edit form.
Put the option to sticky a comment in the "..." popup menu instead of
in the comment edit form. This makes it more consistent with deleting or
undeleting a comment.

Also fix a bug where the comment undelete icon didn't show up due to a
typo.
2021-03-07 20:13:38 -06:00
evazion
e6a501393a comments: change error message when body is blank.
Change error from "Body has no content" to "Body can't be blank" when a
user tries to submit an empty comment. This makes it consistent with
error messages in other models when someone tries to submit blank content.
2021-03-07 20:13:16 -06:00
evazion
4b61a9c73c /robots.txt: enable HTTP caching.
Cache /robots.txt at the HTTP level because it rarely changes but it
gets requested by bots relatively frequently.
2021-03-07 18:35:37 -06:00
evazion
250e7657b5 Update Ruby gems and Yarn packages. 2021-03-07 18:34:40 -06:00
nonamethanks
a4ae07416a Optimize Sources::Strategies.find()
Use lazy.map instead of map, so that we do not run every single
strategy's match method for every source
2021-03-07 18:20:10 +01:00
nonamethanks
4118a3f3c9 Baraag: fix image regex
Fixes a bug for Baraag.net that caused the batch bookmarklet to always pick the first picture in multi-image posts.
2021-03-06 08:50:08 +01:00
evazion
bb0540e1a1 Fix #4747: BUR layout partly broken on iOS.
Move the BUR help text from the <textarea> placeholder attribute to a
<details> tag that embeds the [[help:bur_notice]] wiki page.

Also update some CSS for the <details> tag that was meant to only apply
to the user upgrades page and didn't look good here.
2021-03-05 19:53:42 -06:00
evazion
be162a8ae9 Fix #4746: Related tags checkboxes don't work properly on some phones (iOS).
Only use hover to hide the checkboxes on devices that support hovering
(i.e. computers with a mouse). On some mobile devices, a tap is used to
emulate hovering, which meant the tag had to be tapped twice.
2021-03-05 18:22:47 -06:00
evazion
58e42ee8d3 rate limits: add /rate_limits endpoint.
Allow users to view their own rate limits with /rate_limits.json.

Note that rate limits are only updated after every API call, so this
page only shows the state of the limits after the last call, not the
current state.
2021-03-05 16:47:20 -06:00
evazion
1ee1e807cf rate limits: penalize user if they keep making requests while limited.
If the user makes a request while rate limited, penalize them 1 second
for that request, up to a maximum of 30 seconds. This means that if a
user doesn't stop making requests after being rate limited, then they
will stay rate limited forever until they stop.

This is to temp ban bots, especially spam bots, that flood requests
while ignoring HTTP errors or rate limits.

(Note that this is on a per-endpoint basis. Being rate limited on one
endpoint won't penalize you for making calls to other endpoints.)
2021-03-05 16:04:48 -06:00
evazion
413cd34c45 rate limits: adjust limits for various actions.
* Tie rate limits to both the user's ID and their IP address.

* Make each endpoint have separate rate limits. This means that, for
  example, your post edit rate limit is separate from your post vote
  rate limit. Before all write actions had a shared rate limit.

* Make all write endpoints have rate limits. Before some endpoints, such
  as voting, favoriting, commenting, or forum posting, weren't subject
  to rate limits.

* Add stricter rate limits for some endpoints:

** 1 per 5 minutes for creating new accounts.
** 1 per minute for login attempts, changing your email address, or
   for creating mod reports.
** 1 per minute for sending dmails, creating comments, creating forum
   posts, or creating forum topics.
** 1 per second for voting, favoriting, or disapproving posts.
** These rate limits all have burst factors high enough that they
   shouldn't affect normal, non-automated users.

* Raise the default write rate limit for Gold users from 2 per second to
  4 per second, for all other actions not listed above.

* Raise the default burst factor to 200 for all other actions not listed
  above. Before it was 10 for Members, 30 for Gold, and 60 for Platinum.
2021-03-05 16:02:57 -06:00
evazion
4492610dfe rate limits: rework rate limit implementation.
Rework the rate limit implementation to make it more flexible:

* Allow setting different rate limits for different actions. Before we
  had a single rate limit for all write actions. Now different
  controller endpoints can have different limits.

* Allow actions to be rate limited by user ID, by IP address, or both.
  Before actions were only limited by user ID, which meant non-logged-in
  actions like creating new accounts or attempting to login couldn't be rate
  limited. Also, because actions were limited by user ID only, you could
  use multiple accounts with the same IP to get around limits.

Other changes:

* Remove the API Limit field from user profile pages.
* Remove the `remaining_api_limit` field from the `/profile.json` endpoint.
* Rename the `X-Api-Limit` header to `X-Rate-Limit` and change it from a
  number to a JSON object containing all the rate limit info
  (including the refill rate, the burst factor, the cost of the call,
  and the current limits).
* Fix a potential race condition where, if you flooded requests fast
  enough, you could exceed the rate limit. This was because we checked
  and updated the rate limit in two separate steps, which was racy;
  simultaneous requests could pass the check before the update happened.
  The new code uses some tricky SQL to check and update multiple limits
  in a single statement.
2021-03-05 16:00:54 -06:00
smow
7ed674f682 Section removed as per comments 2021-03-04 22:07:52 +01:00
nonamethanks
dc97f4483b Add skeb support 2021-03-04 21:53:27 +01:00
smow
9554ca7219 Change "Inviter" to "Promoter"
It's kind of old and misleading
2021-03-04 20:47:43 +01:00
nonamethanks
e75489aa94 Twitter: update common hashtag regexes 2021-03-02 17:05:47 +01:00
evazion
52adf87489 Fix #4666: Broken network link for some IPs. 2021-03-01 20:44:51 -06:00
evazion
92b8f24724 ip addresses: move more logic to Danbooru::IpAddress.
* Move `is_local?` from IpLookup to Danbooru::IpAddress.
* Refactor more things to use Danbooru::IpAddress instead of using
  IPAddress directly.
2021-03-01 20:13:14 -06:00
evazion
35a0c6b11f Fix #4736: Display network prefix length (if present) in API key IP whitelist. 2021-03-01 02:38:18 -06:00
evazion
e5bbc039ae Fix #4740: Hide underscores in the "Add to favorite group" window. 2021-03-01 01:26:43 -06:00
evazion
a10dc33170 Fix #4742: Ctrl+Enter doesn't work on search bar.
The search form uses a <button type="submit"> tag instead of a
<input type="submit"> tag. It uses a <button> because it contains an
icon and <input> tags can't contain nested tags.
2021-03-01 01:19:59 -06:00
evazion
2bfb78684f css: use root-relative URLs in font face definitions.
Required for eventually upgrading to PnP in Yarn 2. PnP doesn't have a
node_modules folder.

https://yarnpkg.com/features/pnp
2021-03-01 00:39:49 -06:00