Retrieve time through X-FIC-Time header instead of time.json
This commit is contained in:
parent
c33390fa80
commit
6034246015
11 changed files with 107 additions and 131 deletions
|
@ -45,17 +45,37 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
|
||||
$('[data-toggle="popover"]').popover();
|
||||
|
||||
$rootScope.recvTime = function(response) {
|
||||
sessionStorage.userService = angular.toJson({
|
||||
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
||||
"he": (new Date()).getTime(),
|
||||
});
|
||||
}
|
||||
|
||||
function updTime() {
|
||||
if (sessionStorage.userService) {
|
||||
if (sessionStorage.userService && $rootScope.settings) {
|
||||
var time = angular.fromJson(sessionStorage.userService);
|
||||
var srv_cur = (Date.now() + (time.cu * 1000 - time.he)) / 1000;
|
||||
var remain = time.du;
|
||||
if (time.st == Math.floor(srv_cur)) {
|
||||
var settings = $rootScope.settings;
|
||||
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
||||
|
||||
if (Math.floor(settings.start / 1000) == Math.floor(srv_cur / 1000)) {
|
||||
$rootScope.refresh(true);
|
||||
}
|
||||
if (time.st > 0 && time.st <= srv_cur) {
|
||||
remain = time.st + time.du - srv_cur;
|
||||
|
||||
var remain = 0;
|
||||
if (settings.start == 0) {
|
||||
$rootScope.time = {};
|
||||
return
|
||||
} else if (settings.start > srv_cur) {
|
||||
$rootScope.startIn = Math.floor((settings.start - srv_cur) / 1000);
|
||||
remain = settings.end - settings.start;
|
||||
} else if (settings.end > srv_cur) {
|
||||
$rootScope.startIn = 0;
|
||||
remain = settings.end - srv_cur;
|
||||
}
|
||||
|
||||
remain = remain / 1000;
|
||||
|
||||
if (remain < 0) {
|
||||
remain = 0;
|
||||
$rootScope.time.end = true;
|
||||
|
@ -67,8 +87,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
$rootScope.time.end = false;
|
||||
$rootScope.time.expired = false;
|
||||
}
|
||||
$rootScope.time.start = time.st * 1000;
|
||||
$rootScope.time.duration = time.du;
|
||||
|
||||
$rootScope.time.remaining = remain;
|
||||
$rootScope.time.hours = Math.floor(remain / 3600);
|
||||
$rootScope.time.minutes = Math.floor((remain % 3600) / 60);
|
||||
|
@ -95,13 +114,12 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
if (!justMy) {
|
||||
$timeout.cancel($scope.cbr);
|
||||
$scope.cbr = $timeout($rootScope.refresh, 42000);
|
||||
$http.get("/time.json").then(function(response) {
|
||||
var time = response.data;
|
||||
time.he = (new Date()).getTime();
|
||||
sessionStorage.userService = angular.toJson(time);
|
||||
});
|
||||
$http.get("/settings.json").then(function(response) {
|
||||
$scope.settings = response.data;
|
||||
$rootScope.recvTime(response);
|
||||
response.data.start = new Date(response.data.start);
|
||||
response.data.end = new Date(response.data.end);
|
||||
response.data.generation = new Date(response.data.generation);
|
||||
$rootScope.settings = response.data;
|
||||
});
|
||||
$http.get("/themes.json").then(function(response) {
|
||||
$scope.themes = response.data;
|
||||
|
|
Reference in a new issue