| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| var fullFiles = false; |
|
|
| var path = require('path'), |
| fs = require('fs'); |
|
|
| function fromDir(startPath, filter, arr) { |
| arr=arr||[]; |
| |
| if (!fs.existsSync(startPath)) { |
| console.log("no dir ", startPath); |
| return; |
| } |
|
|
| var files = fs.readdirSync(startPath); |
| for (var i = 0; i < files.length; i++) { |
| var filename = path.join(startPath, files[i]); |
| var stat = fs.lstatSync(filename); |
| if (stat.isDirectory()) { |
| fromDir(filename, filter,arr); |
| } else if (filename.endsWith(filter)) { |
| arr.push(filename); |
| |
| }; |
| }; |
| return arr; |
| }; |
|
|
| var addons=[]; var errors=[]; errors2=[]; |
| var push=function(file){ |
| try{ |
| var addon=JSON.parse(fs.readFileSync(file)); |
| } catch(err) { |
| console.error(file + " is probably an LFS pointer. Will be added to delfiles and replacefiles scripts!"); |
| errors.push(file); |
| return; |
| } |
| if(Object.keys(addon).length==0) { |
| console.error(file + " is an empty file! Will be added to delfiles script! Assuming it's not a mistake, it will *not* be replaced!"); |
| errors2.push(file); |
| return; |
| } |
| addon.mirror_path=file; |
|
|
| |
| if(fullFiles == true) { |
| addons.push(addon); |
| return; |
| } |
| delete addon.model.poi; |
| 'createdAt,updatedAt,earlyAccessTimeFrame,downloadUrl,description'.split(',').forEach(key=>{delete addon[key]}); |
| for(file=addon.files.length-1;file>=0;file--) { |
| if(addon.files[file].type == 'Training Data' || addon.files[file].type == 'Config') { |
| addon.files.splice(file,1); |
| } else { |
| 'sizeKB,format,pickleScanResult,pickleScanMessage,virusScanResult,scannedAt,hashes,primary,downloadUrl'.split(',').forEach(key=>{ |
| delete addon.files[file][key]; |
| }); |
| } |
| }; |
| var imgs=addon.images; |
| addon.images=[]; |
| imgs.forEach(img=>{addon.images.push(img.url.replace('https://imagecache.civitai.com/',''))}); |
| addons.push(addon); |
| }; |
|
|
| var files1=fromDir('models', '.civitai.info'); |
| var files2=fromDir('embeddings', '.civitai.info'); |
| var files=[...files1,...files2]; |
| files.forEach(file=>{push(file)}); |
| |
| var errs=[...errors,...errors2].sort(); |
| fs.writeFileSync('civitai.info.json',JSON.stringify(addons)) |
| fs.writeFileSync('errors.json',JSON.stringify(errs)) |
| |
| fs.writeFileSync('delfiles.bat','@echo off\n\n'+errs.map(e=>{return "del \""+ e + "\""}).join('\n')) |
| fs.writeFileSync('delfiles.sh',errs.map(e=>{return "rm \""+ e + "\""}).join('\n').split('\\').join('/')) |
| fs.writeFileSync('replacefiles.sh',errors.map(e=>{return "wget \"https://huggingface.co/anonderpling/civitai_mirror/resolve/main/"+(e.split(" ").join("%23")+"\" -O \""+e+"\"")}).join('\n').split('\\').join('\/')) |
|
|