Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return media attachment dimensions #1985

Closed
1 task done
siuying opened this issue Apr 17, 2017 · 6 comments
Closed
1 task done

Return media attachment dimensions #1985

siuying opened this issue Apr 17, 2017 · 6 comments
Labels
api REST API, Streaming API, Web Push API

Comments

@siuying
Copy link
Contributor

siuying commented Apr 17, 2017

MediaAttachment currently do not return dimension of the image/video. This prevent the view from properly sized the placeholder.

If the api optionally return media dimension, we can make the client render the preview at proper size:

Tweetbot for Mac


  • I searched or browsed the repo’s other issues to ensure this is not a duplicate.
@wxcafe wxcafe added api REST API, Streaming API, Web Push API enhancement labels Apr 17, 2017
@wxcafe wxcafe changed the title Returns media attachment dimensions Return media attachment dimensions Apr 17, 2017
@ashfurrow
Copy link
Contributor

Did some brief research into this, Paperclip has a companion gem for storing the asset dimensions in a database column: https://github.com/teeparham/paperclip-meta Beyond a basic db migration, it looks like it would require "rebuilding thumbnails", and I'm not sure what's involved in that.

@siuying
Copy link
Contributor Author

siuying commented Apr 25, 2017

The dimension field can be optional, then we don't need to worry about rebuilding thumbnails -- a rebuild task can be added later if someone really want all media have dimensions.

@ashfurrow
Copy link
Contributor

Tried for a while to get this, but it's beyond my abilities at the moment. If someone else could take a look, that'd be 💯

@siuying
Copy link
Contributor Author

siuying commented Apr 25, 2017

I'm looking into it!

siuying added a commit to siuying/mastodon.hk that referenced this issue Apr 25, 2017
- add migration AddMediaAttachmentMeta, which add meta field to media_attachments
- before saving attachment, set file meta if needed
- add meta in api
@siuying
Copy link
Contributor Author

siuying commented Apr 25, 2017

Tried to add paperclip-meta, but it conflicts with paperclip-av-transcoder. I don't really want to monkey patch it, so I write some custom code to do that instead.

  1. Add a field file_meta to MediaAttachment
  2. For images, find the meta data using Paperclip::Geometry
  3. For video, paperclip-av-transcoder will set the meta data
  4. Render meta field in _media.rabl

Note:

file_meta is json type, which require newer postgresql (9.4)

Result is something like:

 [
   {
      "media_attachments" : [
         {
            "id" : 4,
            "type" : "image",
            "remote_url" : "",
            "meta" : {
               "original" : {
                  "width" : 600,
                  "size" : "600x400",
                  "height" : 400,
                  "aspect" : 1.5
               },
               "small" : {
                  "aspect" : 1.49812734082397,
                  "height" : 267,
                  "size" : "400x267",
                  "width" : 400
               }
            },
            "url" : "http://127.0.0.1:3000/system/media_attachments/files/000/000/004/original/3416fc5188c656da.jpg?1493138517",
            "preview_url" : "http://127.0.0.1:3000/system/media_attachments/files/000/000/004/small/3416fc5188c656da.jpg?1493138517",
            "text_url" : "http://127.0.0.1:3000/media/4hfW3Kt4U9UxDvV_xug"
         },
         {
            "text_url" : "http://127.0.0.1:3000/media/0vTH_B1kjvIvlUBhGBw",
            "preview_url" : "http://127.0.0.1:3000/system/media_attachments/files/000/000/003/small/23519a5e64064e32.png?1493138030",
            "meta" : {
               "fps" : 15,
               "duration" : 5.06,
               "width" : 320,
               "size" : "320x180",
               "height" : 180,
               "length" : "0:00:05.06",
               "aspect" : 1.77777777777778
            },
            "url" : "http://127.0.0.1:3000/system/media_attachments/files/000/000/003/original/23519a5e64064e32.mp4?1493138030",
            "remote_url" : "",
            "type" : "gifv",
            "id" : 3
         }
      ],
   }
]

@ashfurrow
Copy link
Contributor

Nice work @siuying !

seefood pushed a commit to Toootim/mastodon that referenced this issue Apr 26, 2017
* Fixes mastodon#1985

- add migration AddMediaAttachmentMeta, which add meta field to media_attachments
- before saving attachment, set file meta if needed
- add meta in api

* add spec

* align the “size” format for image and video

* fix code climate

* fixes media_attachment_spec.rb
seefood pushed a commit to Toootim/mastodon that referenced this issue Apr 28, 2017
* Fixes mastodon#1985

- add migration AddMediaAttachmentMeta, which add meta field to media_attachments
- before saving attachment, set file meta if needed
- add meta in api

* add spec

* align the “size” format for image and video

* fix code climate

* fixes media_attachment_spec.rb
nanos pushed a commit to nanos/mastodon that referenced this issue Dec 23, 2022
* Wraps status timestamps in a `div`

Fixes mastodon#1985

This wraps the status timestamp in a `div` to reduce the clickable
target size of the link. The `div` gets a `margin: 0 0 0 auto` to stick
it to the right margin of the status.

* Update app/javascript/flavours/glitch/styles/components/status.scss

Co-authored-by: Claire <claire.github-309c@sitedethib.com>

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api REST API, Streaming API, Web Push API
Projects
None yet
Development

No branches or pull requests

3 participants