1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
This commit is contained in:
Luke Pulverenti 2017-01-27 18:07:14 -05:00
parent 82bcca376f
commit 8a6884abef
494 changed files with 256 additions and 120180 deletions

View file

@ -1,29 +0,0 @@
{
"name": "emby-apiclient",
"main": "apiclient.js",
"authors": [
"The Emby Authors"
],
"repository": {
"type": "git",
"url": "git://github.com/MediaBrowser/Emby.ApiClient.Javascript.git"
},
"license": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/LICENSE",
"homepage": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript",
"dependencies": {
"cryptojslib": "cryptojslib#^3.1.2",
"requirejs": "requirejs#^2.1.22"
},
"devDependencies": {},
"ignore": [],
"version": "1.1.125",
"_release": "1.1.125",
"_resolution": {
"type": "version",
"tag": "1.1.125",
"commit": "de914c8db94b994ea45746626ba73bfb72a594a0"
},
"_source": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
"_target": "^1.1.51",
"_originalSource": "emby-apiclient"
}

View file

@ -1,22 +0,0 @@
The MIT License
Copyright (c) Emby https://emby.media
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,48 +1 @@
define([], function () {
'use strict';
var myStore = {};
var cache;
var localData;
function updateCache() {
cache.put('data', new Response(JSON.stringify(localData)));
}
myStore.setItem = function (name, value) {
if (localData) {
var changed = localData[name] !== value;
if (changed) {
localData[name] = value;
updateCache();
}
}
};
myStore.getItem = function (name) {
if (localData) {
return localData[name];
}
};
myStore.removeItem = function (name) {
if (localData) {
localData[name] = null;
delete localData[name];
updateCache();
}
};
myStore.init = function () {
return caches.open('embydata').then(function (result) {
cache = result;
localData = {};
});
};
return myStore;
});
define([],function(){"use strict";function updateCache(){cache.put("data",new Response(JSON.stringify(localData)))}var cache,localData,myStore={};return myStore.setItem=function(name,value){if(localData){var changed=localData[name]!==value;changed&&(localData[name]=value,updateCache())}},myStore.getItem=function(name){if(localData)return localData[name]},myStore.removeItem=function(name){localData&&(localData[name]=null,delete localData[name],updateCache())},myStore.init=function(){return caches.open("embydata").then(function(result){cache=result,localData={}})},myStore});

View file

@ -1,57 +1 @@
define([], function () {
'use strict';
var myStore = {};
var cache;
var localData;
function updateCache() {
if (cache) {
cache.put('data', new Response(JSON.stringify(localData)));
}
}
myStore.setItem = function (name, value) {
localStorage.setItem(name, value);
if (localData) {
var changed = localData[name] !== value;
if (changed) {
localData[name] = value;
updateCache();
}
}
};
myStore.getItem = function (name) {
return localStorage.getItem(name);
};
myStore.removeItem = function (name) {
localStorage.removeItem(name);
if (localData) {
localData[name] = null;
delete localData[name];
updateCache();
}
};
try {
if (self.caches) {
caches.open('embydata').then(function (result) {
cache = result;
localData = {};
});
}
} catch (err) {
console.log('Error opening cache: ' + err);
}
return myStore;
});
define([],function(){"use strict";function updateCache(){cache&&cache.put("data",new Response(JSON.stringify(localData)))}var cache,localData,myStore={};myStore.setItem=function(name,value){if(localStorage.setItem(name,value),localData){var changed=localData[name]!==value;changed&&(localData[name]=value,updateCache())}},myStore.getItem=function(name){return localStorage.getItem(name)},myStore.removeItem=function(name){localStorage.removeItem(name),localData&&(localData[name]=null,delete localData[name],updateCache())};try{self.caches&&caches.open("embydata").then(function(result){cache=result,localData={}})}catch(err){console.log("Error opening cache: "+err)}return myStore});

View file

@ -1,22 +1 @@
define([], function () {
'use strict';
function MyStore(defaultObject) {
this.localData = {};
}
MyStore.prototype.setItem = function (name, value) {
this.localData[name] = value;
};
MyStore.prototype.getItem = function (name) {
return this.localData[name];
};
MyStore.prototype.removeItem = function (name) {
this.localData[name] = null;
};
return new MyStore();
});
define([],function(){"use strict";function MyStore(defaultObject){this.localData={}}return MyStore.prototype.setItem=function(name,value){this.localData[name]=value},MyStore.prototype.getItem=function(name){return this.localData[name]},MyStore.prototype.removeItem=function(name){this.localData[name]=null},new MyStore});

View file

@ -1,21 +0,0 @@
{
"name": "emby-apiclient",
"main": "apiclient.js",
"authors": [
"The Emby Authors"
],
"repository": {
"type": "git",
"url": "git://github.com/MediaBrowser/Emby.ApiClient.Javascript.git"
},
"license": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/LICENSE",
"homepage": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript",
"dependencies": {
"cryptojslib": "cryptojslib#^3.1.2",
"requirejs": "requirejs#^2.1.22"
},
"devDependencies": {
},
"ignore": []
}

View file

@ -1,15 +1 @@
define([], function () {
'use strict';
function CameraRoll() {
}
CameraRoll.prototype.getFiles = function () {
return Promise.resolve([]);
};
return new CameraRoll();
});
define([],function(){"use strict";function CameraRoll(){}return CameraRoll.prototype.getFiles=function(){return Promise.resolve([])},new CameraRoll});

File diff suppressed because one or more lines are too long

View file

