Commit Graph

487 Commits

Author SHA1 Message Date
evazion
1d15ce2bcd Remove Danbooru Winter Sale. 2021-01-01 04:16:38 -06:00
evazion
83d6cd5980 Update Winter Sale banner for last day. 2020-12-31 06:50:10 -06:00
evazion
d9a8fc99bc javascript: change Cookie.put to take expiry in seconds. 2020-12-31 06:50:10 -06:00
evazion
fd18291382 Add Danbooru Winter Sale. 2020-12-25 06:07:21 -06:00
evazion
069231a33b user upgrades: update upgrade landing page.
* Add a frequently asked questions section.
* Add nicer looking upgrade buttons.
* Format the page nicer.
* Prevent users from attempting invalid upgrades on users that are
  already Platinum or above.
2020-12-25 00:47:08 -06:00
evazion
3d1ff9dff9 autocomplete: fix not detecting correct tag in edit box. 2020-12-17 23:57:13 -06:00
evazion
0d83106a21 autocomplete: fix cache issue related to content negotiation.
This is the scenario:

* You type something in autocomplete, let's say 'touhou'.
* Autocomplete calls /autocomplete?search[query]=touhou&search[type]=tag_query
* The endpoint returns JSON, because the autocomplete call sets an
  `Accept: application/json` header requesting JSON.
* Visit /autocomplete?search[query]=touhou&search[type]=tag_query in your browser.
* Notice that the cached JSON response is incorrectly returned, not an
  HTML response like the browser requested.

The problem is that the response type is chosen based on the Accept
header, but the response didn't set the `Vary: Accept` header, so the
browser doesn't know the response type can vary and so it incorrectly
returns the cached response.

This issue is partially fixed by Rails 6.1 ([1]), which properly sets the
`Vary: Accept` header when the response depends on the Accept header.

However, the next issue is that Cloudflare doesn't respect the Vary
header at all ([2], [3]). Therefore we can't use the Accept header to
pick the format, instead we have explicitly specify the format with
/autocomplete.json.

This is clearer and better for caching anyway. Using the `Vary: Accept`
header reduces the cache hit rate, because the exact format of the
Accept header varies across browsers, which fragments the cache.

Whew.

[1] https://github.com/rails/rails/pull.36213
[2] https://community.cloudflare.com/t/cloudflare-cdn-cache-to-support-http-vary-header/160802
[3] https://support.cloudflare.com/hc/en-us/articles/115003206852
[4] https://www.smashingmagazine.com/2017/11/understanding-vary-header/
2020-12-16 03:13:55 -06:00
evazion
4cdaf7bcdf autocomplete: update html data attributes.
* Remove the `source` and `weight` html data attributes (no longer used).
* Make the `type` html data attribute properly indicate the completion
  type. Valid types: `tag`, `tag-alias`, `tag-abbreviation`,
  `tag-autocorrect`, `tag-other-name`.
2020-12-14 18:58:11 -06:00
evazion
23f6b8a46d js: refactor Cookie.put.
* Set Max-Age= flag instead of Expires= flag.
* Set Secure flag when using HTTPS.
* Extend default cookie lifetime from 1 year to 20 years.
* Remove "session" expiration option (unused).
* Remove max cookie size check.

The cookie size check was previously added in #2518 to deal with running
out of space due to tag scripts and blacklists. This should no longer
happen since we no longer use cookies for these things. Remove the
warning because it should never happen, we can't fix it if it does, and
the user probably won't know how to fix it either.
2020-12-14 15:39:17 -06:00
evazion
df1404b673 js: set SameSite=Lax on cookies set by Javascript.
This is the new default for most browsers nowadays. Fixes a warning in
Firefox about using SameSite=None without the Secure flag.
2020-12-14 15:37:58 -06:00
evazion
0150911343 css: remove missing --dtext-expand-border-color var. 2020-12-14 14:29:31 -06:00
evazion
67eefadd7f users: let mods see email addresses on user profiles.
* Let Mods and Admins see the email addresses of users below their level.
* Let users see their own email address on their profile.
* Let users verify or edit their email address from their profile.

