Skip to content

Commit

Permalink
fix(feed): fix feed build
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jun 13, 2018
1 parent 3aefdc8 commit 7111988
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
36 changes: 36 additions & 0 deletions src/app/feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import TorrentLine from './torrent'
import {List} from 'material-ui/List';
import Divider from 'material-ui/Divider';
import Subheader from 'material-ui/Subheader';

export default class RecentTorrents extends Component {
constructor() {
super()
this.torrents = [];
}
componentDidMount() {
window.torrentSocket.emit('feed', window.customLoader((data) => {
if(data) {
this.torrents = data;
console.log(data)
this.forceUpdate();
}
}))
}
render() {
return (
<List className='animated torrents-container'>
<Subheader className='recent-title' inset={true}>
{__('Feed')}
</Subheader>
<Divider />
{
this.torrents.map((torrent, index) =>{
return <TorrentLine key={index} torrent={torrent} />;
})
}
</List>
);
}
}
10 changes: 3 additions & 7 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const forBigTable = require('./forBigTable')
const compareVersions = require('compare-versions');
const getTorrent = require('./gettorrent')
const _ = require('lodash')
const Feed = require('./feed')

module.exports = async ({
sphinx,
Expand All @@ -19,7 +18,8 @@ module.exports = async ({
insertTorrentToDB,
removeTorrentFromDB,
checkTorrent,
p2pStore
p2pStore,
feed
}) => {
let torrentClientHashMap = {}

Expand Down Expand Up @@ -737,12 +737,8 @@ module.exports = async ({

});

const feed = new Feed({sphinx})
await feed.load()
feed.clear()
setInterval(() => feed.save(), 10000)

// store torrent to feed
await feed.load()
p2pStore.on('store', async ({data: record, temp}) => {
if(!temp || !temp.torrent)
return
Expand Down
9 changes: 8 additions & 1 deletion src/background/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ module.exports = class Feed {
{
this.feed = []
this.sphinx = sphinx
this.loaded = false
}

async save() {
console.log('saving feed')
if(!this.loaded)
return // feed not loaded on begining, ignore saving

console.log('saving feed')
await this.sphinx.query('delete from feed where id > 0')
let id = 0
return Promise.all(
Expand All @@ -24,10 +28,13 @@ module.exports = class Feed {
this.feed = []

this._order()
this.loaded = true
console.log('lodead feed')
}

clear()
{
console.log('clearing feed')
this.feed = []
}

Expand Down
11 changes: 10 additions & 1 deletion src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const stun = require('stun')
const natUpnp = require('nat-upnp');
const http = require('https')
const API = require('./api')
const Feed = require('./feed')
//var sm = require('sitemap');
//var phantomjs = require('phantomjs-prebuilt')
//const disk = require('diskusage');
Expand Down Expand Up @@ -699,6 +700,10 @@ spider.on('peer', (IPs) => {
IPs.forEach(ip => p2p.add(ip))
})

// feed
const feed = new Feed({sphinx})
// load inside api

// setup api
API({
sphinx,
Expand All @@ -714,7 +719,8 @@ API({
insertTorrentToDB,
removeTorrentFromDB,
checkTorrent,
p2pStore
p2pStore,
feed
})

if(config.indexer) {
Expand Down Expand Up @@ -743,6 +749,9 @@ this.stop = async (callback) => {

console.log('closing p2p...')
p2p.close()

// save feed
await feed.save()

// safe future peers
if(dataDirectory)
Expand Down

0 comments on commit 7111988

Please sign in to comment.