@ -1,126 +1 @@
define(['events', 'appStorage'], function (events, appStorage) {
'use strict';
return function (key) {
var self = this;
var credentials = null;
key = key || 'servercredentials3';
function ensure() {
if (!credentials) {
var json = appStorage.getItem(key) || '{}';
console.log('credentials initialized with: ' + json);
credentials = JSON.parse(json);
credentials.Servers = credentials.Servers || [];
}
}
function get() {
ensure();
return credentials;
}
function set(data) {
if (data) {
credentials = data;
appStorage.setItem(key, JSON.stringify(data));
} else {
self.clear();
}
events.trigger(self, 'credentialsupdated');
}
self.clear = function () {
credentials = null;
appStorage.removeItem(key);
};
self.credentials = function (data) {
if (data) {
set(data);
}
return get();
};
self.addOrUpdateServer = function (list, server) {
if (!server.Id) {
throw new Error('Server.Id cannot be null or empty');
}
var existing = list.filter(function (s) {
return s.Id === server.Id;
})[0];
if (existing) {
// Merge the data
existing.DateLastAccessed = Math.max(existing.DateLastAccessed || 0, server.DateLastAccessed || 0);
existing.UserLinkType = server.UserLinkType;
if (server.AccessToken) {
existing.AccessToken = server.AccessToken;
existing.UserId = server.UserId;
}
if (server.ExchangeToken) {
existing.ExchangeToken = server.ExchangeToken;
}
if (server.RemoteAddress) {
existing.RemoteAddress = server.RemoteAddress;
}
if (server.ManualAddress) {
existing.ManualAddress = server.ManualAddress;
}
if (server.LocalAddress) {
existing.LocalAddress = server.LocalAddress;
}
if (server.Name) {
existing.Name = server.Name;
}
if (server.WakeOnLanInfos && server.WakeOnLanInfos.length) {
existing.WakeOnLanInfos = server.WakeOnLanInfos;
}
if (server.LastConnectionMode != null) {
existing.LastConnectionMode = server.LastConnectionMode;
}
if (server.ConnectServerId) {
existing.ConnectServerId = server.ConnectServerId;
}
return existing;
}
else {
list.push(server);
return server;
}
};
self.addOrUpdateUser = function (server, user) {
server.Users = server.Users || [];
var existing = server.Users.filter(function (s) {
return s.Id === user.Id;
})[0];
if (existing) {
// Merge the data
existing.IsSignedInOffline = true;
}
else {
server.Users.push(user);
}
};
};
});
define(["events","appStorage"],function(events,appStorage){"use strict";return function(key){function ensure(){if(!credentials){var json=appStorage.getItem(key)||"{}";console.log("credentials initialized with: "+json),credentials=JSON.parse(json),credentials.Servers=credentials.Servers||[]}}function get(){return ensure(),credentials}function set(data){data?(credentials=data,appStorage.setItem(key,JSON.stringify(data))):self.clear(),events.trigger(self,"credentialsupdated")}var self=this,credentials=null;key=key||"servercredentials3",self.clear=function(){credentials=null,appStorage.removeItem(key)},self.credentials=function(data){return data&&set(data),get()},self.addOrUpdateServer=function(list,server){if(!server.Id)throw new Error("Server.Id cannot be null or empty");var existing=list.filter(function(s){return s.Id===server.Id})[0];return existing?(existing.DateLastAccessed=Math.max(existing.DateLastAccessed||0,server.DateLastAccessed||0),existing.UserLinkType=server.UserLinkType,server.AccessToken&&(existing.AccessToken=server.AccessToken,existing.UserId=server.UserId),server.ExchangeToken&&(existing.ExchangeToken=server.ExchangeToken),server.RemoteAddress&&(existing.RemoteAddress=server.RemoteAddress),server.ManualAddress&&(existing.ManualAddress=server.ManualAddress),server.LocalAddress&&(existing.LocalAddress=server.LocalAddress),server.Name&&(existing.Name=server.Name),server.WakeOnLanInfos&&server.WakeOnLanInfos.length&&(existing.WakeOnLanInfos=server.WakeOnLanInfos),null!=server.LastConnectionMode&&(existing.LastConnectionMode=server.LastConnectionMode),server.ConnectServerId&&(existing.ConnectServerId=server.ConnectServerId),existing):(list.push(server),server)},self.addOrUpdateUser=function(server,user){server.Users=server.Users||[];var existing=server.Users.filter(function(s){return s.Id===user.Id})[0];existing?existing.IsSignedInOffline=!0:server.Users.push(user)}}});

View file

@ -1,62 +1 @@
define([], function () {
'use strict';
function getCallbacks(obj, name) {
if (!obj) {
throw new Error("obj cannot be null!");
}
obj._callbacks = obj._callbacks || {};
var list = obj._callbacks[name];
if (!list) {
obj._callbacks[name] = [];
list = obj._callbacks[name];
}
return list;
}
return {
on: function (obj, eventName, fn) {
var list = getCallbacks(obj, eventName);
list.push(fn);
},
off: function (obj, eventName, fn) {
var list = getCallbacks(obj, eventName);
var i = list.indexOf(fn);
if (i !== -1) {
list.splice(i, 1);
}
},
trigger: function (obj, eventName) {
var eventObject = {
type: eventName
};
var eventArgs = [];
eventArgs.push(eventObject);
var additionalArgs = arguments[2] || [];
for (var i = 0, length = additionalArgs.length; i < length; i++) {
eventArgs.push(additionalArgs[i]);
}
var callbacks = getCallbacks(obj, eventName).slice(0);
callbacks.forEach(function (c) {
c.apply(obj, eventArgs);
});
}
};
});
define([],function(){"use strict";function getCallbacks(obj,name){if(!obj)throw new Error("obj cannot be null!");obj._callbacks=obj._callbacks||{};var list=obj._callbacks[name];return list||(obj._callbacks[name]=[],list=obj._callbacks[name]),list}return{on:function(obj,eventName,fn){var list=getCallbacks(obj,eventName);list.push(fn)},off:function(obj,eventName,fn){var list=getCallbacks(obj,eventName),i=list.indexOf(fn);i!==-1&&list.splice(i,1)},trigger:function(obj,eventName){var eventObject={type:eventName},eventArgs=[];eventArgs.push(eventObject);for(var additionalArgs=arguments[2]||[],i=0,length=additionalArgs.length;i<length;i++)eventArgs.push(additionalArgs[i]);var callbacks=getCallbacks(obj,eventName).slice(0);callbacks.forEach(function(c){c.apply(obj,eventArgs)})}}});

View file

@ -1,13 +1 @@
define([], function () {
'use strict';
return function () {
var self = this;
self.upload = function (file, name, url) {
return Promise.reject();
};
};
});
define([],function(){"use strict";return function(){var self=this;self.upload=function(file,name,url){return Promise.reject()}}});

File diff suppressed because one or more lines are too long

View file

