finished migration to new glob...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-05-08 21:39:10 +03:00
parent 250869530f
commit 3fd43123ba
4 changed files with 55 additions and 43 deletions

View File

@ -501,17 +501,26 @@ var FileSystemLoaderActions = actions.Actions({
// get the image list... // get the image list...
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
var files = {}
glob.globStream(path + '/'+ that.config['image-file-pattern'], { glob.globStream(path + '/'+ that.config['image-file-pattern'], {
stat: !!read_stat, stat: !!read_stat,
withFileTypes: true,
strict: false, strict: false,
}) })
.on('data', function(e){ found.push(e) }) .on('data', function(e){
var p = e.fullpath()
// normalize win paths...
.replace(/\\/g, '/')
files[p] = e
found.push(p) })
.on('error', function(err){ .on('error', function(err){
update_interval update_interval
&& clearInterval(update_interval) && clearInterval(update_interval)
console.error(err) console.error(err)
reject(err) }) reject(err) })
.on('end', function(lst){ .on('end', function(){
// XXX do we need to have two copies of the list???
var lst = found.slice()
update_interval update_interval
&& clearInterval(update_interval) && clearInterval(update_interval)
logger && found.length > 0 logger && found.length > 0
@ -526,11 +535,13 @@ var FileSystemLoaderActions = actions.Actions({
var imgs = images.Images.fromArray(lst, path) var imgs = images.Images.fromArray(lst, path)
if(!!read_stat){ if(!!read_stat){
var stats = this.statCache
var p = pathlib.posix var p = pathlib.posix
imgs.forEach(function(gid, img){ imgs.forEach(function(gid, img){
var stat = stats[p.join(img.base_path, img.path)] var stat = files[
img.base_path ?
p.join(img.base_path, img.path)
: img.path]
img.atime = stat.atime img.atime = stat.atime
img.mtime = stat.mtime img.mtime = stat.mtime
@ -1203,48 +1214,47 @@ var FileSystemLoaderUIActions = actions.Actions({
browseImages: ['- File/Load images...', makeBrowseProxy('loadImages')], browseImages: ['- File/Load images...', makeBrowseProxy('loadImages')],
browseSubIndexes: ['File/List sub-indexes...', browseSubIndexes: ['File/List sub-indexes...',
widgets.makeUIDialog(function(){ widgets
var that = this .makeUIDialog(function(){
var index_dir = this.config['index-dir'] var that = this
var index_dir = this.config['index-dir']
var o = browse.makeLister(null, function(path, make){ var o = browse.makeLister(null, function(path, make){
var dialog = this var dialog = this
var path = that.location.path var path = that.location.path
if(that.location.load != 'loadIndex'){ if(that.location.load != 'loadIndex'){
make('No indexes loaded...', null, true) make('No indexes loaded...', null, true)
return return }
}
// indicate that we are working... // indicate that we are working...
var spinner = make('...') var spinner = make('...')
// XXX we do not need to actually read anything.... // XXX we do not need to actually read anything....
//file.loadIndex(path, that.config['index-dir'], this.logger) //file.loadIndex(path, that.config['index-dir'], this.logger)
// XXX we need to prune the indexes -- avoid loading nested indexes... // XXX we need to prune the indexes -- avoid loading nested indexes...
file.listIndexes(path, index_dir) var res = []
.on('error', function(err){ file.listIndexes(path, index_dir)
console.error(err) .on('error', function(err){
}) console.error(err) })
.on('end', function(res){ .on('data', function(path){
res.push(path) })
.on('end', function(){
// we got the data, we can now remove the spinner...
spinner.remove()
// we got the data, we can now remove the spinner... res.forEach(function(p){
spinner.remove() // trim local paths and keep external paths as-is...
p = p.split(index_dir)[0]
var txt = p.split(path).pop()
txt = txt != p ? './'+pathlib.join('.', txt) : txt
res.forEach(function(p){ make(txt)
// trim local paths and keep external paths as-is... .on('open', function(){
p = p.split(index_dir)[0] that.loadIndex(p) }) }) }) })
var txt = p.split(path).pop() .on('open', function(){
txt = txt != p ? './'+pathlib.join('.', txt) : txt o.close() })
return o })],
make(txt)
.on('open', function(){
that.loadIndex(p) }) }) }) })
.on('open', function(){
o.close() })
return o
})],
toggleDotFileDrawing: ['Interface/File browser/Hide dot files', toggleDotFileDrawing: ['Interface/File browser/Hide dot files',
core.makeConfigToggler( core.makeConfigToggler(

View File

@ -25,7 +25,7 @@ if(typeof(process) != 'undefined'){
var cp = requirejs('child_process') var cp = requirejs('child_process')
var fse = requirejs('fs-extra') var fse = requirejs('fs-extra')
var pathlib = requirejs('path') var pathlib = requirejs('path')
var glob = requirejs('glob') //var glob = requirejs('glob')
// XXX migrate to exifreader as it is a bit more flexible... // XXX migrate to exifreader as it is a bit more flexible...
// ...use it in browser mode... // ...use it in browser mode...
//var exifReader = requirejs('exifreader') //var exifReader = requirejs('exifreader')

View File

@ -321,7 +321,9 @@ module.ImagesClassPrototype = {
// XXX stub... // XXX stub...
var i = 0 var i = 0
//var base_pattern = base ? RegExp('^' + base) : null //var base_pattern = base ? RegExp('^' + base) : null
var base_pattern = base ? RegExp('^' + RegExp.quoteRegExp(base)) : null var base_pattern = base ?
RegExp('^' + RegExp.quoteRegExp(base))
: null
data.forEach(function(path){ data.forEach(function(path){
// XXX need to normalize path... // XXX need to normalize path...
var p = path.startsWith('data') ? var p = path.startsWith('data') ?

View File

@ -1,7 +1,7 @@
{ {
"name": "ImageGrid.Viewer.g4", "name": "ImageGrid.Viewer.g4",
"main": "index.html", "main": "index.html",
"version": "4.0.6a", "version": "4.0.7a",
"author": "Alex A. Naanou <alex.nanou@gmail.com> (https://github.com/flynx)", "author": "Alex A. Naanou <alex.nanou@gmail.com> (https://github.com/flynx)",
"contributors": [], "contributors": [],
"repository": "github:flynx/ImageGrid", "repository": "github:flynx/ImageGrid",