Efreak
commited on
Commit
•
06567e1
1
Parent(s):
7f0ad03
Add a script for merging the .info files.
Browse filesIt also creates (but does not run) scripts for deleting the LFS pointers and fetching the
full files from civitai. Thus, after those scripts are run, it should be run again.
- civitai.info.js +55 -0
civitai.info.js
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This script exists to merge all .info files into one array.
|
2 |
+
* unfortunately, civitai is storing some of them as LFS objects
|
3 |
+
* so the script outputs a list of errors along with scripts to fix them (delfiles.sh, replacefiles.sh)
|
4 |
+
* others files are blank, so just ignore the errors the second time, they're files that aren't on civitai
|
5 |
+
* now we get tot he important part: it parses all files, and dumps all of them into an array in civitai.info.json for further processing
|
6 |
+
* Run once, run delfiles.bat or delfiles.sh to get rid of the bad ones, then run replacefiles.sh to fetch them from civitai.
|
7 |
+
*/
|
8 |
+
var path = require('path'),
|
9 |
+
fs = require('fs');
|
10 |
+
|
11 |
+
function fromDir(startPath, filter, arr) {
|
12 |
+
arr=arr||[];
|
13 |
+
//console.log('Starting from dir '+startPath+'/');
|
14 |
+
if (!fs.existsSync(startPath)) {
|
15 |
+
console.log("no dir ", startPath);
|
16 |
+
return;
|
17 |
+
}
|
18 |
+
|
19 |
+
var files = fs.readdirSync(startPath);
|
20 |
+
for (var i = 0; i < files.length; i++) {
|
21 |
+
var filename = path.join(startPath, files[i]);
|
22 |
+
var stat = fs.lstatSync(filename);
|
23 |
+
if (stat.isDirectory()) {
|
24 |
+
fromDir(filename, filter,arr); //recurse
|
25 |
+
} else if (filename.endsWith(filter)) {
|
26 |
+
arr.push(filename);
|
27 |
+
//console.log('-- found: ', filename);
|
28 |
+
};
|
29 |
+
};
|
30 |
+
return arr;
|
31 |
+
};
|
32 |
+
|
33 |
+
var addons=[];
|
34 |
+
var errors=[];
|
35 |
+
var push=function(file){
|
36 |
+
try{
|
37 |
+
var addon=JSON.parse(fs.readFileSync(file));
|
38 |
+
addon.mirror_path=file; // Add the location we found the file.
|
39 |
+
addons.push(addon)
|
40 |
+
} catch(err) {
|
41 |
+
console.log(file);
|
42 |
+
console.error(err)
|
43 |
+
errors.push(file);
|
44 |
+
}
|
45 |
+
};
|
46 |
+
|
47 |
+
var files=fromDir('.', '.civitai.info');
|
48 |
+
files.map(e=>{push(e);});
|
49 |
+
|
50 |
+
fs.writeFileSync('civitai.info.json',JSON.stringify(addons))
|
51 |
+
fs.writeFileSync('errors.json',JSON.stringify(errors))
|
52 |
+
//console.error("Error with the following files:",errors);
|
53 |
+
fs.writeFileSync('delfiles.bat','@echo off\n\n'+errors.map(e=>{return "del \""+ e + "\""}).join('\n'))
|
54 |
+
fs.writeFileSync('delfiles.sh',errors.map(e=>{return "rm \""+ e + "\""}).join('\n').split('\\').join('/'))
|
55 |
+
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('\/'))
|