Skip to content

Commit

Permalink
Merge pull request pepyatka#202 from FreeFeed/dsumin/opengraph_single…
Browse files Browse the repository at this point in the history
…thumbnail

Attachment image size fallback for posts-opengraph API
  • Loading branch information
indeyets authored Mar 6, 2017
2 parents 2e4ebfa + 3287014 commit c184834
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/controllers/api/v2/PostsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,22 @@ export default class PostsController {
if (attachments.length > 0) {
for (const item of attachments.map(serializeAttachment)) {
if (item.mediaType === 'image') {
image = item.imageSizes[`t2`].url;
image_h = item.imageSizes[`t2`].h;
image_w = item.imageSizes[`t2`].w;
let image_size;

// Image fallback: thumbnail 2 (t2) => thumbnail (t) => original (o) => none
if (`t2` in item.imageSizes) {
image_size = `t2`;
} else if (`t` in item.imageSizes) {
image_size = `t`;
} else if (`o` in item.imageSizes) {
image_size = `o`;
} else {
break;
}

image = item.imageSizes[image_size].url;
image_h = item.imageSizes[image_size].h;
image_w = item.imageSizes[image_size].w;
break;
}
}
Expand Down

0 comments on commit c184834

Please sign in to comment.