discourse/discourse — pull request #1037 by ZogStriP (2013-06-17 01:23:54+00:00)
Title: Imagineering

:warning: This is a **large** PR :warning:

I've left some of the commits so it's easier to review/digest.

Brief overview of this PR:
- All the uploads are now identified using the SHA1 of their content. Thus reusing already uploaded files whenever needed.
- The `CookedPostProcessor` will now create thumbnails (information stored in the new `optimized_image` model)

Al the commits:
- [x] 6ea91b44169e275dbedd89bb281e2cd5d61e5f80 removes useless upload's `belongs_to :topic` association. This association is indeed no longer needed as an upload now belongs to *many* posts and thus *many* topics.
- [x] 6c4554b941bfb3a6de542fabbb854e727488ec51 make sure all uploads are identified with the `SHA1` of the uploaded content. This prevents users from uploading the same file twice.
- [x] f94e4ffdcb7c5cea78169a88fbf39d23633acb47 adds a `uploads:backfill_shas` rake task which can be used to backfill all the SHAs
- [x] 8a98310cf95d7d59e18856ef0360b48360e5c6c7 small refactoring to make sure we only do the work once
- [x] c11f4456ae8caeb40a03c5996c3db9e8412f4674 reorganizes & cleans up `CookedPostProcessor` a bit and improves the specs
- [x] 2c3f75795152b0a7f7781a3e215a446e09382a59 moves `has_been_uploaded?` and `uploaded_regex` to the `Upload` model (where they belongs)
- [x] 5de03814fb5620454e4489fc9bd48ce2ccff50fa creates the `optimized_image` model that is used to references all the optimized versions of an uploaded image
- [x] d4c3fe4e6a2cf7656bdd7c9590b38b2aaf8e5bfc adds the `create_thumbnails?` site setting (used as a feature flag for now. Once fully tested, we might want to remove it or at least changed its default value)
- [x] cc9e0ec80a86ddc539dd2b44d2c8c8a96ab9c8fe creates thumbnails using ImageSorcery (wrapper around ImageMagick) when a big image has been uploaded
- [x] 510bac4b27935a6ccd2516067e8391612cdabf19 refactors things a bit and *slightly* tested thumbnails creation.
- [x] 454636abf16644c523252eca163241a666b11b10 annotates the models