@ -1,132 +1 @@
define([], function () {
'use strict';
function getLocalItem(serverId, itemId) {
return Promise.resolve();
}
function getLocalItemById(id) {
return Promise.resolve();
}
function saveOfflineUser(user) {
return Promise.resolve();
}
function deleteOfflineUser(id) {
return Promise.resolve();
}
function recordUserAction(action) {
return Promise.resolve();
}
function getUserActions(serverId) {
return Promise.resolve([]);
}
function deleteUserAction(action) {
return Promise.resolve();
}
function deleteUserActions(actions) {
return Promise.resolve();
}
function getServerItemIds(serverId) {
return Promise.resolve([]);
}
function getServerItems(serverId) {
return Promise.resolve([]);
}
function getViews(serverId, userId) {
return Promise.resolve([]);
}
function getViewItems(serverId, userId, parentId) {
return Promise.resolve([]);
}
function removeLocalItem(localItem) {
return Promise.resolve();
}
function addOrUpdateLocalItem(localItem) {
return Promise.resolve();
}
function createLocalItem(libraryItem, serverInfo, jobItem) {
return Promise.resolve();
}
function getSubtitleSaveFileName(localItem, mediaPath, language, isForced, format) {
return null;
}
function getItemFileSize(path) {
return Promise.resolve();
}
function downloadFile(url, localItem) {
return Promise.resolve();
}
function downloadSubtitles(url, fileName) {
return Promise.resolve();
}
function getImageUrl(serverId, itemId, imageType, index) {
return null;
}
function hasImage(serverId, itemId, imageType, index) {
return Promise.resolve();
}
function downloadImage(localItem, url, serverId, itemId, imageType, index) {
return Promise.resolve();
}
function isDownloadFileInQueue(path) {
return Promise.resolve();
}
function translateFilePath(path) {
return Promise.resolve(path);
}
function resyncTransfers() {
return Promise.resolve();
}
return {
getLocalItem: getLocalItem,
saveOfflineUser: saveOfflineUser,
deleteOfflineUser: deleteOfflineUser,
recordUserAction: recordUserAction,
getUserActions: getUserActions,
deleteUserAction: deleteUserAction,
deleteUserActions: deleteUserActions,
getServerItemIds: getServerItemIds,
removeLocalItem: removeLocalItem,
addOrUpdateLocalItem: addOrUpdateLocalItem,
createLocalItem: createLocalItem,
downloadFile: downloadFile,
downloadSubtitles: downloadSubtitles,
hasImage: hasImage,
downloadImage: downloadImage,
getImageUrl: getImageUrl,
translateFilePath: translateFilePath,
getSubtitleSaveFileName: getSubtitleSaveFileName,
getLocalItemById: getLocalItemById,
getServerItems: getServerItems,
getItemFileSize: getItemFileSize,
isDownloadFileInQueue: isDownloadFileInQueue,
getViews: getViews,
getViewItems: getViewItems,
resyncTransfers: resyncTransfers
};
});
define([],function(){"use strict";function getLocalItem(serverId,itemId){return Promise.resolve()}function getLocalItemById(id){return Promise.resolve()}function saveOfflineUser(user){return Promise.resolve()}function deleteOfflineUser(id){return Promise.resolve()}function recordUserAction(action){return Promise.resolve()}function getUserActions(serverId){return Promise.resolve([])}function deleteUserAction(action){return Promise.resolve()}function deleteUserActions(actions){return Promise.resolve()}function getServerItemIds(serverId){return Promise.resolve([])}function getServerItems(serverId){return Promise.resolve([])}function getViews(serverId,userId){return Promise.resolve([])}function getViewItems(serverId,userId,parentId){return Promise.resolve([])}function removeLocalItem(localItem){return Promise.resolve()}function addOrUpdateLocalItem(localItem){return Promise.resolve()}function createLocalItem(libraryItem,serverInfo,jobItem){return Promise.resolve()}function getSubtitleSaveFileName(localItem,mediaPath,language,isForced,format){return null}function getItemFileSize(path){return Promise.resolve()}function downloadFile(url,localItem){return Promise.resolve()}function downloadSubtitles(url,fileName){return Promise.resolve()}function getImageUrl(serverId,itemId,imageType,index){return null}function hasImage(serverId,itemId,imageType,index){return Promise.resolve()}function downloadImage(localItem,url,serverId,itemId,imageType,index){return Promise.resolve()}function isDownloadFileInQueue(path){return Promise.resolve()}function translateFilePath(path){return Promise.resolve(path)}function resyncTransfers(){return Promise.resolve()}return{getLocalItem:getLocalItem,saveOfflineUser:saveOfflineUser,deleteOfflineUser:deleteOfflineUser,recordUserAction:recordUserAction,getUserActions:getUserActions,deleteUserAction:deleteUserAction,deleteUserActions:deleteUserActions,getServerItemIds:getServerItemIds,removeLocalItem:removeLocalItem,addOrUpdateLocalItem:addOrUpdateLocalItem,createLocalItem:createLocalItem,downloadFile:downloadFile,downloadSubtitles:downloadSubtitles,hasImage:hasImage,downloadImage:downloadImage,getImageUrl:getImageUrl,translateFilePath:translateFilePath,getSubtitleSaveFileName:getSubtitleSaveFileName,getLocalItemById:getLocalItemById,getServerItems:getServerItems,getItemFileSize:getItemFileSize,isDownloadFileInQueue:isDownloadFileInQueue,getViews:getViews,getViewItems:getViewItems,resyncTransfers:resyncTransfers}});

View file

