key:
"getRegistrationInfo"
,
value: function(feature, apiClient, options) {
var params
=
{
serverId: apiClient.serverId(),
deviceId: this.deviceId(),
deviceName: this.deviceName(),
appName: this.appName(),
appVersion: this.appVersion(),
embyUserName: ""
};
(options
=
options || {}).viewOnly && (params.viewOnly
=
options.viewOnly);
var cacheKey
=
getCacheKey(feature, apiClient, options),
regInfo
=
JSON.parse(this.appStorage.getItem(cacheKey) ||
"{}"
),
timeSinceLastValidation
=
Date.now()
-
(regInfo.lastValidDate ||
0
);
if
(timeSinceLastValidation <
=
864e5
)
return
console.log(
"getRegistrationInfo returning cached info"
), Promise.resolve();
var regCacheValid
=
timeSinceLastValidation <
=
864e5
*
(regInfo.cacheExpirationDays ||
7
);
params.embyUserName
=
apiClient.getCurrentUserName();
var currentUserId
=
apiClient.getCurrentUserId();
if
(currentUserId &&
"81f53802ea0247ad80618f55d9b4ec3c"
=
=
=
currentUserId.toLowerCase() &&
"21585256623b4beeb26d5d3b09dec0ac"
=
=
=
params.serverId.toLowerCase())
return
Promise.reject();
var appStorage
=
this.appStorage,
getRegPromise
=
ajax({
url:
"https://mb3admin.com/admin/service/registration/validateDevice?"
+
paramsToString(params),
type
:
"POST"
,
dataType:
"json"
}).then(function(response) {
return
appStorage.setItem(cacheKey, JSON.stringify({
lastValidDate: Date.now(),
deviceId: params.deviceId,
cacheExpirationDays: response.cacheExpirationDays
})), Promise.resolve()
}, function(response) {
var status
=
(response || {}).status;
return
console.log(
"getRegistrationInfo response: "
+
status),
403
=
=
=
status ? Promise.reject(
"overlimit"
) : status && status <
500
? Promise.reject() : function(err) {
if
(console.log(
"getRegistrationInfo failed: "
+
err), regCacheValid)
return
console.log(
"getRegistrationInfo returning cached info"
), Promise.resolve();
throw err
}(response)
});
return
regCacheValid ? (console.log(
"getRegistrationInfo returning cached info"
), Promise.resolve()) : getRegPromise
}