Skip to content

Commit

Permalink
Update remove-duplicates.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gap579137 authored Sep 20, 2024
1 parent dd42b8b commit e424b49
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions scripts/remove-duplicates.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
const fs = require("fs").promises;
const path = require("path");
const fs = require("node:fs").promises;
const path = require("node:path");

(async () => {
try {
const directoryPath = path.join(__dirname, "..");
const files = (await fs.readdir(directoryPath)).filter(file => file.endsWith(".txt"));
const files = (await fs.readdir(directoryPath)).filter((file) =>
file.endsWith(".txt"),
);

await Promise.all(files.map(async file => {
const filePath = path.join(directoryPath, file);
let fileContents = await fs.readFile(filePath, "utf8");
await Promise.all(
files.map(async (file) => {
const filePath = path.join(directoryPath, file);
const fileContents = await fs.readFile(filePath, "utf8");

const lines = fileContents.split("\n");
const existingDomains = new Set();
const filteredLines = [];

lines.forEach(line => {
if (line.startsWith("0.0.0.0 ")) {
const domain = line.replace("0.0.0.0 ", "");
if (!existingDomains.has(domain)) {
existingDomains.add(domain);
filteredLines.push(line);
const lines = fileContents.split("\n");
const existingDomains = new Set();
const filteredLines = lines.filter((line) => {
if (line.startsWith("0.0.0.0 ")) {
const domain = line.replace("0.0.0.0 ", "");
if (!existingDomains.has(domain)) {
existingDomains.add(domain);
return true;
}
return false;
}
} else {
filteredLines.push(line);
}
});

// Combine the filtered lines back into a single string
const updatedContents = filteredLines.join("\n");
return true;
});

await fs.writeFile(filePath, updatedContents, "utf8");
}));
await fs.writeFile(filePath, filteredLines.join("\n"), "utf8");
}),
);
} catch (error) {
console.error("Error processing files:", error);
}
Expand Down

0 comments on commit e424b49

Please sign in to comment.