@ -1,166 +1 @@
define([], function () {
'use strict';
function stringToArrayBuffer(string) {
// UTF-16LE
var buf = new ArrayBuffer(string.length * 2);
var bufView = new Uint16Array(buf);
for (var i = 0, strLen = string.length; i < strLen; i++) {
bufView[i] = string.charCodeAt(i);
}
return buf;
}
function arrayBufferToString(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
function getResultCode(result) {
if (result != null && result.resultCode != null) {
return result.resultCode;
}
return result;
}
function closeSocket(socketId) {
try {
chrome.sockets.udp.close(socketId);
} catch (err) {
}
}
function findServersInternal(timeoutMs) {
return new Promise(function (resolve, reject) {
var servers = [];
// Expected server properties
// Name, Id, Address, EndpointAddress (optional)
var chrome = window.chrome;
if (!chrome) {
resolve(servers);
return;
}
if (!chrome.sockets) {
resolve(servers);
return;
}
var timeout;
var socketId;
function onTimerExpired() {
resolve(servers);
if (socketId) {
chrome.sockets.udp.onReceive.removeListener(onReceive);
closeSocket(socketId);
}
}
function startTimer() {
console.log('starting udp receive timer with timeout ms: ' + timeoutMs);
timeout = setTimeout(onTimerExpired, timeoutMs);
}
function onReceive(info) {
try {
console.log('ServerDiscovery message received');
console.log(info);
if (info != null && info.socketId === socketId) {
var json = arrayBufferToString(info.data);
console.log('Server discovery json: ' + json);
var server = JSON.parse(json);
server.RemoteAddress = info.remoteAddress;
if (info.remotePort) {
server.RemoteAddress += ':' + info.remotePort;
}
servers.push(server);
}
} catch (err) {
console.log('Error receiving server info: ' + err);
}
}
var port = 7359;
console.log('chrome.sockets.udp.create');
startTimer();
chrome.sockets.udp.create(function (createInfo) {
if (!createInfo) {
console.log('create fail');
return;
}
if (!createInfo.socketId) {
console.log('create fail');
return;
}
socketId = createInfo.socketId;
console.log('chrome.sockets.udp.bind');
chrome.sockets.udp.bind(createInfo.socketId, '0.0.0.0', 0, function (bindResult) {
if (getResultCode(bindResult) !== 0) {
console.log('bind fail: ' + bindResult);
return;
}
var data = stringToArrayBuffer('who is EmbyServer?');
console.log('chrome.sockets.udp.send');
chrome.sockets.udp.send(createInfo.socketId, data, '255.255.255.255', port, function (sendResult) {
if (getResultCode(sendResult) !== 0) {
console.log('send fail: ' + sendResult);
} else {
chrome.sockets.udp.onReceive.addListener(onReceive);
console.log('sendTo: success ' + port);
}
});
});
});
});
}
return {
findServers: function (timeoutMs) {
return new Promise(function (resolve, reject) {
try {
findServersInternal(timeoutMs).then(resolve, function () {
resolve([]);
});
} catch (err) {
resolve([]);
}
});
}
};
});
define([],function(){"use strict";function stringToArrayBuffer(string){for(var buf=new ArrayBuffer(2*string.length),bufView=new Uint16Array(buf),i=0,strLen=string.length;i<strLen;i++)bufView[i]=string.charCodeAt(i);return buf}function arrayBufferToString(buf){return String.fromCharCode.apply(null,new Uint16Array(buf))}function getResultCode(result){return null!=result&&null!=result.resultCode?result.resultCode:result}function closeSocket(socketId){try{chrome.sockets.udp.close(socketId)}catch(err){}}function findServersInternal(timeoutMs){return new Promise(function(resolve,reject){function onTimerExpired(){resolve(servers),socketId&&(chrome.sockets.udp.onReceive.removeListener(onReceive),closeSocket(socketId))}function startTimer(){console.log("starting udp receive timer with timeout ms: "+timeoutMs),timeout=setTimeout(onTimerExpired,timeoutMs)}function onReceive(info){try{if(console.log("ServerDiscovery message received"),console.log(info),null!=info&&info.socketId===socketId){var json=arrayBufferToString(info.data);console.log("Server discovery json: "+json);var server=JSON.parse(json);server.RemoteAddress=info.remoteAddress,info.remotePort&&(server.RemoteAddress+=":"+info.remotePort),servers.push(server)}}catch(err){console.log("Error receiving server info: "+err)}}var servers=[],chrome=window.chrome;if(!chrome)return void resolve(servers);if(!chrome.sockets)return void resolve(servers);var timeout,socketId,port=7359;console.log("chrome.sockets.udp.create"),startTimer(),chrome.sockets.udp.create(function(createInfo){return createInfo&&createInfo.socketId?(socketId=createInfo.socketId,console.log("chrome.sockets.udp.bind"),void chrome.sockets.udp.bind(createInfo.socketId,"0.0.0.0",0,function(bindResult){if(0!==getResultCode(bindResult))return void console.log("bind fail: "+bindResult);var data=stringToArrayBuffer("who is EmbyServer?");console.log("chrome.sockets.udp.send"),chrome.sockets.udp.send(createInfo.socketId,data,"255.255.255.255",port,function(sendResult){0!==getResultCode(sendResult)?console.log("send fail: "+sendResult):(chrome.sockets.udp.onReceive.addListener(onReceive),console.log("sendTo: success "+port))})})):void console.log("create fail")})})}return{findServers:function(timeoutMs){return new Promise(function(resolve,reject){try{findServersInternal(timeoutMs).then(resolve,function(){resolve([])})}catch(err){resolve([])}})}}});

View file

@ -1,126 +1 @@
define([], function () {
'use strict';
function listenerSession(resolve, timeoutMs) {
var listenerSocket = null;
var serviceName = "7359";
var servers = [];
var timeout;
var stringToSend = "who is EmbyServer?|emby";
function closeListenerSocket() {
if (timeout) {
clearTimeout(timeout);
}
if (listenerSocket !== null) {
// The call below explicitly closes the socket, freeing the UDP port that it is currently bound to.
listenerSocket.close();
listenerSocket = null;
}
resolve(servers);
}
function startListener(eventObject) {
listenerSocket = new Windows.Networking.Sockets.DatagramSocket();
listenerSocket.addEventListener("messagereceived", onMessageReceived);
// Start listen operation.
listenerSocket.bindServiceNameAsync("").done(function () {
//try {
// var multicastGroup = '255.255.255.255';
// listenerSocket.joinMulticastGroup(new Windows.Networking.HostName(multicastGroup));
//}
//catch (exception) {
// onError("Error while joining multicast group: " + exception.message);
// return;
//}
sendMessage(stringToSend);
}, onError);
}
function sendMessage(txt) {
try {
var remoteHostname = new Windows.Networking.HostName("255.255.255.255");
// GetOutputStreamAsync can be called multiple times on a single DatagramSocket instance to obtain
// IOutputStreams pointing to various different remote endpoints. The remote hostname given to
// GetOutputStreamAsync can be a unicast, multicast or broadcast address.
listenerSocket.getOutputStreamAsync(remoteHostname, serviceName).done(function (outputStream) {
try {
// Send out some multicast or broadcast data. Datagrams generated by the IOutputStream will use
// <source host, source port> information obtained from the parent socket (i.e., 'listenSocket' in
// this case).
var writer = new Windows.Storage.Streams.DataWriter(outputStream);
writer.writeString(txt);
writer.storeAsync().done(function () {
timeout = setTimeout(closeListenerSocket, timeoutMs);
}, onError);
}
catch (exception) {
onError("Error sending message: " + exception.message);
}
}, onError);
}
catch (exception) {
onError("Error sending message outer: " + exception.message);
}
}
function onMessageReceived(eventArguments) {
try {
// Interpret the incoming datagram's entire contents as a string.
var stringLength = eventArguments.getDataReader().unconsumedBufferLength;
var receivedMessage = eventArguments.getDataReader().readString(stringLength);
if (receivedMessage === stringToSend) {
return;
}
var server = JSON.parse(receivedMessage);
var remoteAddress;
//if (eventArguments && eventArguments.remoteAddress) {
// remoteAddress = eventArguments.remoteAddress + ":" + eventArguments.remotePort;
//}
//if (remoteAddress) {
// server.RemoteAddress = remoteAddress;
//}
servers.push(server);
} catch (exception) {
onError("Error receiving message: " + exception);
}
}
function onError(reason) {
//require(['alert'], function (alert) {
// alert(reason);
//});
closeListenerSocket();
}
startListener();
}
return {
findServers: function (timeoutMs) {
return new Promise(function (resolve, reject) {
new listenerSession(resolve, timeoutMs);
});
}
};
});
define([],function(){"use strict";function listenerSession(resolve,timeoutMs){function closeListenerSocket(){timeout&&clearTimeout(timeout),null!==listenerSocket&&(listenerSocket.close(),listenerSocket=null),resolve(servers)}function startListener(eventObject){listenerSocket=new Windows.Networking.Sockets.DatagramSocket,listenerSocket.addEventListener("messagereceived",onMessageReceived),listenerSocket.bindServiceNameAsync("").done(function(){sendMessage(stringToSend)},onError)}function sendMessage(txt){try{var remoteHostname=new Windows.Networking.HostName("255.255.255.255");listenerSocket.getOutputStreamAsync(remoteHostname,serviceName).done(function(outputStream){try{var writer=new Windows.Storage.Streams.DataWriter(outputStream);writer.writeString(txt),writer.storeAsync().done(function(){timeout=setTimeout(closeListenerSocket,timeoutMs)},onError)}catch(exception){onError("Error sending message: "+exception.message)}},onError)}catch(exception){onError("Error sending message outer: "+exception.message)}}function onMessageReceived(eventArguments){try{var stringLength=eventArguments.getDataReader().unconsumedBufferLength,receivedMessage=eventArguments.getDataReader().readString(stringLength);if(receivedMessage===stringToSend)return;var server=JSON.parse(receivedMessage);servers.push(server)}catch(exception){onError("Error receiving message: "+exception)}}function onError(reason){closeListenerSocket()}var timeout,listenerSocket=null,serviceName="7359",servers=[],stringToSend="who is EmbyServer?|emby";startListener()}return{findServers:function(timeoutMs){return new Promise(function(resolve,reject){new listenerSession(resolve,timeoutMs)})}}});

View file

@ -1,14 +1 @@
define([], function () {
'use strict';
return {
findServers: function (timeoutMs) {
// Expected server properties
// Name, Id, Address, EndpointAddress (optional)
return Promise.resolve([]);
}
};
});
define([],function(){"use strict";return{findServers:function(timeoutMs){return Promise.resolve([])}}});

View file

@ -1,98 +1 @@
define(['localassetmanager', 'cameraRoll'], function (localAssetManager, cameraRoll) {
'use strict';
return function (connectionManager) {
var self = this;
self.uploadImages = function (server) {
return cameraRoll.getFiles().then(function (photos) {
if (!photos.length) {
return Promise.resolve();
}
var apiClient = connectionManager.getApiClient(server.Id);
return apiClient.getContentUploadHistory().then(function (uploadHistory) {
photos = getFilesToUpload(photos, uploadHistory);
console.log('Found ' + photos.length + ' files to upload');
return new Promise(function (resolve, reject) {
uploadNext(photos, 0, server, apiClient, resolve, reject);
});
}, function () {
return Promise.resolve();
});
});
};
function getFilesToUpload(files, uploadHistory) {
return files.filter(function (file) {
// Seeing some null entries for some reason
if (!file) {
return false;
}
return uploadHistory.FilesUploaded.filter(function (u) {
return getUploadId(file) === u.Id;
}).length === 0;
});
}
function getUploadId(file) {
return CryptoJS.SHA1(file + "1").toString();
}
function uploadNext(files, index, server, apiClient, resolve, reject) {
var length = files.length;
if (index >= length) {
resolve();
return;
}
uploadFile(files[index], apiClient).then(function () {
uploadNext(files, index + 1, server, apiClient, resolve, reject);
}, function () {
uploadNext(files, index + 1, server, apiClient, resolve, reject);
});
}
function uploadFile(file, apiClient) {
return new Promise(function (resolve, reject) {
require(['fileupload', "cryptojs-sha1"], function (FileUpload) {
var name = 'camera image ' + new Date().getTime();
var url = apiClient.getUrl('Devices/CameraUploads', {
DeviceId: apiClient.deviceId(),
Name: name,
Album: 'Camera Roll',
Id: getUploadId(file),
api_key: apiClient.accessToken()
});
console.log('Uploading file to ' + url);
new FileUpload().upload(file, name, url).then(resolve, reject);
});
});
}
};
});
define(["localassetmanager","cameraRoll"],function(localAssetManager,cameraRoll){"use strict";return function(connectionManager){function getFilesToUpload(files,uploadHistory){return files.filter(function(file){return!!file&&0===uploadHistory.FilesUploaded.filter(function(u){return getUploadId(file)===u.Id}).length})}function getUploadId(file){return CryptoJS.SHA1(file+"1").toString()}function uploadNext(files,index,server,apiClient,resolve,reject){var length=files.length;return index>=length?void resolve():void uploadFile(files[index],apiClient).then(function(){uploadNext(files,index+1,server,apiClient,resolve,reject)},function(){uploadNext(files,index+1,server,apiClient,resolve,reject)})}function uploadFile(file,apiClient){return new Promise(function(resolve,reject){require(["fileupload","cryptojs-sha1"],function(FileUpload){var name="camera image "+(new Date).getTime(),url=apiClient.getUrl("Devices/CameraUploads",{DeviceId:apiClient.deviceId(),Name:name,Album:"Camera Roll",Id:getUploadId(file),api_key:apiClient.accessToken()});console.log("Uploading file to "+url),(new FileUpload).upload(file,name,url).then(resolve,reject)})})}var self=this;self.uploadImages=function(server){return cameraRoll.getFiles().then(function(photos){if(!photos.length)return Promise.resolve();var apiClient=connectionManager.getApiClient(server.Id);return apiClient.getContentUploadHistory().then(function(uploadHistory){return photos=getFilesToUpload(photos,uploadHistory),console.log("Found "+photos.length+" files to upload"),new Promise(function(resolve,reject){uploadNext(photos,0,server,apiClient,resolve,reject)})},function(){return Promise.resolve()})})}}});

View file

@ -1,50 +1 @@
define([], function () {
'use strict';
function getValidFileName(path) {
// TODO
return path;
}
function getFullLocalPath(pathArray) {
// TODO
return pathArray.join('/');
}
function getPathFromArray(pathArray) {
// TODO
return pathArray.join('/');
}
function deleteFile(path) {
return Promise.resolve();
}
function deleteDirectory(path) {
return Promise.resolve();
}
function fileExists(path) {
return Promise.resolve();
}
function getItemFileSize(path) {
return Promise.resolve(0);
}
return {
getValidFileName: getValidFileName,
getFullLocalPath: getFullLocalPath,
getPathFromArray: getPathFromArray,
deleteFile: deleteFile,
deleteDirectory: deleteDirectory,
fileExists: fileExists,
getItemFileSize: getItemFileSize
};
});
define([],function(){"use strict";function getValidFileName(path){return path}function getFullLocalPath(pathArray){return pathArray.join("/")}function getPathFromArray(pathArray){return pathArray.join("/")}function deleteFile(path){return Promise.resolve()}function deleteDirectory(path){return Promise.resolve()}function fileExists(path){return Promise.resolve()}function getItemFileSize(path){return Promise.resolve(0)}return{getValidFileName:getValidFileName,getFullLocalPath:getFullLocalPath,getPathFromArray:getPathFromArray,deleteFile:deleteFile,deleteDirectory:deleteDirectory,fileExists:fileExists,getItemFileSize:getItemFileSize}});

View file

@ -1,114 +1 @@
define(['idb'], function () {
'use strict';
// Database name
var dbName = "items";
// Database version
var dbVersion = 1;
var dbPromise;
function setup() {
dbPromise = idb.open(dbName, dbVersion, function (upgradeDB) {
// Note: we don't use 'break' in this switch statement,
// the fall-through behaviour is what we want.
switch (upgradeDB.oldVersion) {
case 0:
upgradeDB.createObjectStore(dbName);
//case 1:
// upgradeDB.createObjectStore('stuff', { keyPath: '' });
}
}); //.then(db => console.log("DB opened!", db));
}
function getServerItemIds(serverId) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000).then(function (all) {
return all.filter(function (item) {
return item.ServerId === serverId;
}).map(function (item2) {
return item2.ItemId;
});
});
});
}
function getServerItemTypes(serverId, userId) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000).then(function (all) {
return all.filter(function (item) {
return item.ServerId === serverId && (item.UserIdsWithAccess == null || item.UserIdsWithAccess.contains(userId));
}).map(function (item2) {
return (item2.Item.Type || '').toLowerCase();
}).filter(filterDistinct);
});
});
}
function getServerIds(serverId) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000).then(function (all) {
return all.filter(function (item) {
return item.ServerId === serverId;
}).map(function (item2) {
return item2.Id;
});
});
});
}
function getAll() {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000);
});
}
function get(key) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).get(key);
});
}
function set(key, val) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).put(val, key);
return tx.complete;
});
}
function remove(key) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).delete(key);
return tx.complete;
});
}
function clear() {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).clear();
return tx.complete;
});
}
function filterDistinct(value, index, self) {
return self.indexOf(value) === index;
}
setup();
return {
get: get,
set: set,
remove: remove,
clear: clear,
getAll: getAll,
getServerItemIds: getServerItemIds,
getServerIds: getServerIds,
getServerItemTypes: getServerItemTypes
};
});
define(["idb"],function(){"use strict";function setup(){dbPromise=idb.open(dbName,dbVersion,function(upgradeDB){switch(upgradeDB.oldVersion){case 0:upgradeDB.createObjectStore(dbName)}})}function getServerItemIds(serverId){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4).then(function(all){return all.filter(function(item){return item.ServerId===serverId}).map(function(item2){return item2.ItemId})})})}function getServerItemTypes(serverId,userId){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4).then(function(all){return all.filter(function(item){return item.ServerId===serverId&&(null==item.UserIdsWithAccess||item.UserIdsWithAccess.contains(userId))}).map(function(item2){return(item2.Item.Type||"").toLowerCase()}).filter(filterDistinct)})})}function getServerIds(serverId){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4).then(function(all){return all.filter(function(item){return item.ServerId===serverId}).map(function(item2){return item2.Id})})})}function getAll(){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4)})}function get(key){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).get(key)})}function set(key,val){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).put(val,key),tx.complete})}function remove(key){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).delete(key),tx.complete})}function clear(){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).clear(),tx.complete})}function filterDistinct(value,index,self){return self.indexOf(value)===index}var dbPromise,dbName="items",dbVersion=1;return setup(),{get:get,set:set,remove:remove,clear:clear,getAll:getAll,getServerItemIds:getServerItemIds,getServerIds:getServerIds,getServerItemTypes:getServerItemTypes}});

