Skip to content

Commit

Permalink
added browser getcookie, updated hightech try to get from cookies first
Browse files Browse the repository at this point in the history
  • Loading branch information
gegehprast committed Jan 18, 2020
1 parent 3648496 commit aed07c0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ class Browser {
async getPlainProperty(element, property) {
return await element.getProperty(property).then(x => x.jsonValue())
}

/**
* Get a cookie object of page.
*
* @param {Object} page Browser page
* @param {String} name Name of the cookie to select
*/
async getCookie(page, name) {
const cookies = await page.cookies()

const cookie = cookies.filter(cookie => cookie.name == name)

return cookie[0]
}
}

module.exports = new Browser
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shallty",
"version": "2.1.0",
"version": "2.1.3",
"description": "Shallty adalah aplikasi untuk meng-crawl situs fastsub/fanshare Indonesia. Tujuan utamanya adalah untuk melewati berbagai halaman redirect dan mengambil tautan unduh aslinya. Saat ini Shallty telah mendukung crawling untuk Meownime, Samehadaku, Neonime, dan Oploverz. https://shallty.kyuun.id",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions shortlinks/Hightech.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ class Hightech {
try {
await page.goto(link)

const xyzklCookie = await Browser.getCookie(page, 'xyzkl')

if (xyzklCookie && xyzklCookie.value) {
await page.close()

return {
url: Util.base64Decode(xyzklCookie.value)
}
}

await Util.sleep(8000)
await page.waitForSelector('a[href="#generate"]')
await page.click('a[href="#generate"]')
Expand Down
23 changes: 23 additions & 0 deletions test/integration/shortlink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ describe('shortlink', function () {
})
})

describe('hightech', function () {
it('should return 200 and a string of url', function (done) {
this.timeout(60000)
supertest(app).get('/api/shortlink?link=https%3A%2F%2Fhightech.web.id%2Fko82jkl9%2F%3Fxyzkl%3DaHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL3VjP2lkPTFheVhtZlcwWV9VZjRGMDhqcjVjTDl0NDhDVnBmUlJ2Xw%3D%3D')
.expect(200)
.expect(function (res) {
expect(res.body.status).to.equal(200)
expect(res.body.message).to.equal('Success')
expect(res.body.data).to.be.an('object')
expect(res.body.data).to.has.property('url')
expect(res.body.data.url).to.be.a('string')
expect(res.body.data.url).to.include('google')
})
.end(function (err, res) {
if (err) {
console.log(res.body)
return done(err)
}
done()
})
})
})

describe('anjay', function () {
it('should return 200 and a string of url', function (done) {
this.timeout(60000)
Expand Down
13 changes: 13 additions & 0 deletions test/unit/shortlink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ describe('shortlink', function () {
})
})

describe('hightech', function () {
it('should return an object which has a string url property', async function () {
this.timeout(60000)
await Browser.init()
const data = await Shortlink.parse('https%3A%2F%2Fhightech.web.id%2Fko82jkl9%2F%3Fxyzkl%3DaHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL3VjP2lkPTFheVhtZlcwWV9VZjRGMDhqcjVjTDl0NDhDVnBmUlJ2Xw%3D%3D')

expect(data).to.be.an('object')
expect(data).to.has.property('url')
expect(data.url).to.be.a('string')
expect(data.url).to.include('google')
})
})

describe('anjay', function () {
it('should return an object which has a string url property', async function () {
this.timeout(60000)
Expand Down

0 comments on commit aed07c0

Please sign in to comment.