|
| 1 | +import { ClassifierSdk, HashType, ImageFormat, RequestEncoding, type ClassifyImageInput } from '@crispthinking/athena-classifier-sdk'; |
| 2 | +import { randomUUID } from 'crypto'; |
| 3 | +import { createReadStream } from 'fs'; |
| 4 | +import { inspect } from 'util'; |
| 5 | + |
| 6 | + |
| 7 | +const sdk = new ClassifierSdk({ |
| 8 | + authentication: { |
| 9 | + clientId: process.env.VITE_ATHENA_CLIENT_ID, |
| 10 | + clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET, |
| 11 | + issuerUrl: process.env.VITE_OAUTH_ISSUER, |
| 12 | + scope: "manage:classify" |
| 13 | + }, |
| 14 | + grpcAddress: 'csam-classification-messages.crispdev.com:443', |
| 15 | + affiliate: 'test-affiliate', |
| 16 | + deploymentId: 'node-js-client-test' |
| 17 | +}); |
| 18 | + |
| 19 | +sdk.on('data', (data) => { |
| 20 | + for(const item of data.outputs) |
| 21 | + { |
| 22 | + console.log(inspect(item, { showHidden: false, colors: true, depth: null, maxArrayLength: null, showProxy: false })); |
| 23 | + } |
| 24 | +}); |
| 25 | + |
| 26 | +await sdk.open(); |
| 27 | + |
| 28 | +// Enter loop to run until keypress entered. |
| 29 | +process.stdin.on('data', async (data) => { |
| 30 | + const input = data.toString().trim(); |
| 31 | + if (input === 'exit') { |
| 32 | + await sdk.close(); |
| 33 | + process.exit(0); |
| 34 | + } |
| 35 | +}); |
| 36 | + |
| 37 | +// Break if sigterm |
| 38 | +process.on('SIGTERM', async () => { |
| 39 | + await sdk.close(); |
| 40 | + process.exit(0); |
| 41 | +}); |
| 42 | + |
| 43 | +while(true) |
| 44 | +{ |
| 45 | + const inputs = Array.from({ length: 3 }, () => ({ |
| 46 | + data: createReadStream('448x448.jpg'), |
| 47 | + format: ImageFormat.JPEG, |
| 48 | + correlationId: randomUUID(), |
| 49 | + encoding: RequestEncoding.UNCOMPRESSED, |
| 50 | + includeHashes: [HashType.MD5, HashType.SHA1] |
| 51 | + } as ClassifyImageInput)); |
| 52 | + |
| 53 | + await sdk.sendClassifyRequest(inputs); |
| 54 | + |
| 55 | + // Sleep for 10 seconds |
| 56 | + await new Promise((resolve) => setTimeout(resolve, Math.random() * 10000)); |
| 57 | +} |
0 commit comments