View file

@ -1,46 +1 @@
define(['appSettings', 'connectionManager'], function (appSettings, connectionManager) {
'use strict';
var syncPromise;
return {
sync: function (options) {
if (syncPromise) {
return syncPromise;
}
return new Promise(function (resolve, reject) {
require(['multiserversync'], function (MultiServerSync) {
options = options || {};
options.cameraUploadServers = appSettings.cameraUploadServers();
syncPromise = new MultiServerSync(connectionManager).sync(options).then(function () {
syncPromise = null;
resolve();
}, function () {
syncPromise = null;
reject();
});
});
});
},
getSyncStatus: function () {
if (syncPromise != null) {
return 'Syncing';
}
return 'Idle';
}
};
});
define(["appSettings","connectionManager"],function(appSettings,connectionManager){"use strict";var syncPromise;return{sync:function(options){return syncPromise?syncPromise:new Promise(function(resolve,reject){require(["multiserversync"],function(MultiServerSync){options=options||{},options.cameraUploadServers=appSettings.cameraUploadServers(),syncPromise=new MultiServerSync(connectionManager).sync(options).then(function(){syncPromise=null,resolve()},function(){syncPromise=null,reject()})})})},getSyncStatus:function(){return null!=syncPromise?"Syncing":"Idle"}}});

