-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
48 lines (42 loc) · 1.83 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Readable } from 'stream'
import * as Types from './types'
export interface FilterResult extends Types.TxFlaggedOptions {
flagged: boolean // main output: whether the image is filtered or not
/** @deprecated */
scores?: string //remove later
}
/* Feedback error types to the host app. Host may process image and try submitting to plugin again. */
export interface FilterErrorResult {
flagged: undefined
data_reason:
'oversized' // oversized compressed png files that cannot be opened by most image libraries.
| 'partial' // partial image that library cannnot open
| 'unsupported' // unsupported file type (your plugin is expected to handle jpeg/png/gif at a minimum)
| 'corrupt' // image data is corrupt
| 'corrupt-maybe' // image data is corrupt, but can be displayed by a browser
| 'noop' // no operation
| 'retry' // clean up and retry
| 'mimetype' // mimetype mismatch
err_message?: string // optional error message
}
export interface FilterPluginInterface {
/**
* init()
* This will be called early to instantiate your rater plugin. You should do things like load AI models here.
* Consider using Singleton/ESM module level variables/static coding patterns to conserve ram.
*/
init(): Promise<void>
/**
* @param buffer - buffer containing image data. Already checked for mime-type, but actual data is often corrupt
* @param mimetype - the mime-type indicated
* @param txid - the Arweave txid, useful for debugging against the actual served data
*/
checkImage(buffer: Buffer, mimetype: string, txid: string): Promise<FilterResult | FilterErrorResult>
}
export interface APIFilterResult {
txid: string
filterResult: FilterResult | FilterErrorResult
}
export interface StreamPluginInterface {
checkStream(read: Readable, mimetype: string, txid: string):Promise<string | Error>
}