2017-03-02 22:53:21 -07:00
|
|
|
define(["filerepository","itemrepository","useractionrepository","transfermanager","cryptojs-md5"],function(filerepository,itemrepository,useractionrepository,transfermanager){"use strict";function getLocalItem(serverId,itemId){return itemrepository.get(serverId,itemId)}function recordUserAction(action){return action.Id=createGuid(),useractionrepository.set(action.Id,action)}function getUserActions(serverId){return useractionrepository.getByServerId(serverId)}function deleteUserAction(action){return useractionrepository.remove(action.Id)}function deleteUserActions(actions){var results=[];return actions.forEach(function(action){results.push(deleteUserAction(action))}),Promise.all(results)}function getServerItems(serverId){return itemrepository.getAll(serverId)}function getItemsFromIds(serverId,ids){var actions=ids.map(function(id){var strippedId=stripStart(id,"local:");return getLocalItem(serverId,strippedId)});return Promise.all(actions).then(function(items){var libItems=items.map(function(locItem){return locItem.Item});return Promise.resolve(libItems)})}function getViews(serverId,userId){return itemrepository.getServerItemTypes(serverId,userId).then(function(types){var item,list=[];return types.indexOf("audio")>-1&&(item={Name:"Music",ServerId:serverId,Id:"localview:MusicView",Type:"MusicView",CollectionType:"music",IsFolder:!0},list.push(item)),types.indexOf("photo")>-1&&(item={Name:"Photos",ServerId:serverId,Id:"localview:PhotosView",Type:"PhotosView",CollectionType:"photos",IsFolder:!0},list.push(item)),types.indexOf("episode")>-1&&(item={Name:"TV",ServerId:serverId,Id:"localview:TVView",Type:"TVView",CollectionType:"tvshows",IsFolder:!0},list.push(item)),types.indexOf("movie")>-1&&(item={Name:"Movies",ServerId:serverId,Id:"localview:MoviesView",Type:"MoviesView",CollectionType:"movies",IsFolder:!0},list.push(item)),types.indexOf("video")>-1&&(item={Name:"Videos",ServerId:serverId,Id:"localview:VideosView",Type:"VideosView",CollectionType:"videos",IsFolder:!0},list.push(item)),types.indexOf("musicvideo")>-1&&(item={Name:"Music Videos",ServerId:serverId,Id:"localview:MusicVideosView",Type:"MusicVideosView",CollectionType:"videos",IsFolder:!0},list.push(item)),Promise.resolve(list)})}function getTypeFilterForTopLevelView(parentId){var typeFilter=null;switch(parentId){case"localview:MusicView":typeFilter="audio";break;case"localview:PhotosView":typeFilter="photo";break;case"localview:TVView":typeFilter="episode";break;case"localview:VideosView":typeFilter="video";break;case"localview:MoviesView":typeFilter="movie";break;case"localview:MusicVideosView":typeFilter="musicvideo"}return typeFilter}function getViewItems(serverId,userId,options){var parentId=options.ParentId,typeFilterTop=getTypeFilterForTopLevelView(parentId),typeFilter=options.MediaType;return typeFilter||(typeFilter=typeFilterTop),parentId=stripStart(parentId,"localview:"),parentId=stripStart(parentId,"local:"),getServerItems(serverId).then(function(items){var resultItemIds=items.filter(function(item){if(item.SyncStatus&&"synced"!==item.SyncStatus)return!1;if(options.MediaType)return item.Item.MediaType===options.MediaType;if(typeFilter){var type=(item.Item.Type||"").toLowerCase();return typeFilter===type}return item.Item.ParentId===parentId}).map(function(item2){switch(typeFilterTop){case"audio":case"photo":return item2.Item.AlbumId;case"episode":return item2.Item.SeriesId}return item2.Item.Id}).filter(filterDistinct);if(options.Recursive){var resultItemIds2=items.filter(function(item){return(!item.SyncStatus||"synced"===item.SyncStatus)&&resultItemIds.indexOf(item.Item.ParentId)>=0}).map(function(item2){return item2.Item.Id});resultItemIds=resultItemIds.concat(resultItemIds2)}var resultItems=[];return items.forEach(function(item){"IsNotFolder"===options.Filters&&item.Item.IsFolder||("IsFolder"!==options.Filters||item.Item.IsFolder)&&resultItemIds.forEach(function(id){item.Item.Id===id&&resultItems.push(item.Item)})}),"DateCreated"===options.SortBy&&resultItems.sort(function(a,b){return compareDates(a.DateCreated,b.DateCreated)}),options.Limit&&(resultIte
|