File diff suppressed because one or more lines are too long

View file

@ -1,42 +1 @@
define(['serversync'], function (ServerSync) {
'use strict';
function syncNext(connectionManager, servers, index, options, resolve, reject) {
var length = servers.length;
if (index >= length) {
resolve();
return;
}
var server = servers[index];
console.log("Creating ServerSync to server: " + server.Id);
new ServerSync(connectionManager).sync(server, options).then(function () {
syncNext(connectionManager, servers, index + 1, options, resolve, reject);
}, function () {
syncNext(connectionManager, servers, index + 1, options, resolve, reject);
});
}
return function (connectionManager) {
var self = this;
self.sync = function (options) {
return new Promise(function (resolve, reject) {
var servers = connectionManager.getSavedServers();
syncNext(connectionManager, servers, 0, options, resolve, reject);
});
};
};
});
define(["serversync"],function(ServerSync){"use strict";function syncNext(connectionManager,servers,index,options,resolve,reject){var length=servers.length;if(index>=length)return void resolve();var server=servers[index];console.log("Creating ServerSync to server: "+server.Id),new ServerSync(connectionManager).sync(server,options).then(function(){syncNext(connectionManager,servers,index+1,options,resolve,reject)},function(){syncNext(connectionManager,servers,index+1,options,resolve,reject)})}return function(connectionManager){var self=this;self.sync=function(options){return new Promise(function(resolve,reject){var servers=connectionManager.getSavedServers();syncNext(connectionManager,servers,0,options,resolve,reject)})}}});

