-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.ts
44 lines (36 loc) · 1.16 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const ipfsearch = require("ipfsearch-index")
const parse = require("csv-parse")
const fs = require("fs")
let indexer = new ipfsearch.Indexer()
let i = 0
const parser = parse()
fs.createReadStream("dump.csv").pipe(parser)
parser.on('readable', function () {
let record
while (record = parser.read()) {
if (parseInt(record[3]) > 0) {
indexer.addToIndex(new Torrent(record[0], record[1], parseInt(record[2]), parseInt(record[3]), parseInt(record[4]), parseInt(record[5])))
i++
}
}
})
parser.on('error', function (err) {
console.error(err.message)
})
parser.on('end', function () {
console.log("Read all " + i + " records. Persisting.");
indexer.persist("../website/generated/inv", "../website/generated/inx", "Urban Guacamole", "Torrent Paradise index", "", 1000);
})
class Torrent extends ipfsearch.Document {
len: number
s: number
l: number
c: number
constructor(id: string, text: string, size: number, seeders: number, leechers: number, completed: number) {
super(id, text)
this.len = size
this.s = seeders
this.l = leechers
this.c = completed
}
}