Commit Graph

31 Commits

Author SHA1 Message Date
evazion
570d6a9d01 storage manager: close file after copying it. 2022-11-20 23:13:57 -06:00
evazion
ac98c142a4 posts: move expunged image to trash folder.
When a post is expunged, move the image to a trash folder so it can be
recovered if needed.
2022-05-03 05:51:09 -05:00
evazion
e7744cb6e3 uploads: generate thumbnails in parallel.
Make uploads faster by generating and saving thumbnails in parallel.

We generate each thumbnail in parallel, then send each thumbnail to the
backend image servers in parallel.

Most images have 5 variants: 'preview' (150x150), 180x180, 360x360,
720x720, and 'sample' (850px width). Plus the original file, that's 6
files we have to save. In production we have 2 image servers, so we have
to save each file twice, to 2 remote servers. Doing all this in parallel
should make uploads significantly faster.
2022-02-04 16:20:50 -06:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
6fc0854b4c Remove StorageManager::SFTP.
Remove the SFTP file storage backend. Downstream users can use either
sshfs (which is what Danbooru now uses in production) or rclone instead.
The Ruby SFTP gem was much slower than sshfs.
2021-12-01 23:46:20 -06:00
evazion
f593828bb9 storage manager: refactor base_dir option.
Fix it so the `base_dir` option is only required by subclasses that
actually use it. The StorageManager::Mirror class doesn't use it.
2021-10-29 07:14:21 -05:00
evazion
4095d14f2a media assets: fix tagged filenames option.
Fix the `enable_seo_post_urls` config option not being respected. This
option controls whether filenames in image URLs contain the tags. This
option requires URLs rewrites in Nginx to work so it's disabled by
default.
2021-10-29 07:14:21 -05:00
evazion
1614b301e3 storage managers: add mirror storage manager.
Add a storage manager that allows mirroring files to multiple storage
backends.
2021-10-29 07:14:21 -05:00
evazion
082544ab03 StorageManager: remove Post-specific code.
Refactor StorageManager to remove all image URL generation code. Instead
the image URL generation code lives in MediaAsset.

Now StorageManager is only concerned with how to read and write files to
remote storage backends like S3 or SFTP, not with how image URLs should
be generated. This way the file storage code isn't tightly coupled to
posts, so it can be used to store any kind of file, not just images
belonging to posts.
2021-10-27 00:05:30 -05:00
evazion
1d034a3223 media assets: move more file-handling logic into MediaAsset.
Move more of the file-handling logic from UploadService and
StorageManager into MediaAsset. This is part of refactoring posts and
uploads to allow multiple images per post.
2021-10-18 00:10:29 -05:00
evazion
00ca7526bb docs: add remaining docs for classes in app/logical. 2021-06-24 01:31:41 -05:00
evazion
29d2e7fed2 storage manager: remove hierarchical option.
Remove the `hierarchical` file storage option. This means that image
files are always stored in MD5-based subdirectories, like this:

   https://danbooru.donmai.us/data/original/f3/a7/f3a70a89c350b5ed4db22dbb25b934bb.jpg
   https://danbooru.donmai.us/data/sample/f3/a7/sample-f3a70a89c350b5ed4db22dbb25b934bb.jpg
   https://danbooru.donmai.us/data/preview/f3/a7/f3a70a89c350b5ed4db22dbb25b934bb.jpg

instead of in a single flat directory, like this:

   https://danbooru.donmai.us/data/original/f3a70a89c350b5ed4db22dbb25b934bb.jpg

This option is removed because storing files in a single directory is a
bad idea for large installations, and migrating from a single directory
to subdirectories later is a pain.

Downstream boorus who still have files in the old layout can migrate by
running this script:

   `./script/fixes/077_symlink_subdirectories.rb`

This will create symlinks that redirect the 00-ff subdirectories back to
the current directory, so that you can still store files in a single
directory, but use URLs containing subdirectories.

You should also make sure to remove the `hierarchical` option from
`storage_manager` in `config/danbooru_local_config.rb` if you set it
there.
2021-03-18 01:33:56 -05:00
evazion
a620a71b59 storage manager: remove original_subdir option.
Always store original files in `public/data/original` instead of directly in
`public/data`. Previously this was optional and defaulted to off.

Downstream boorus will need to either move all images in the
`public/data` directory to `public/data/original`, or symlink the
`public/data/original` directory to the toplevel `public/data` directory:

    ln -s . /path/to/danbooru/public/data/original

