Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Meteor.startup(function(){
console.log('DTube APP Started')
var konami = new KonamiCode();
konami.listen(function() {
// ??
})
window.steem = steem
window.testgun=Gun({peers:["https://guntest.herokuapp.com/gun"],localStorage:!1});
window.testgun.get("test").on(function(t){testgun.count=(testgun.count||0)+1});
Session.set('remoteSettings', Meteor.settings.public.remote)
// choose steem api on startup
if(!localStorage.getItem('steemAPI'))
steem.api.setOptions({ url: Meteor.settings.public.remote.APINodes[0], useAppbaseApi: true}); //Default
else
steem.api.setOptions({ url: localStorage.getItem('steemAPI'), useAppbaseApi: true }); //Set saved API.
Session.set('steemAPI', steem.api.options.url)
Session.set('lastHot', null)
Session.set('lastTrending', null)
Session.set('lastCreated', null)
Session.set('lastBlogs', {})
Session.set('tagDays', 7)
Session.set('tagSortBy', null)
async _init() {
let keypair = this.options.keypair;
if (!keypair) {
keypair = await Key.getDefault();
}
const gun = this.options.gun || new Gun();
const user = gun.user();
user.auth(keypair);
this.writable = true;
this.rootContact = new Attribute(`keyID`, Key.getId(keypair));
user.get(`epub`).put(keypair.epub);
// Initialize indexes with deterministic gun souls (.top)
this.gun = user.get(`iris`).put(user.top(`iris`));
this.gun.get(`identitiesBySearchKey`).put(user.top(`identitiesBySearchKey`));
this.gun.get(`identitiesByTrustDistance`).put(user.top(`identitiesByTrustDistance`));
this.gun.get(`messages`).put(user.top(`messages`));
this.gun.get(`messagesByTimestamp`).put(user.top(`messagesByTimestamp`));
this.gun.get(`messagesByHash`).put(user.top(`messagesByHash`));
this.gun.get(`messagesByDistance`).put(user.top(`messagesByDistance`));
this.messages = new Collection({gun: this.gun, class: Message, indexes: [`time`, `trustDistance`]});
this.contacts = new Collection({gun: this.gun, class: Contact});
if (!process.env.IRIS_NO_IPFS) {
let IPFS = null;
try {
IPFS = require('js-ipfs');
}
catch (err) {
console.warn('IRIS_NO_IPFS not set, and `js-ipfs` library not found! Local IPFS node NOT instantiated.');
}
if (IPFS) {
await IPFS.create({repo: `${configDir}/${ipfsRepo}`});
}
}
// Instantiate gun
debug(gunConfig);
const gun = new Gun(gunConfig);
// Load default Iris index with given configuration
config.gun = gun;
const index = new Iris.SocialNetwork(config);
debug(`index!`, index);
//await index.create(); // Create an index, if one does not exist
console.info(`Iris is up and running!`);
})().catch(e => {
console.error(e);
const newGuns = ports.map(port => {
const server = http.createServer(Gun.serve).listen(port, ip);
const g = new Gun({
radisk: false,
port: port,
multicast: false,
peers: {},
// file: `${configDir}/${gunDBName}.${port}`,
web: server,
});
g.netPort = port;
g.netId = netId;
return g;
});
//
// have to do this before instancing gun(?)
const gunPeers: Array<{ send: (msg: any) => void }> = [];
Gun.on('out', function(msg: any) {
// @ts-ignore
this.to.next(msg);
msg = JSON.stringify(msg);
// tslint:disable-next-line
gunPeers.forEach(function(peer) {
peer.send(msg);
});
});
const gun = Gun({
file: 'data',
});
const server = http.createServer((req, res) => {
let insert = '';
if (req.url!.endsWith('gun.js')) {
insert = '../';
}
fs.createReadStream(require('path').join(__dirname, insert, req.url))
.on('error', () => {
// static files!
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
})
.pipe(res); // stream