View file

@ -1,49 +1 @@
define(['localassetmanager'], function (localAssetManager) {
'use strict';
function syncNext(users, index, resolve, reject, apiClient, server) {
var length = users.length;
if (index >= length) {
resolve();
return;
}
var onFinish = function () {
syncNext(users, index + 1, resolve, reject, apiClient, server);
};
syncUser(users[index], apiClient).then(onFinish, onFinish);
}
function syncUser(user, apiClient) {
return apiClient.getOfflineUser(user.Id).then(function (result) {
return localAssetManager.saveOfflineUser(result);
}, function () {
// TODO: We should only delete if there's a 401 response
return localAssetManager.deleteOfflineUser(user.Id).catch(function () {
return Promise.resolve();
});
});
}
return function offlineUserSync() {
var self = this;
self.sync = function (apiClient, server) {
return new Promise(function (resolve, reject) {
var users = server.Users || [];
syncNext(users, 0, resolve, reject, apiClient, server);
});
};
};
});
define(["localassetmanager"],function(localAssetManager){"use strict";function syncNext(users,index,resolve,reject,apiClient,server){var length=users.length;if(index>=length)return void resolve();var onFinish=function(){syncNext(users,index+1,resolve,reject,apiClient,server)};syncUser(users[index],apiClient).then(onFinish,onFinish)}function syncUser(user,apiClient){return apiClient.getOfflineUser(user.Id).then(function(result){return localAssetManager.saveOfflineUser(result)},function(){return localAssetManager.deleteOfflineUser(user.Id).catch(function(){return Promise.resolve()})})}return function(){var self=this;self.sync=function(apiClient,server){return new Promise(function(resolve,reject){var users=server.Users||[];syncNext(users,0,resolve,reject,apiClient,server)})}}});

View file

@ -1,110 +1 @@
define([], function () {
'use strict';
return function (connectionManager) {
var self = this;
self.sync = function (server, options) {
if (!server.AccessToken && !server.ExchangeToken) {
console.log('Skipping sync to server ' + server.Id + ' because there is no saved authentication information.');
return Promise.resolve();
}
var connectionOptions = {
updateDateLastAccessed: false,
enableWebSocket: false,
reportCapabilities: false,
enableAutomaticBitrateDetection: false
};
return connectionManager.connectToServer(server, connectionOptions).then(function (result) {
if (result.State === MediaBrowser.ConnectionState.SignedIn) {
return performSync(server, options);
} else {
console.log('Unable to connect to server id: ' + server.Id);
return Promise.reject();
}
}, function (err) {
console.log('Unable to connect to server id: ' + server.Id);
throw err;
});
};
function performSync(server, options) {
console.log("ServerSync.performSync to server: " + server.Id);
options = options || {};
var uploadPhotos = options.uploadPhotos !== false;
if (options.cameraUploadServers && options.cameraUploadServers.indexOf(server.Id) === -1) {
uploadPhotos = false;
}
var pr = syncOfflineUsers(server, options);
return pr.then(function () {
if (uploadPhotos) {
return uploadContent(server, options);
}
return Promise.resolve();
}).then(function () {
return syncMedia(server, options);
});
}
function syncOfflineUsers(server, options) {
if (options.syncOfflineUsers === false) {
return Promise.resolve();
}
return new Promise(function (resolve, reject) {
require(['offlineusersync'], function (OfflineUserSync) {
var apiClient = connectionManager.getApiClient(server.Id);
new OfflineUserSync().sync(apiClient, server).then(resolve, reject);
});
});
}
function uploadContent(server, options) {
return new Promise(function (resolve, reject) {
require(['contentuploader'], function (contentuploader) {
uploader = new ContentUploader(connectionManager);
uploader.uploadImages(server).then(resolve, reject);
});
});
}
function syncMedia(server, options) {
return new Promise(function (resolve, reject) {
require(['mediasync'], function (MediaSync) {
var apiClient = connectionManager.getApiClient(server.Id);
new MediaSync().sync(apiClient, server, options).then(resolve, reject);
});
});
}
};
});
define([],function(){"use strict";return function(connectionManager){function performSync(server,options){console.log("ServerSync.performSync to server: "+server.Id),options=options||{};var uploadPhotos=options.uploadPhotos!==!1;options.cameraUploadServers&&options.cameraUploadServers.indexOf(server.Id)===-1&&(uploadPhotos=!1);var pr=syncOfflineUsers(server,options);return pr.then(function(){return uploadPhotos?uploadContent(server,options):Promise.resolve()}).then(function(){return syncMedia(server,options)})}function syncOfflineUsers(server,options){return options.syncOfflineUsers===!1?Promise.resolve():new Promise(function(resolve,reject){require(["offlineusersync"],function(OfflineUserSync){var apiClient=connectionManager.getApiClient(server.Id);(new OfflineUserSync).sync(apiClient,server).then(resolve,reject)})})}function uploadContent(server,options){return new Promise(function(resolve,reject){require(["contentuploader"],function(contentuploader){uploader=new ContentUploader(connectionManager),uploader.uploadImages(server).then(resolve,reject)})})}function syncMedia(server,options){return new Promise(function(resolve,reject){require(["mediasync"],function(MediaSync){var apiClient=connectionManager.getApiClient(server.Id);(new MediaSync).sync(apiClient,server,options).then(resolve,reject)})})}var self=this;self.sync=function(server,options){if(!server.AccessToken&&!server.ExchangeToken)return console.log("Skipping sync to server "+server.Id+" because there is no saved authentication information."),Promise.resolve();var connectionOptions={updateDateLastAccessed:!1,enableWebSocket:!1,reportCapabilities:!1,enableAutomaticBitrateDetection:!1};return connectionManager.connectToServer(server,connectionOptions).then(function(result){return result.State===MediaBrowser.ConnectionState.SignedIn?performSync(server,options):(console.log("Unable to connect to server id: "+server.Id),Promise.reject())},function(err){throw console.log("Unable to connect to server id: "+server.Id),err})}}});

