Skip to content

Commit e89be49

Browse files
authored
Merge pull request #235 from BuildFire/fix-missing-media-thumbnail
Fix missing media thumbnail
2 parents b7c38b7 + 0ddbc15 commit e89be49

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

control/content/controllers/content.home.controller.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@
290290
&& !ContentHome.info.data.content.updatedRecords) {
291291
ContentHome.updateRecords(ContentHome.info.data.content.sortBy);
292292
}
293+
// correct image src for dropbox to crop/resize and show it
294+
function getImageUrl(imageSrc) {
295+
if (imageSrc && imageSrc.includes("dropbox.com")) {
296+
imageSrc = imageSrc.replace("www.dropbox", "dl.dropboxusercontent").split("?dl=")[0];
297+
imageSrc = imageSrc.replace("dropbox.com", "dl.dropboxusercontent.com").split("?dl=")[0];
298+
}
299+
return imageSrc;
300+
}
293301

294302
/**
295303
* ContentHome.getMore is used to load the items
@@ -314,6 +322,12 @@
314322
ContentHome.noMore = false;
315323
}
316324

325+
result = result.map(item=>{
326+
item.data.topImage = getImageUrl(item.data.topImage);
327+
item.data.image = getImageUrl(item.data.image);
328+
return item;
329+
})
330+
317331
ContentHome.items = ContentHome.items ? ContentHome.items.concat(result) : result;
318332
ContentHome.isBusy = false;
319333
}, function fail() {

control/content/controllers/content.media.controller.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
* else init it with bootstrap data
123123
*/
124124
if (media) {
125+
media.data.topImage = getImageUrl(media.data.topImage);
126+
media.data.image = getImageUrl(media.data.image);
125127
ContentMedia.item = media;
126128
ContentMedia.dbItem = {
127129
id: media.id,
@@ -650,6 +652,8 @@
650652

651653
MediaContent.getById(data.id).then((item) => {
652654
registerAnalytics(item);
655+
item.data.topImage = getImageUrl(item.data.topImage);
656+
item.data.image = getImageUrl(item.data.image);
653657
ContentMedia.item = item;
654658
ContentMedia.item.data.deepLinkUrl = Buildfire.deeplink.createLink({ id: item.id });
655659
updateMasterItem(item);
@@ -833,8 +837,15 @@
833837
// $scope.$apply();
834838
// }
835839
//};
836-
837-
840+
841+
// correct image src for dropbox to crop/resize and show it
842+
function getImageUrl(imageSrc) {
843+
if (imageSrc && imageSrc.includes("dropbox.com")) {
844+
imageSrc = imageSrc.replace("www.dropbox", "dl.dropboxusercontent").split("?dl=")[0];
845+
imageSrc = imageSrc.replace("dropbox.com", "dl.dropboxusercontent.com").split("?dl=")[0];
846+
}
847+
return imageSrc;
848+
}
838849

839850
/* Build fire thumbnail component to add thumbnail image*/
840851
var audioImage = new Buildfire.components.images.thumbnail("#audioImage", {

widget/controllers/widget.home.controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,16 @@
952952
});
953953
};
954954

955+
// correct image src for dropbox to crop/resize and show it
956+
function getImageUrl(imageSrc) {
957+
if (imageSrc) {
958+
imageSrc = imageSrc.replace("www.dropbox", "dl.dropboxusercontent").split("?dl=")[0];
959+
imageSrc = imageSrc.replace("dropbox.com", "dl.dropboxusercontent.com").split("?dl=")[0];
960+
imageSrc = imageSrc.replace("dl.dropbox.com", "dl.dropboxusercontent.com");
961+
}
962+
return imageSrc;
963+
}
964+
955965
WidgetHome.loadMore = () => {
956966
updateGetOptions();
957967
const getRecords = () => {
@@ -962,6 +972,11 @@
962972
WidgetHome.currentlyLoading = true;
963973

964974
MediaContent.find(searchOptions).then((result) => {
975+
result = result.map(item=>{
976+
item.data.topImage = getImageUrl(item.data.topImage);
977+
item.data.image = getImageUrl(item.data.image);
978+
return item
979+
})
965980
WidgetHome.items = WidgetHome.items.concat(result);
966981
WidgetHome.items.forEach(item => {
967982
var searchOptions = {

widget/controllers/widget.media.controller.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@
336336
url: "./assets/css/videogular.css"
337337
}
338338
};
339+
// correct image src for dropbox to crop/resize and show it
340+
function getImageUrl(imageSrc) {
341+
if (imageSrc) {
342+
imageSrc = imageSrc.replace("www.dropbox", "dl.dropboxusercontent").split("?dl=")[0];
343+
imageSrc = imageSrc.replace("dropbox.com", "dl.dropboxusercontent.com").split("?dl=")[0];
344+
imageSrc = imageSrc.replace("dl.dropbox.com", "dl.dropboxusercontent.com");
345+
}
346+
return imageSrc;
347+
}
339348

340349
WidgetMedia.changeVideoSrc = function () {
341350
if (WidgetMedia.item.data.videoUrl) {
@@ -460,6 +469,8 @@
460469
//Check if item has newly downloaded media
461470
WidgetMedia.loadingData = true;
462471

472+
media.data.topImage = getImageUrl(media.data.topImage);
473+
media.data.image = getImageUrl(media.data.image);
463474
WidgetMedia.item = media;
464475
WidgetMedia.mediaType = media.data.audioUrl ? 'AUDIO' : (media.data.videoUrl ? 'VIDEO' : null);
465476
Buildfire.auth.getCurrentUser((err, user) => {
@@ -603,6 +614,8 @@
603614
switch (event.tag) {
604615
case COLLECTIONS.MediaContent:
605616
if (event.data) {
617+
event.data.topImage = getImageUrl(event.data.topImage);
618+
event.data.image = getImageUrl(event.data.image);
606619
WidgetMedia.item = event;
607620
$scope.$digest();
608621
// Update item in globalPlaylist

widget/controllers/widget.nowplaying.controller.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
NowPlaying.forceAutoPlay = $rootScope.forceAutoPlay;
1313
NowPlaying.transferPlaylist = $rootScope.transferAudioContentToPlayList;
1414
media.data.audioUrl = convertDropbox(media.data.audioUrl);
15+
media.data.topImage = convertDropbox(media.data.topImage);
16+
media.data.image = convertDropbox(media.data.image);
1517

1618
NowPlaying.currentTime = 0;
1719

@@ -133,7 +135,12 @@
133135
}).join('');
134136

135137
var pluginSongs = result.filter(el => el.data.audioUrl && el.data.audioUrl.length > 0);
136-
var pluginListSongs = pluginSongs.map(el => { el.data.audioUrl = convertDropbox(el.data.audioUrl); return el.data.audioUrl; }).join('');
138+
var pluginListSongs = pluginSongs.map(el => {
139+
el.data.audioUrl = convertDropbox(el.data.audioUrl);
140+
el.data.topImage = convertDropbox(el.data.topImage);
141+
el.data.image = convertDropbox(el.data.image);
142+
return el.data.audioUrl;
143+
}).join('');
137144
var pluginListTitles = pluginSongs.map(el => { return el.data.title; }).join('');
138145

139146
var pluginListBackground = pluginSongs.map(el => {

0 commit comments

Comments
 (0)