This is to make catching sockpuppets easier, and to make it easier for
users to fix their email.
2020-12-13 21:21:08 -06:00
evazion
b3ad13e6e3 users: add new owner level.
Add a new Owner user level for the site owner. Highly sensitive
operations like manually changing the passwords of other users will be
restricted to the site owner.
2020-12-13 21:18:24 -06:00
evazion
b002bf25f5 autocomplete: display autocorrected tags like aliases.
Display autocorrected tags similar to aliases, with an arrow pointing at
the corrected tag, but with a dotted underline beneath the misspelled
tag to indicate that it's misspelled.
2020-12-13 04:10:48 -06:00
evazion
adc1c2c2cc autocomplete: refactor javascript to use /autocomplete endpoint.
This refactors the autocomplete Javascript to use a single dedicated
/autocomplete.json endpoint instead of a bunch of separate endpoints.

This simplifies the autocomplete Javascript by making it so that instead
of calling a different endpoint for each type of query (for users, wiki
pages, pools, artists, etc), then having to parse the results of each
call to get the data we need, we can call a single endpoint that returns
exactly what we need.

This also means we don't have to parse searches clientside in order to
autocomplete metatags. Instead we can just pass the search term to the
server and let it parse the search, which is easy to do serverside.

Finally, this makes autocomplete easier to test, and it makes it easier
to add more sophisticated autocomplete behavior, since most of the logic
lives serverside.
2020-12-13 00:45:22 -06:00
Aaron Franke
191b528ad7 Ensure files end in newlines (POSIX compliance) 2020-10-04 05:13:39 -04:00
evazion
c295e233f2 Fix #4597: <code> blocks no longer render as monospace for notes. 2020-08-21 21:14:42 -05:00
evazion
fee68b6dd9 css: fix input box size in inline forms. 2020-08-18 11:08:02 -05:00
evazion
d98dd0bb6d ugoiras: don't initialize notes on ugoiras.
Fixes note font scaling increasing the size of the ugoira playback controls.
2020-08-18 11:06:19 -05:00
evazion
d072ef98ba css: don't use monospace font for textareas.
This changes the font in text input boxes (including the tag edit box)
from monospace to Verdana.
2020-08-16 15:17:40 -05:00
evazion
44cbce9855 css: factor out fonts to css variables. 2020-08-16 15:01:28 -05:00
evazion
317cfe19b4 flags: only show current flag on flagged posts.
* Only show the current pending flag on flagged posts. Don't show old flags.

* Don't show both the "This post was flagged for review" and the "This
  post was flagged and is pending" notices.
2020-08-16 14:31:47 -05:00
evazion
7eb9f0b75e appeals: only show current appeal on appealed posts.
* Only show the current pending appeal in the "This post was appealed"
  notice. Don't show old appeals.

* Don't show both the "This post was deleted" and the "This post was
  appealed" notice on appealed posts. Only show the "This post was
  appealed" notice.

* Show "no reason" if no appeal reason was given.
2020-08-16 14:31:47 -05:00
evazion
06564b25ca autocomplete: add status:appealed to autocomplete. 2020-08-12 22:40:17 -05:00
evazion
3d3b5262cc uploads: don't show translated commentary in tag edit dialog. 2020-08-12 11:02:11 -05:00
evazion
3a17b5a13e flags/appeals: replace is_resolved flag with statuses.
Replace references to the `is_resolved` field with the `status` field.
Post flags were marked as resolved when a post was approved (but not
when the post was deleted because it went unapproved). The status field
supercedes the resolved field.
2020-08-07 19:24:57 -05:00
evazion
afc07d8adf css: fix padding beneath buttons in dialog boxes.
Fix not having any space between the Submit / Cancel buttons and the
bottom of the dialog box. For some reason this only happens in
production, not development.
2020-08-07 10:35:13 -05:00
evazion
ad2ad295af Merge pull request #4560 from BrokenEagle/fix-tooltip-initialize
Fix tooltips to allow for reinitialization
2020-08-07 10:02:32 -05:00
evazion
56a4e58510 uploads: fix js error when resizing window.
Fix exception when resizing the window when the preview image isn't
present.
2020-08-05 12:28:24 -05:00
evazion
1a5cda44b9 css: tweak dialog box margins.
Tweak margins around dialog boxes to fix some poorly spaced elements,
especially around buttons and forms controls.
2020-08-05 12:28:24 -05:00
evazion
ef9bc37d9e posts: show ratings in tag edit dialog box.
* Show the rating buttons in the tag edit dialog box.
* Fix the tag counter not showing up in the tag edit dialog box on the
  uploads page.
