mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-28 14:04:45 -04:00
Refactor item.
This commit is contained in:
parent
003b3f3edb
commit
0f1ca4e85b
3 changed files with 22 additions and 15 deletions
|
@ -95,7 +95,7 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/settings
|
|||
|
||||
_.each(json.items, function (jsonItem) {
|
||||
|
||||
var e = Item.get(jsonItem.href, jsonItem.time, jsonItem.size, jsonItem.isManaged, jsonItem.content);
|
||||
var e = Item.get(jsonItem);
|
||||
found[e.absHref] = true;
|
||||
});
|
||||
|
||||
|
|
|
@ -46,26 +46,32 @@ modulejs.define('model/item', ['_', 'core/event', 'core/location', 'core/server'
|
|||
}
|
||||
}
|
||||
|
||||
function getItem(absHref, time, size, isManaged, isContentFetched) {
|
||||
function getItem(options) {
|
||||
|
||||
absHref = location.forceEncoding(absHref);
|
||||
|
||||
if (!startsWith(absHref, settings.rootHref)) {
|
||||
if (_.isString(options)) {
|
||||
options = {href: options};
|
||||
} else if (!options || !_.isString(options.href)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var self = cache[absHref] || new Item(absHref);
|
||||
var href = location.forceEncoding(options.href);
|
||||
|
||||
if (_.isNumber(time)) {
|
||||
self.time = time;
|
||||
if (!startsWith(href, settings.rootHref)) {
|
||||
return null;
|
||||
}
|
||||
if (_.isNumber(size)) {
|
||||
self.size = size;
|
||||
|
||||
var self = cache[href] || new Item(href);
|
||||
|
||||
if (_.isNumber(options.time)) {
|
||||
self.time = options.time;
|
||||
}
|
||||
if (isManaged) {
|
||||
if (_.isNumber(options.size)) {
|
||||
self.size = options.size;
|
||||
}
|
||||
if (options.managed) {
|
||||
self.isManaged = true;
|
||||
}
|
||||
if (isContentFetched) {
|
||||
if (options.fetched) {
|
||||
self.isContentFetched = true;
|
||||
}
|
||||
|
||||
|
@ -105,7 +111,8 @@ modulejs.define('model/item', ['_', 'core/event', 'core/location', 'core/server'
|
|||
|
||||
if (response.items) {
|
||||
_.each(response.items, function (jsonItem) {
|
||||
getItem(jsonItem.href, jsonItem.time, jsonItem.size, jsonItem.isManaged, jsonItem.content);
|
||||
|
||||
getItem(jsonItem);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,8 @@ class Item {
|
|||
);
|
||||
|
||||
if ($this->is_folder) {
|
||||
$obj["isManaged"] = $this->app->is_managed_href($this->href);
|
||||
$obj["content"] = $this->is_content_fetched;
|
||||
$obj["managed"] = $this->app->is_managed_href($this->href);
|
||||
$obj["fetched"] = $this->is_content_fetched;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue