vk-to-telegram
Advanced tools
Comparing version 0.2.5 to 0.2.6
42
index.js
@@ -64,3 +64,3 @@ const forwarder = require('./lib/forwarder') | ||
let body | ||
const request = () => { | ||
const request = (() => { | ||
if (ctx.request) { | ||
@@ -71,3 +71,3 @@ return ctx.request | ||
} | ||
} | ||
})() | ||
const callback = async data => { | ||
@@ -81,5 +81,5 @@ if (ctx.request) { | ||
try { | ||
body = JSON.parse(JSON.stringify(request().body)) | ||
body = JSON.parse(JSON.stringify(request.body)) | ||
} catch (e) { | ||
throw `Error with body from vk: \n\n${request().body}\n${request().ip}` | ||
throw `Error with body from vk: \n\n${request.body}\n${request.ip}` | ||
} | ||
@@ -107,22 +107,34 @@ debug('Post body: %b', body) | ||
if (this.heroku) { | ||
const newPost = { id: body.object.id, date: Date.now() } | ||
if (herokuPosts[body.group_id] && Object.keys(herokuPosts[body.group_id]).length > 0) { | ||
for (const id in herokuPosts[body.group_id]) { | ||
const post = herokuPosts[body.group_id][id] | ||
if (Date.now() - post.date > this.herokuTimeout) { | ||
delete herokuPosts[body.group_id][id] | ||
const { originalUrl } = request | ||
const newPost = { id: body.object.id, owner: body.object.owner_id, date: Date.now() } | ||
if (herokuPosts[originalUrl] && Object.keys(herokuPosts[originalUrl]).length) { | ||
for (const owner in herokuPosts[originalUrl]) { | ||
const group = herokuPosts[originalUrl][owner] | ||
if (Object.keys(group).length) { | ||
for (const postId in group) { | ||
const post = group[postId] | ||
if (Date.now() - post.date > this.herokuTimeout) { | ||
delete group[postId] | ||
} | ||
} | ||
} | ||
} | ||
const post = herokuPosts[body.group_id][newPost.id] | ||
let post | ||
try { | ||
post = herokuPosts[originalUrl][newPost.owner][newPost.id] | ||
} catch (e) {} | ||
if (post) { | ||
throw `Double post detected ${JSON.stringify(body.object)}` | ||
throw `Double post detected: path - "${originalUrl}", post url - https://vk.com/wall${newPost.owner}_${newPost.id}` | ||
} else { | ||
herokuPosts[body.group_id][newPost.id] = { date: newPost.date } | ||
herokuPosts[originalUrl][newPost.owner][newPost.id] = { date: newPost.date } | ||
} | ||
} else { | ||
herokuPosts[body.group_id] = { | ||
[newPost.id]: { date: newPost.date } | ||
herokuPosts[originalUrl] = { | ||
[newPost.owner]: { | ||
[newPost.id]: { date: newPost.date } | ||
} | ||
} | ||
} | ||
} | ||
console.log(herokuPosts) | ||
if (this.debug) {debug('heroku Obj: %p', herokuPosts) } | ||
@@ -129,0 +141,0 @@ if (this.fromId ? body.object.from_id !== this.fromId : false) { |
{ | ||
"name": "vk-to-telegram", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Vk to telegram forwarder", | ||
@@ -5,0 +5,0 @@ "author": "ejnshtein", |
@@ -8,3 +8,3 @@ const vkToTelegram = require('./') | ||
signed: '👨', | ||
heroku: false, | ||
heroku: true, | ||
debug: true, | ||
@@ -21,3 +21,3 @@ prependText: '#overwatch', | ||
app.use(bodyParser()) | ||
app.use(route.post('/', async ctx => { | ||
app.use(async ctx => { | ||
vkToTg.send(ctx) | ||
@@ -27,3 +27,3 @@ // vkToTg.send({body: ctx.request.body, ip: ctx.request.ip }, { async send (data) {ctx.body = data} }) | ||
.catch(console.log) | ||
})) | ||
}) | ||
// app.post('/', (req, res) => { | ||
@@ -30,0 +30,0 @@ // vkToTg.send(req, res) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47665
860