pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import * as us from 'unscan' |
| 2 | import fetch from 'node-fetch' |
| 3 | import { writeFileSync } from 'fs' |
| 4 | import generateFileName from './temp/generateFileName.js' |
| 5 | import * as path from 'path' |
| 6 | import {fileURLToPath} from 'url'; |
| 7 | const __filename = fileURLToPath(import.meta.url); |
| 8 | const __dirname = path.dirname(__filename); |
| 9 | |
| 10 | export async function testNSFW(link: string): Promise<JSON> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 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) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 16 | return result |
| 17 | } |
| 18 | |
| 19 | export async function testMalware(link: string): Promise<JSON> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 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) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 25 | return result |
| 26 | } |
| 27 | |
| 28 | export async function testLink(link: string): Promise<JSON> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 29 | return await us.link.scan(link) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 30 | } |