2020-08-05 12:28:24 -05:00
evazion
605b4eff2a posts: adjust tag edit dialog width.
60% of window width was too large for widescreen monitors.
2020-08-05 12:19:30 -05:00
evazion
5aa7019cfe tag counter: fix clicking related tags not updating counter. 2020-08-03 23:18:11 -05:00
evazion
6b7cd7b972 posts: update tag counter icons. 2020-08-02 18:33:47 -05:00
evazion
b3a4c7aa43 posts: rewrite tag counter widget in React.
Rewrite the tag counter widget (the one above the tag edit box) to use
React. This is a trial run for using React elsewhere.

We actually use Preact instead of React because it's lighter weight.
We use Mobx for state management because it's cleaner than React's
setState or useState.

This incidentally fixes a couple bugs:

* The tag counter wasn't updated when deleting tags with backspace
* The tag counter wasn't updated when pasting in new tags.
2020-08-02 16:48:45 -05:00
evazion
baf0cf87af Fix #4571: Show banner when email verification is required.
* Show a banner if the user is restricted because they signed up from a
  proxy or VPN.

* Add an option to resend the confirmation email if your account has an
  unverified email address.
2020-08-02 16:48:45 -05:00
evazion
a8577b2b94 posts: remove data-* attributes from #image element.
These attributes can be found on the `.image-container` element instead.
2020-07-31 15:16:01 -05:00
evazion
3fe18c57d0 posts: always show "resized to X%" notice on mobile.
Always show the "Resized to X% of original" notice when viewing a sample
image on mobile.
2020-07-31 15:09:56 -05:00
evazion
1c6451b4c7 notes: don't show note bodies while dragging.
Bug: if you moused over another note while dragging a note, it would
trigger a note body popup. This would also happen when drawing out a new
note.

Also fix the drag box for new notes being drawn behind other notes.
2020-07-29 20:08:49 -05:00
evazion
2d002b3d5f notes: fix numerical instability in note positions.
Bug: loading and saving a note without moving it could change the note's
position. Moving a note with the keyboard could also cause unintended
changes to the note's size or position. This was because of floating
point errors when converting from percentage coordinates (floats) to pixel
coordinates (integers).

Fix: store note coordinates as pixel coordinates instead of as
percentage coordinates. Percentages are only used to position notes for
display.

Also fix it so you can resize rotated notes with the keyboard. This was
disabled before.
2020-07-29 19:35:27 -05:00
evazion
edbde657da notes: fix notes not being unselected on click.
Bug: clicking one note then clicking another note wouldn't unselect the
first note.
2020-07-29 16:07:27 -05:00
evazion
dcc869cb07 notes: raise notes on hover.
* Raise notes when hovering over them. This is so that when dragging
  embedded notes, they're not hidden behind other notes. Also so that if
  two notes are overlapping, you can hover over one to raise it over the
  other.