This to simplify file layout. This option existed because in the past we
stored original files in different locations on different servers (for
no particular reason).
2021-03-16 23:37:07 -05:00
evazion
0f90ae0fed storage manager: use canonical URL for image URLs.
Generate image URLs relative to the site's canonical URL instead of
relative to the domain of the current request.

This means that all subdomains of Danbooru - safebooru.donmai.us,
shima.donmai.us, saitou.donmai.us, and kagamihara.donmai.us - will use
image URLs from https://danbooru.donmai.us, instead of from the current
domain.

The main reason we did this before was so that we could generate either
http:// or https:// image URLs, depending on whether the current request
was HTTP or HTTPS, back when we tried to support both at the same time.
Now we support only HTTPS in production, so there's no need for this. It
was also pretty hacky, since it required storing the URL of the current
request in a per-request global variable in `CurrentUser`.

This also improves caching slightly, since users of safebooru.donmai.us
will receive cached images from danbooru.donmai.us.

Downstream boorus should make sure that the `canonical_url` and
`storage_manager` config options are set correctly. If you don't support
https:// in development, you should make sure to set the canonical_url
option to http:// instead of https://.
2021-03-16 23:30:29 -05:00
evazion
15799f8af7 Fix #4260: Unable to replace cdn.donmai.us images?
Bug: Replacing posts hosted on cdn.donmai.us didn't work.

Cause: Original files on cdn.donmai.us are hosted under /var/www/danbooru/original/, but replacements
were trying to store them directly under /var/www/danbooru, which failed with a permission error.
We were trying to store them in the wrong directory because we didn't respect the `original_subdir`
option when generating file paths.
2020-06-09 15:57:43 -05:00
evazion
bab656a873 config: remove more obsolete or unneeded config options.
Remove more config options that were either unused or that shouldn't
need to be configured by downstream users.
2020-01-11 01:31:29 -06:00
evazion
c0171f49a6 storage manager: add option for storing files under original/ dir.
Add option to allow for storing original files under an `original/`
subdir. Previously preview, crop, and sample files were stored under
subdirs but original files were stored in the top-level directory. This
is optional for backwards compatibility.
2020-01-01 13:46:05 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
88a177e1d5 TagSetPresenter: refactor humanized_essential_tag_string.
Move Post#humanized_essential_tag_string to TagSetPresenter#humanized_essential_tag_string.

This allows humanized_essential_tag_string to reuse the same set of tags
already fetched by the tag set presenter for the sidebar.

This avoids fetching the tag categories from memcache again (via
Post#typed_tags) when we're already fetched the tags once before.

This also means it's no longer necessary to cache humanized_essential_tag_string
itself in memcache, since it can be generated as quickly as the sidebar taglist.
2018-09-30 21:52:24 -05:00
Albert Yi
0314dc9751 more consistent behavior of CurrentUser.root_url 2018-08-15 16:08:10 -07:00
Albert Yi
ea210bdc75 Add matching storage manager 2018-07-12 17:15:41 -07:00
Albert Yi
64446d49e1 add image cropping support 2018-06-22 14:41:57 -07:00
Albert Yi
03e2a2ca3b add rake task for distributing images using storage managers 2018-04-12 10:40:24 -07:00
Albert Yi
23fef71346 Merge pull request #3609 from evazion/fix-3603
Fix #3603: Unable to view images on Hijiribe/Sonohara when Danbooru is blocked
2018-04-09 10:56:00 -07:00
evazion
2cbec785ea Fix #3613: Broken preview images for flash files. 2018-04-08 11:49:30 -05:00
evazion
1b14545d0d Fix #3603: Unable to view images on Hijiribe/Sonohara when Danbooru domain is blocked. 2018-04-06 21:25:14 -05:00
evazion
084fcd91ed Only generate tagged filenames for URLs on post show pages (#3597).
Don't generate tagged filenames for urls in the data attributes on
thumbnails, or in the /posts.json api.
2018-04-05 14:20:37 -05:00
Albert Yi
18dd47c557 Merge branch 'master' of github.com:r888888888/danbooru 2018-03-28 17:19:35 -07:00
Albert Yi
929b2fa896 move default base url to method to deal with deployment issues 2018-03-28 17:19:21 -07:00
evazion
be0c2cfcfa posts: fix incorrect large_file_url for animated_gifs.
For animated_gif posts, large_file_url was returning
"/data/sample-$md5.jpg" instead of "/data/$md5.gif".
2018-03-28 19:17:15 -05:00
evazion
b0c7d9c185 Add storage managers (local, sftp, s3, hybrid). 2018-03-20 19:49:06 -05:00