1 个不稳定版本
0.1.1 | 2024 年 7 月 9 日 |
---|---|
0.1.0 |
|
#7 in #consuming
85 每月下载量
32KB
526 行
Arachnid Shield SDK
用于消费 Arachnid Shield API 的 SDK。
用法
首先,通过联系 Project Arachnid 获取登录凭证。
同步客户端
您可以使用拥有所有消费 Arachnid Shield API 所需方法的 ArachnidShield
客户端。
use arachnid_shield::{ArachnidShield, ApiUser};
use mime::IMAGE_JPEG;
fn get_media() -> Vec<u8> {
return vec![]
}
let client = ArachnidShield::new(
ApiUser::new("<username>", "<password>")
);
// Suppose you have media contents and mime_type already available.
let contents = get_media();
// Request Arachnid Shield to scan the media.
let response = client.scan_media_from_bytes(contents, IMAGE_JPEG);
// Might want to handle errors in practice, but we'll
// just .unwrap() it here in this example.
let scanned_media = response.unwrap();
if scanned_media.matches_known_media() {
eprintln!("Uh-oh, this media: {:#?} matches known media so it is harmful.", scanned_media);
}
异步客户端
您可以使用与同步客户端接口完全相同但所有方法均为可等待的 AsyncArachnidShield
客户端。
use arachnid_shield::{AsyncArachnidShield as ArachnidShield, ApiUser};
use mime::IMAGE_JPEG;
fn get_media() -> Vec<u8> {
return vec![]
}
let client = ArachnidShield::new(
ApiUser::new("<username>", "<password>")
);
#[tokio::main] // Just an example. Could use any runtime here.
async fn main() {
// Suppose you have media contents and mime_type already available.
let contents = get_media();
// Request Arachnid Shield to scan the media.
let response = client.scan_media_from_bytes(contents, IMAGE_JPEG).await;
// Might want to handle errors in practice, but we'll
// just .unwrap() it here in this example.
let scanned_media = response.unwrap();
if scanned_media.matches_known_media() {
eprintln!("Uh-oh, this media: {:#?} matches known media so it is harmful.", scanned_media);
}
}
依赖项
~4–16MB
~235K SLoC