修复link_lite.json bug
This commit is contained in:
1 parent
8dec5359bd
commit
68e3cf372f
7 files changed
+251
-241
No files matched your search
+18
-1
@@ -87,10 +87,27 @@ async function main() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let linksData;
|
||||
let links;
|
||||
try {
|
||||
const fileContent = fs.readFileSync(LINKS_FILE, 'utf8');
|
||||
links = JSON.parse(fileContent);
|
||||
linksData = JSON.parse(fileContent);
|
||||
// Adapt to both array (old) and object with friends key (new)
|
||||
if (Array.isArray(linksData)) {
|
||||
links = linksData;
|
||||
} else if (linksData.friends && Array.isArray(linksData.friends)) {
|
||||
// The new format has [name, url, avatar] arrays inside friends array
|
||||
// We need to convert them to objects {name, url} for the checker
|
||||
links = linksData.friends.map(item => {
|
||||
if (Array.isArray(item)) {
|
||||
return { name: item[0], url: item[1] };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
console.error('Error: Unknown JSON format');
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing JSON:', e.message);
|
||||
process.exit(1);
|
||||
|
||||
Reference in new issue
Block a user