blob: 97e9bf476dff796de70e32c553e1c3f2f8295b6b [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import * as us from 'unscan'
2import fetch from 'node-fetch'
3import { writeFileSync } from 'fs'
4import generateFileName from './temp/generateFileName.js'
5import * as path from 'path'
6import {fileURLToPath} from 'url';
7const __filename = fileURLToPath(import.meta.url);
8const __dirname = path.dirname(__filename);
9
10export async function testNSFW(link: string): Promise<JSON> {
11 const image = (await (await fetch(link)).buffer()).toString('base64')
12 let fileName = generateFileName(link.split('/').pop().split('.').pop())
13 let p = path.join(__dirname, '/temp', fileName)
14 writeFileSync(p, image, 'base64')
15 let result = await us.nsfw.file(p)
16 return result
17}
18
19export async function testMalware(link: string): Promise<JSON> {
20 const file = (await (await fetch(link)).buffer()).toString('base64')
21 let fileName = generateFileName(link.split('/').pop().split('.').pop())
22 let p = path.join(__dirname, '/temp', fileName)
23 writeFileSync(p, file, 'base64')
24 let result = await us.malware.file(p)
25 return result
26}
27
28export async function testLink(link: string): Promise<JSON> {
29 return await us.link.scan(link)
30}