mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Adds core/refresh. Refactors ext/autoupdate.
This commit is contained in:
parent
f7fbd2e256
commit
3e3b2813cd
4 changed files with 56 additions and 34 deletions
|
@ -44,6 +44,27 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
|||
});
|
||||
},
|
||||
|
||||
getEntries = function (href, content, callback) {
|
||||
|
||||
$.ajax({
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'getentries',
|
||||
href: href,
|
||||
content: content
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getArchive = function (data, callback) {
|
||||
|
||||
$.ajax({
|
||||
|
@ -149,6 +170,7 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
|||
return {
|
||||
getStatus: getStatus,
|
||||
getChecks: getChecks,
|
||||
getEntries: getEntries,
|
||||
getArchive: getArchive,
|
||||
getThumbSrcSmall: getThumbSrcSmall,
|
||||
getThumbSrcBig: getThumbSrcBig,
|
||||
|
|
31
src/_h5ai/js/inc/core/refresh.js
Normal file
31
src/_h5ai/js/inc/core/refresh.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
modulejs.define('core/refresh', ['_', 'core/ajax', 'model/entry'], function (_, ajax, Entry) {
|
||||
|
||||
var parseJson = function (entry, json) {
|
||||
|
||||
var found = {};
|
||||
|
||||
_.each(json.entries, function (jsonEntry) {
|
||||
|
||||
found[jsonEntry.absHref] = true;
|
||||
Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
||||
});
|
||||
|
||||
_.each(entry.content, function (e) {
|
||||
if (!found[e.absHref]) {
|
||||
Entry.remove(e.absHref);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
refresh = function () {
|
||||
|
||||
var entry = Entry.get();
|
||||
ajax.getEntries(entry.absHref, 1, function (json) {
|
||||
|
||||
parseJson(entry, json);
|
||||
});
|
||||
};
|
||||
|
||||
return refresh;
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
modulejs.define('ext/autoupdate', ['_', '$', 'core/settings', 'core/event', 'core/resource', 'model/entry'], function (_, $, allsettings, event, resource, Entry) {
|
||||
modulejs.define('ext/autoupdate', ['_', '$', 'core/settings', 'core/event', 'core/refresh'], function (_, $, allsettings, event, refresh) {
|
||||
|
||||
var defaults = {
|
||||
enabled: false,
|
||||
|
@ -8,41 +8,9 @@ modulejs.define('ext/autoupdate', ['_', '$', 'core/settings', 'core/event', 'cor
|
|||
|
||||
settings = _.extend({}, defaults, allsettings.autoupdate),
|
||||
|
||||
parseJson = function (entry, json) {
|
||||
|
||||
var found = {};
|
||||
|
||||
_.each(json.entries, function (jsonEntry) {
|
||||
|
||||
found[jsonEntry.absHref] = true;
|
||||
Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
||||
});
|
||||
|
||||
_.each(entry.content, function (e) {
|
||||
if (!found[e.absHref]) {
|
||||
Entry.remove(e.absHref);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
heartbeat = function () {
|
||||
|
||||
var entry = Entry.get();
|
||||
|
||||
$.ajax({
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'getentries',
|
||||
href: entry.absHref,
|
||||
content: 1
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
parseJson(entry, json);
|
||||
}
|
||||
});
|
||||
|
||||
refresh();
|
||||
setTimeout(heartbeat, settings.interval);
|
||||
},
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// @include "core/format.js"
|
||||
// @include "core/langs.js"
|
||||
// @include "core/parser.js"
|
||||
// @include "core/refresh.js"
|
||||
// @include "core/resource.js"
|
||||
// @include "core/settings.js"
|
||||
// @include "core/store.js"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue