Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vk-to-telegram

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vk-to-telegram - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

13

index.js

@@ -38,9 +38,8 @@ const forwarder = require('./lib/forwarder')

let body
const request = (() => {
if (ctx.request) {
return ctx.request
} else {
return ctx
}
})()
let request
if (ctx.request) {
request = ctx.request
} else {
request = ctx
}
const callback = async data => {

@@ -47,0 +46,0 @@ if (ctx.request) {

const puppeteer = require('puppeteer')
const EventEmitter = require('./event')
const events = new EventEmitter()
// work in progress
module.exports = {
/**
* get Audio List
* @param {String[]} audioList
*/
getAudios(audioList) {
return new Promise((resolve, reject) => {
events.emit('audioData', audioList, (err, result) => err ? reject(err) : resolve(result))
})
},
audioData (url) {
return new Promise((resolve, reject) => {
events.emit('audioDowndload', url, (err, result) => err ? reject(err) : resolve(result))
})
}
/**
* get Audio List
* @param {String[]} audioList
*/
getAudios (audioList) {
return new Promise((resolve, reject) => {
events.emit('audioData', audioList, (err, result) => err ? reject(err) : resolve(result))
})
},
audioData (url) {
return new Promise((resolve, reject) => {
events.emit('audioDowndload', url, (err, result) => err ? reject(err) : resolve(result))
})
}
}
async function start () {
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--profile-directory="Default"']
})
const page = await browser.newPage()
await page.goto('https://datmusic.xyz', {
timeout: 5000,
waitUntil: 'domcontentloaded',
})
await page.waitForSelector('#result > div.list-group')
events.on('audioData', async (audios, callback) => {
const result = []
for (let i = 0; i < audios.length; i++) {
let audioData
try {
audioData = await page.evaluate((audio) => {
return fetch(`https://api-2.datmusic.xyz/search?q=${audio}`).then(response => response.json())
}, audios[i])
} catch (e) {
return callback(e)
}
result.push(audioData.data[0])
}
callback(null, result)
})
// events.on('audioDowndload', async (audio, callback) => {
// const page = await browser.newPage()
// console.log(audio)
// try {
// await page.goto(audio)
// } catch (e) {
// return callback(e)
// }
// return callback(null, audioBuffer)
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--profile-directory="Default"']
})
const page = await browser.newPage()
await page.goto('https://datmusic.xyz', {
timeout: 5000,
waitUntil: 'domcontentloaded',
})
await page.waitForSelector('#result > div.list-group')
events.on('audioData', async (audios, callback) => {
const result = []
for (let i = 0; i < audios.length; i++) {
let audioData
try {
audioData = await page.evaluate((audio) => {
return fetch(`https://api-2.datmusic.xyz/search?q=${audio}`).then(response => response.json())
}, audios[i])
} catch (e) {
return callback(e)
}
result.push(audioData.data[0])
}
callback(null, result)
})
// events.on('audioDowndload', async (audio, callback) => {
// const page = await browser.newPage()
// console.log(audio)
// try {
// await page.goto(audio)
// } catch (e) {
// return callback(e)
// }
// return callback(null, audioBuffer)
// })
// })
}
start()

@@ -1,2 +0,2 @@

const Telegram = require('telegraf/telegram')
const { Telegram } = require('telegraf')
const utils = require('./utils')

@@ -94,5 +94,3 @@ const defaultConfig = require('./default-config')

type: 'photo',
media: {
url: utils.photo.getHQ(attachment.photo)
},
media: utils.photo.getHQ(attachment.photo),
caption: mediaText,

@@ -103,3 +101,2 @@ parse_mode: 'HTML'

}
console.log(attachmentsArray)
if (messageExtra.reply_markup.inline_keyboard.length > 0) {

@@ -118,5 +115,3 @@ let attachmentsExtraText = messageExtra.reply_markup.inline_keyboard.map(el => el.text)

type: 'photo',
post: {
url: utils.photo.getHQ(attachment.album.thumb)
},
media: utils.photo.getHQ(attachment.album.thumb),
caption: `<a href="https://vk.com/album${attachment.album.owner_id}_${attachment.album.id}">${decode(attachment.album.title)}</a>`,

@@ -150,5 +145,3 @@ parse_mode: 'HTML'

type: 'photo',
media: {
url: utils.photo.getHQ(attachments[i].photo)
},
media: utils.photo.getHQ(attachments[i].photo),
caption: attachments[i].photo.text.length < 1000 ? decode(attachments[i].photo.text) : '',

@@ -159,3 +152,2 @@ parse_mode: 'HTML'

}
console.log(photosArray)
if (photosArray.length === 1) {

@@ -162,0 +154,0 @@ messages.push(await telegram.sendPhoto(chatId, photosArray[0].media.url, mediaExtra))

@@ -5,4 +5,4 @@ const Telegram = require('telegraf/telegram')

const vkApi = require('./vkapi')
const Entities = require('html-entities').AllHtmlEntities
const { decode } = new Entities()
const { AllHtmlEntities } = require('html-entities')
const { decode } = new AllHtmlEntities()
module.exports = ({ token, vkToken, chatId }) => {

@@ -23,7 +23,7 @@ const telegram = new Telegram(token)

if (!text) {
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, doc.preview.video.src, extra))
} else if (text && text.length < 1000) {
extra.caption = `${text}\n\n<a href="${doc.url}">Open original</a>`
extra.disable_web_page_preview = true
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, doc.preview.video.src, extra))
} else {

@@ -33,3 +33,3 @@ extra.disable_web_page_preview = false

extra.caption = `<a href="${doc.url}">Open original</a>`
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, doc.preview.video.src, extra))
}

@@ -39,7 +39,7 @@ } else if (doc.ext === 'mp4' && doc.size < 50000000) {

if (!text) {
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, doc.url, extra))
} else if (text && text.length < 1000) {
extra.caption = `${text}\n\n<a href="${doc.url}">Open original</a>`
extra.disable_web_page_preview = true
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, doc.url, extra))
} else {

@@ -49,10 +49,10 @@ extra.disable_web_page_preview = false

extra.caption = `<a href="${doc.url}">Open original</a>`
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, doc.url, extra))
}
} else if (doc.size < 50000000) {
if (!text) {
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, doc.url, extra))
} else if (text && text.length < 1000) {
extra.caption = text
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, doc.url, extra))
} else {

@@ -62,3 +62,3 @@ extra.disable_web_page_preview = false

extra.disable_web_page_preview = true
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, doc.url, extra))
}

@@ -65,0 +65,0 @@ } else {

{
"name": "vk-to-telegram",
"version": "0.2.9",
"version": "0.3.0",
"description": "Vk to telegram forwarder",

@@ -26,3 +26,3 @@ "author": "ejnshtein",

"html-entities": "^1.2.1",
"telegraf": "^3.25.5",
"telegraf": "^3.26.0",
"telegram-typings": "^4.0.0-beta"

@@ -29,0 +29,0 @@ },

@@ -15,9 +15,9 @@ const VkToTelegram = require('./')

})
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const app = new Koa()
app.use(bodyParser())
app.use(async ctx => {
console.log(ctx)
VkToTg.send(ctx)
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json())
app.use((req, res) => {
// console.log(req)
VkToTg.send(req, res)
.then(console.log)

@@ -24,0 +24,0 @@ .catch(err => {

@@ -11,3 +11,3 @@ /// <reference types="node" />

*/
send(req: IncomingMessage, res?: ServerResponse): Promise<ResponseMessage[]>
send(req: IncomingMessage, res?: ServerResponse): Promise<Array<ResponseMessage>>
}

@@ -14,0 +14,0 @@ export interface ForwarderOptions {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc