|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=[]; |
|
var push=function(file){ |
|
try{ |
|
var addon=JSON.parse(fs.readFileSync(file)); |
|
addon.mirror_path=file; |
|
addons.push(addon) |
|
} catch(err) { |
|
console.log(file); |
|
console.error(err) |
|
errors.push(file); |
|
} |
|
}; |
|
|
|
var files=fromDir('.', '.civitai.info'); |
|
files.map(e=>{push(e);}); |
|
|
|
fs.writeFileSync('civitai.info.json',JSON.stringify(addons)) |
|
fs.writeFileSync('errors.json',JSON.stringify(errors)) |
|
|
|
fs.writeFileSync('delfiles.bat','@echo off\n\n'+errors.map(e=>{return "del \""+ e + "\""}).join('\n')) |
|
fs.writeFileSync('delfiles.sh',errors.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('\/')) |
|
|