blob: 5abd7262ea4e5c3b4e56914ab92adc2b418a4003 [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> {
pineafane625d782022-05-09 18:04:32 +010011 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)
pineafan32767212022-03-14 21:27:39 +000016 return result
17}
18
19export async function testMalware(link: string): Promise<JSON> {
pineafane625d782022-05-09 18:04:32 +010020 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)
pineafan32767212022-03-14 21:27:39 +000025 return result
26}
27
28export async function testLink(link: string): Promise<JSON> {
pineafane625d782022-05-09 18:04:32 +010029 return await us.link.scan(link)
pineafan32767212022-03-14 21:27:39 +000030}