Skip to content

Commit

Permalink
fix request options
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jul 27, 2019
1 parent 7f3d78e commit 2307207
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import chowdown from 'chowdown'
import Agent from 'socks5-https-client/lib/Agent'

const cache = new LRU({max: 500})
const baseRequestOptions: request.CoreOptions = {
baseUrl: 'https://www.google.com/search',
const baseRequestOptions: request.Options = {
baseUrl: 'https://www.google.com',
uri: '/search',
qs: {
hl: 'zh-CN',
tbm: 'isch',
Expand All @@ -26,16 +27,15 @@ export default class Searcher {
}

static async searchRemote (site: string, query: string) {
const requestOptions = {
const requestOptions: request.Options = {
...baseRequestOptions,
qs: {
...baseRequestOptions.qs,
q: `site:${site} ${query}`
}
}

let albums: string[] = []
await chowdown(requestOptions).collection('.rg_el .rg_meta', chowdown.query.string())
let albums: string[] = await chowdown(requestOptions).collection('.rg_el .rg_meta', chowdown.query.string())
albums = albums.map((a) => JSON.parse(a))

const cacheKey = Searcher.getCacheKey(site, query)
Expand Down
7 changes: 5 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import http from 'http'
import _ from 'lodash'
import getPort from 'get-port'
import bundler from './bundler'
import app from './index'

bundler.on('bundled', async () => {
async function launchServer () {
const server = http.createServer(app)

const port = await getPort({
Expand All @@ -16,4 +17,6 @@ bundler.on('bundled', async () => {
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`
console.log(`Listening on ${bind}`)
})
})
}

bundler.on('bundled', _.once(launchServer))

0 comments on commit 2307207

Please sign in to comment.