mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
working on .checkIndex(..)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9f2357952d
commit
530102521f
@ -754,6 +754,50 @@ var FileSystemLoaderActions = actions.Actions({
|
|||||||
return imgs
|
return imgs
|
||||||
})
|
})
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
// XXX update index for removed images...
|
||||||
|
// - remove non-existing previews from index
|
||||||
|
// - replace non-existing originals with the largest preview (in index)
|
||||||
|
// ...do not touch the fs
|
||||||
|
// XXX this does not give the logger to render...
|
||||||
|
// XXX set changes...
|
||||||
|
checkIndex: ['File/',
|
||||||
|
core.doc`
|
||||||
|
`,
|
||||||
|
function(logger){
|
||||||
|
logger = logger || this.logger
|
||||||
|
logger = logger && logger.push('Checking index')
|
||||||
|
|
||||||
|
// XXX can we remove this restriction...
|
||||||
|
if(this.location.loaded.length != 1){
|
||||||
|
throw new Error('.fixIndex(): combined indexes not supported.')
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.images
|
||||||
|
.run(function(){
|
||||||
|
logger
|
||||||
|
&& this
|
||||||
|
.forEach(function(gid){
|
||||||
|
logger.emit('queued', gid)}) })
|
||||||
|
.map(function(gid, image){
|
||||||
|
var updated = false
|
||||||
|
|
||||||
|
var previews = image.preview || {}
|
||||||
|
Object.entries(previews)
|
||||||
|
.forEach(function(p){
|
||||||
|
!fse.existsSync(image.base_path +'/'+ p[1])
|
||||||
|
&& (updated = true)
|
||||||
|
&& (delete previews[p[0]]) })
|
||||||
|
|
||||||
|
!fse.existsSync(image.base_path +'/'+ image.path)
|
||||||
|
&& (updated = true)
|
||||||
|
&& (delete image.path)
|
||||||
|
|
||||||
|
logger && logger.emit('done', gid)
|
||||||
|
|
||||||
|
return updated ? gid : []
|
||||||
|
})
|
||||||
|
.flat() }],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -354,9 +354,7 @@ module.ImagesPrototype = {
|
|||||||
//version: '3.1',
|
//version: '3.1',
|
||||||
|
|
||||||
get length(){
|
get length(){
|
||||||
return Object.keys(this).length
|
return this.keys().length },
|
||||||
// XXX is this the correct way to deal with service props???
|
|
||||||
+ (this.hasOwnProperty('version') ? -1 : 0) },
|
|
||||||
|
|
||||||
// Generic iterators...
|
// Generic iterators...
|
||||||
//
|
//
|
||||||
@ -371,12 +369,15 @@ module.ImagesPrototype = {
|
|||||||
//
|
//
|
||||||
// XXX revise...
|
// XXX revise...
|
||||||
// XXX are these slower than doing it manualy via Object.keys(..)
|
// XXX are these slower than doing it manualy via Object.keys(..)
|
||||||
|
// XXX use .keys()
|
||||||
forEach: function(func){
|
forEach: function(func){
|
||||||
var i = 0
|
var i = 0
|
||||||
for(var key in this){
|
for(var key in this){
|
||||||
// reject non images...
|
// reject non images...
|
||||||
// XXX make this cleaner...
|
// XXX make this cleaner...
|
||||||
if(key == 'length' || typeof(this[key]) == typeof(function(){})){
|
if(key == 'length'
|
||||||
|
|| key == 'version'
|
||||||
|
|| this[key] instanceof Function){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
func.call(this[key], key, this[key], i++, this)
|
func.call(this[key], key, this[key], i++, this)
|
||||||
@ -389,7 +390,9 @@ module.ImagesPrototype = {
|
|||||||
for(var key in this){
|
for(var key in this){
|
||||||
// reject non images...
|
// reject non images...
|
||||||
// XXX make this cleaner...
|
// XXX make this cleaner...
|
||||||
if(key == 'length' || typeof(this[key]) == typeof(function(){})){
|
if(key == 'length'
|
||||||
|
|| key == 'version'
|
||||||
|
|| this[key] instanceof Function){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if(func.call(this[key], key, this[key], i++, this)){
|
if(func.call(this[key], key, this[key], i++, this)){
|
||||||
@ -406,7 +409,9 @@ module.ImagesPrototype = {
|
|||||||
for(var key in this){
|
for(var key in this){
|
||||||
// reject non images...
|
// reject non images...
|
||||||
// XXX make this cleaner...
|
// XXX make this cleaner...
|
||||||
if(key == 'length' || typeof(this[key]) == typeof(function(){})){
|
if(key == 'length'
|
||||||
|
|| key == 'version'
|
||||||
|
|| this[key] instanceof Function){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//res[key] = func.call(this[key], key, this[key], i++, this)
|
//res[key] = func.call(this[key], key, this[key], i++, this)
|
||||||
@ -419,7 +424,9 @@ module.ImagesPrototype = {
|
|||||||
for(var key in this){
|
for(var key in this){
|
||||||
// reject non images...
|
// reject non images...
|
||||||
// XXX make this cleaner...
|
// XXX make this cleaner...
|
||||||
if(key == 'length' || typeof(this[key]) == typeof(function(){})){
|
if(key == 'length'
|
||||||
|
|| key == 'version'
|
||||||
|
|| this[key] instanceof Function){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res = func.call(this[key], res, this[key], key, i++, this)
|
res = func.call(this[key], res, this[key], key, i++, this)
|
||||||
@ -427,8 +434,14 @@ module.ImagesPrototype = {
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// XXX remove version...
|
||||||
keys: function(){
|
keys: function(){
|
||||||
return Object.keys(this) },
|
var keys = Object.keys(this)
|
||||||
|
var i = keys.indexOf('version')
|
||||||
|
i >= 0
|
||||||
|
&& keys.splice(i, 1)
|
||||||
|
return keys
|
||||||
|
},
|
||||||
|
|
||||||
// Build an image index relative to an attribute...
|
// Build an image index relative to an attribute...
|
||||||
//
|
//
|
||||||
@ -491,19 +504,29 @@ module.ImagesPrototype = {
|
|||||||
img_data = IMAGE_DATA
|
img_data = IMAGE_DATA
|
||||||
}
|
}
|
||||||
|
|
||||||
var s
|
// get minimal element bigger than size or if size is null get
|
||||||
var url = img_data.path
|
// the greatest element...
|
||||||
var preview_size = 'Original'
|
var path = img_data.path
|
||||||
var p = Infinity
|
var preview = img_data.preview || {}
|
||||||
var previews = img_data.preview || {}
|
var p = [null, 0]
|
||||||
|
for(var s in preview){
|
||||||
|
var v = parseInt(s)
|
||||||
|
p = (size == null || (v < size && p[1] < size)) ?
|
||||||
|
(v < p[1] ? p : [s, v])
|
||||||
|
: (p[1] >= size && (v > p[1] || v < size)) ?
|
||||||
|
p
|
||||||
|
: [s, v]
|
||||||
|
}
|
||||||
|
|
||||||
for(var k in previews){
|
// get the original if it exists and smaller than size...
|
||||||
s = parseInt(k)
|
if(path && (size == null || p[1] < size)){
|
||||||
if(s < p && s > size){
|
var url = path
|
||||||
preview_size = k
|
var preview_size = 'Original'
|
||||||
p = s
|
|
||||||
url = previews[k]
|
// get the largest preview...
|
||||||
}
|
} else {
|
||||||
|
var url = preview[p[0]]
|
||||||
|
var preview_size = p[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX LEGACY...
|
// XXX LEGACY...
|
||||||
@ -514,7 +537,7 @@ module.ImagesPrototype = {
|
|||||||
img_data.base_path + '/'
|
img_data.base_path + '/'
|
||||||
: '')
|
: '')
|
||||||
+ url,
|
+ url,
|
||||||
size: preview_size
|
size: preview_size,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user