jellyfin-web/dashboard-ui/bower_components/emby-apiclient/apiclientex.js

1 line
10 KiB
JavaScript
Raw Normal View History

2017-03-01 13:29:42 -07:00
define(["apiclientcore","localassetmanager","events","appStorage"],function(apiclientcorefactory,localassetmanager,events,appStorage){"use strict";var localPrefix="local:",localViewPrefix="localview:";return function(serverAddress,clientName,applicationVersion,deviceName,deviceId,devicePixelRatio){function getCurrentUser(){return apiclientcore.getCurrentUser().then(function(user){return appStorage.setItem("user-"+user.Id,JSON.stringify(user)),user},function(error){var userId=apiclientcore.getCurrentUserId();if(userId&&apiclientcore.accessToken()){var json=appStorage.getItem("user-"+userId);if(json)return Promise.resolve(JSON.parse(json))}return Promise.reject(error)})}function getUserViews(userId){return apiclientcore.getUserViews(userId).then(function(result){var serverInfo=apiclientcore.serverInfo();return serverInfo?getLocalView(serverInfo.Id,userId).then(function(localView){return localView&&(result.Items.push(localView),result.TotalRecordCount++),Promise.resolve(result)}):Promise.resolve(result)})}function getLocalView(serverId,userId){return getLocalFolders(serverId,userId).then(function(views){var localView=null;return views.length>0&&(localView={Name:"Offline Items",ServerId:serverId,Id:"localview",Type:"localview"}),Promise.resolve(localView)})}function getLocalFolders(userId){var serverInfo=apiclientcore.serverInfo();return userId=userId||serverInfo.UserId,localassetmanager.getViews(serverInfo.Id,userId)}function getItems(userId,options){var i,serverInfo=apiclientcore.serverInfo();if(serverInfo&&"localview"===options.ParentId)return getLocalFolders(serverInfo.Id,userId).then(function(items){var result={Items:items,TotalRecordCount:items.length};return Promise.resolve(result)});if(serverInfo&&options&&(isLocalId(options.ParentId)||isLocalViewId(options.ParentId)))return localassetmanager.getViewItems(serverInfo.Id,userId,options).then(function(items){items.forEach(function(item){adjustGuidProperties(item)}),items.sort(function(a,b){return a.SortName.toLowerCase().localeCompare(b.SortName.toLowerCase())});var result={Items:items,TotalRecordCount:items.length};return Promise.resolve(result)});if(options&&options.ExcludeItemIds&&options.ExcludeItemIds.length){var exItems=options.ExcludeItemIds.split(",");for(i=0;i<exItems.length;i++)if(isLocalId(exItems[i]))return Promise.resolve(createEmptyList())}else if(options&&options.Ids&&options.Ids.length){var ids=options.Ids.split(","),hasLocal=!1;for(i=0;i<ids.length;i++)isLocalId(ids[i])&&(hasLocal=!0);if(hasLocal)return localassetmanager.getItemsFromIds(serverInfo.Id,ids).then(function(items){items.forEach(function(item){adjustGuidProperties(item)});var result={Items:items,TotalRecordCount:items.length};return Promise.resolve(result)})}return apiclientcore.getItems(userId,options)}function getItem(userId,itemId){itemId&&(itemId=itemId.toString());var serverInfo;return isLocalViewId(itemId)&&(serverInfo=apiclientcore.serverInfo())?getLocalFolders(serverInfo.Id,userId).then(function(items){var views=items.filter(function(item){return item.Id===itemId});return views.length>0?Promise.resolve(views[0]):Promise.reject()}):isLocalId(itemId)&&(serverInfo=apiclientcore.serverInfo())?localassetmanager.getLocalItem(serverInfo.Id,stripLocalPrefix(itemId)).then(function(item){return adjustGuidProperties(item.Item),Promise.resolve(item.Item)}):apiclientcore.getItem(userId,itemId)}function adjustGuidProperties(downloadedItem){downloadedItem.Id=convertGuidToLocal(downloadedItem.Id),downloadedItem.SeriesId=convertGuidToLocal(downloadedItem.SeriesId),downloadedItem.SeasonId=convertGuidToLocal(downloadedItem.SeasonId),downloadedItem.AlbumId=convertGuidToLocal(downloadedItem.AlbumId),downloadedItem.ParentId=convertGuidToLocal(downloadedItem.ParentId),downloadedItem.ParentThumbItemId=convertGuidToLocal(downloadedItem.ParentThumbItemId),downloadedItem.ParentPrimaryImageItemId=convertGuidToLocal(downloadedItem.ParentPrimaryImageItemId),downloadedItem.PrimaryImageItemId=convertGuidToLocal(downloadedItem.PrimaryImageItemId),downloadedItem.ParentLogoItemId=convertGuidToLocal(downloadedItem.Pare