* Replace .hovering class with :hover selector.
2020-07-29 13:09:10 -05:00
evazion
0fbbc60a33 notes: show note bodies after dragging notes.
After dragging a note, show the note body again so you can see how it
looks.
2020-07-29 12:45:52 -05:00
evazion
dd7cd7c1c2 notes: hide note bodies while keyboard moving notes.
Bug: if you used they keyboard to move or resize a note, then the note
body would stay visible, which could get in the way when moving in the
down direction.
2020-07-29 10:13:14 -05:00
evazion
fd8a62ba5e notes: hide note bodies when resizing image.
Bug: if you're editing a note and click preview, then you resize the
image or press V to toggle the image size, then the note body will stay
on the screen in the wrong position.
2020-07-29 10:13:05 -05:00
evazion
5940a40a5a notes: hide note bodies when toggling notes.
Bug: if you clicked preview on a note to show the note body, then clicked
the image to hide the notes, then the note body wouldn't be hidden.
2020-07-29 10:12:51 -05:00
evazion
66ff9bd186 notes: don't mark note as unsaved when previewing.
Bug: previewing a note would mark the note as unsaved even if the note
hadn't been changed.

Fix: mark the note as unsaved when the user types something into the
note edit box, not when the note is previewed.
2020-07-29 10:12:27 -05:00
evazion
43bdb8db86 notes: allow ctrl+enter to save note.
Pressing Ctrl+Enter inside the note edit box will save the note.
2020-07-29 04:26:59 -05:00
evazion
fe557e7e85 notes: allow deleting new notes.
Allow new unsaved notes to be deleted. Before trying to delete a new
note did nothing.
2020-07-29 02:40:59 -05:00
evazion
2cbce9a525 notes: rewrite notes Javascript to object-oriented style.
Rewrite the notes Javascript from a procedural style to an
object-oriented style.

Before the notes Javascript had a lot of problems:

* There was hidden state everywhere, both locally and globally. We had
  state in global variables, in <meta> tags, in DOM data-* attributes
  (on multiple elements), and in jQuery .data() properties (which are
  different from data-* attributes, because they aren't visible in the
  DOM).

* Local state was hard to reason about. There was lots of direct DOM
  manipulation in random places. Functions had to constantly pass around
  note ids and look up elements in the DOM to get the state. State was
  invisible because it was stored as jQuery .data() properties. It was
  hard to follow where state was stored, how it was initialized, and how
  it changed.

* Global state was also a mess. There were a lot of global flags and
  variables only used in specific situations. Almost all of this state was
  unnecessary. Global state also prevented us from doing things like
  loading or unloading posts dynamically, or showing multiple posts with
  notes on the same page.

* There was a lot of duplication of code, especially for placing notes,
  and for loading or saving new notes versus saved notes.

Now the code is organized in an object-oriented fashion:

* The Note class represents a single note. A post has a list of notes,
  and each note object has a Note.Box and a Note.Body. Together these
  objects encapsulate the note's state.

* Notes have methods for doing things like placing note boxes, or showing
  and hiding note bodies, or creating, saving, or deleting notes. This
  makes the JS API cleaner.

* Global state is kept to a minimum.

This is one big patch because it was too hard to make these changes
incrementally. There are a couple minor bugfixes, but the actual
behavior of notes should remain unchanged.

Bugfixes:

* It was possible to enter translation mode, start dragging a new note,
  then press N to leave translation mode while still dragging the note.
  If you did this, then you would be stuck in translation mode and you
  couldn't stop dragging the note.

* Placement of new notes is now pixel-perfect. Before when placing a
  note, the note would shift by 1-2 pixels.

* Previewing an empty note didn't show the "Click to edit" message.

Other noteworthy changes:

* Most global state has been eliminated. There were a lot of flags and
  variables stored as global variables on `Danbooru.Note`. Most of these
  turned out to be either unnecessary or even unused.

* Notes now have an explicit minimum size of 10x10 pixels. Before this
  limit was hardcoded and undocumented.

* A lot of the note placement and note creation code has been simplified.

* `Note.add()` and `Note.create()` have been refactored into `new Note()`.
  Before `Note.add` was used to load an existing note, while `Note.create`
  was used to create a new note. These did the same thing, but had
  slightly different behavior.

* `Note.Box.scale()` and `Note.box.update_data_attributes` have been
  refactored into `Note.Box.place_note()`. Contrary to their names,
  these functions were actually both used to place notes.
2020-07-28 22:06:35 -05:00