View file

@ -1,23 +1 @@
define(['filerepository'], function (filerepository) {
'use strict';
function downloadFile(url, folderName, localPath) {
return Promise.resolve();
}
function downloadSubtitles(url, folderName, localItem) {
return Promise.resolve('');
}
function downloadImage(url, folderName, serverId, itemId, imageTag) {
return Promise.resolve(false);
}
return {
downloadFile: downloadFile,
downloadSubtitles: downloadSubtitles,
downloadImage: downloadImage
};
});
define(["filerepository"],function(filerepository){"use strict";function downloadFile(url,folderName,localPath){return Promise.resolve()}function downloadSubtitles(url,folderName,localItem){return Promise.resolve("")}function downloadImage(url,folderName,serverId,itemId,imageTag){return Promise.resolve(!1)}return{downloadFile:downloadFile,downloadSubtitles:downloadSubtitles,downloadImage:downloadImage}});

View file

@ -1,82 +1 @@
define(['idb'], function () {
'use strict';
// Database name
var dbName = "useractions";
// Database version
var dbVersion = 1;
var dbPromise;
function setup() {
dbPromise = idb.open(dbName, dbVersion, function (upgradeDB) {
// Note: we don't use 'break' in this switch statement,
// the fall-through behaviour is what we want.
switch (upgradeDB.oldVersion) {
case 0:
upgradeDB.createObjectStore(dbName);
//case 1:
// upgradeDB.createObjectStore('stuff', { keyPath: '' });
}
}); //.then(db => console.log("DB opened!", db));
}
function getByServerId(serverId) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 1000).then(function (all) {
return all.filter(function (item) {
return item.ServerId === serverId;
});
});
});
}
function getAll() {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000);
});
}
function get(key) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).get(key);
});
}
function set(key, val) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).put(val, key);
return tx.complete;
});
}
function remove(key) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).delete(key);
return tx.complete;
});
}
function clear() {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).clear(key);
return tx.complete;
});
}
setup();
return {
get: get,
set: set,
remove: remove,
clear: clear,
getAll: getAll,
getByServerId: getByServerId
};
});
define(["idb"],function(){"use strict";function setup(){dbPromise=idb.open(dbName,dbVersion,function(upgradeDB){switch(upgradeDB.oldVersion){case 0:upgradeDB.createObjectStore(dbName)}})}function getByServerId(serverId){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e3).then(function(all){return all.filter(function(item){return item.ServerId===serverId})})})}function getAll(){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4)})}function get(key){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).get(key)})}function set(key,val){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).put(val,key),tx.complete})}function remove(key){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).delete(key),tx.complete})}function clear(){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).clear(key),tx.complete})}var dbPromise,dbName="useractions",dbVersion=1;return setup(),{get:get,set:set,remove:remove,clear:clear,getAll:getAll,getByServerId:getByServerId}});

View file

@ -1,71 +1 @@
define(['idb'], function () {
'use strict';
// Database name
var dbName = "users";
// Database version
var dbVersion = 1;
var dbPromise;
function setup() {
dbPromise = idb.open(dbName, dbVersion, function (upgradeDB) {
// Note: we don't use 'break' in this switch statement,
// the fall-through behaviour is what we want.
switch (upgradeDB.oldVersion) {
case 0:
upgradeDB.createObjectStore(dbName);
//case 1:
// upgradeDB.createObjectStore('stuff', { keyPath: '' });
}
}); //.then(db => console.log("DB opened!", db));
}
function getAll() {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000);
});
}
function get(key) {
return dbPromise.then(function (db) {
return db.transaction(dbName).objectStore(dbName).get(key);
});
}
function set(key, val) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).put(val, key);
return tx.complete;
});
}
function remove(key) {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).delete(key);
return tx.complete;
});
}
function clear() {
return dbPromise.then(function (db) {
var tx = db.transaction(dbName, 'readwrite');
tx.objectStore(dbName).clear(key);
return tx.complete;
});
}
setup();
return {
get: get,
set: set,
remove: remove,
clear: clear,
getAll: getAll
};
});
define(["idb"],function(){"use strict";function setup(){dbPromise=idb.open(dbName,dbVersion,function(upgradeDB){switch(upgradeDB.oldVersion){case 0:upgradeDB.createObjectStore(dbName)}})}function getAll(){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).getAll(null,1e4)})}function get(key){return dbPromise.then(function(db){return db.transaction(dbName).objectStore(dbName).get(key)})}function set(key,val){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).put(val,key),tx.complete})}function remove(key){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).delete(key),tx.complete})}function clear(){return dbPromise.then(function(db){var tx=db.transaction(dbName,"readwrite");return tx.objectStore(dbName).clear(key),tx.complete})}var dbPromise,dbName="users",dbVersion=1;return setup(),{get:get,set:set,remove:remove,clear:clear,getAll:getAll}});

View file

@ -1,13 +1 @@
define([], function () {
'use strict';
function send(info) {
return Promise.resolve();
}
return {
send: send
};
});
define([],function(){"use strict";function send(info){return Promise.resolve()}return{send:send}});