Skip to content

Commit

Permalink
update filetype check
Browse files Browse the repository at this point in the history
  • Loading branch information
zongyz committed Apr 3, 2018
1 parent d456718 commit 23259f8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ typings/
# dotenv environment variables file
.env

package-lock.json
11 changes: 6 additions & 5 deletions lib/origin/file.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use strict'
const request = require('../request')
const {URL, parse:urlParse} = require('url')
const fileType = require('file-type')

module.exports = async baseurl=>{
let icons = []
return new Promise(async (resolve, reject)=>{
let url = new URL('/favicon.ico', baseurl).href
try {
let response = await request(url, {
method:'HEAD'
})
method:'GET',
responseType: 'arraybuffer'
}), type = fileType(response.data) || {}
if(
response.status ==200 &&
parseInt(response.headers['content-length'],10) > 0 &&
/image/ig.test(response.headers['content-type'])
response.status == 200 &&
/image/ig.test(type.mime)
){
icons.push({
src:url,
Expand Down
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-website-favicon",
"version": "0.0.5",
"version": "0.0.6",
"description": "get the favicons url from any website",
"main": "index.js",
"scripts": {
Expand All @@ -17,6 +17,7 @@
},
"dependencies": {
"axios": "^0.18.0",
"cheerio": "^1.0.0-rc.2"
"cheerio": "^1.0.0-rc.2",
"file-type": "^7.6.0"
}
}

0 comments on commit 23259f8

Please sign in to comment.