commit
06be615b1c
@ -0,0 +1,24 @@
|
||||
|
||||
name: Publish a release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Login
|
||||
env:
|
||||
CRATES_IO_TOKEN: ${{secrets.CRATES_IO_TOKEN}}
|
||||
run: cargo login "$CRATES_IO_TOKEN"
|
||||
|
||||
- name: Publish to crates.io
|
||||
run: cargo publish --all-features
|
@ -0,0 +1,73 @@
|
||||
use crate::api_core::common::FileIdentifier;
|
||||
use crate::api_core::Endpoint;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct SetNotes;
|
||||
|
||||
impl Endpoint for SetNotes {
|
||||
type Request = SetNotesRequest;
|
||||
type Response = ();
|
||||
|
||||
fn path() -> String {
|
||||
String::from("add_notes/set_notes")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Debug, Default)]
|
||||
pub struct SetNotesRequest {
|
||||
notes: HashMap<String, String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
hash: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
file_id: Option<u64>,
|
||||
}
|
||||
|
||||
impl SetNotesRequest {
|
||||
pub fn new(id: FileIdentifier, notes: HashMap<String, String>) -> Self {
|
||||
let mut request = Self {
|
||||
notes,
|
||||
..Default::default()
|
||||
};
|
||||
match id {
|
||||
FileIdentifier::ID(id) => request.file_id = Some(id),
|
||||
FileIdentifier::Hash(hash) => request.hash = Some(hash),
|
||||
}
|
||||
|
||||
request
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DeleteNotes;
|
||||
|
||||
impl Endpoint for DeleteNotes {
|
||||
type Request = DeleteNotesRequest;
|
||||
type Response = ();
|
||||
|
||||
fn path() -> String {
|
||||
String::from("add_notes/delete_notes")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Debug, Default)]
|
||||
pub struct DeleteNotesRequest {
|
||||
note_names: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
hash: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
file_id: Option<u64>,
|
||||
}
|
||||
|
||||
impl DeleteNotesRequest {
|
||||
pub fn new(id: FileIdentifier, note_names: Vec<String>) -> Self {
|
||||
let mut request = Self {
|
||||
note_names,
|
||||
..Default::default()
|
||||
};
|
||||
match id {
|
||||
FileIdentifier::ID(id) => request.file_id = Some(id),
|
||||
FileIdentifier::Hash(hash) => request.hash = Some(hash),
|
||||
}
|
||||
|
||||
request
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
use crate::api_core::common::FileIdentifier;
|
||||
use crate::error::Result;
|
||||
use crate::Client;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Builder to create a request for adding notes to a given file
|
||||
pub struct AddNotesBuilder {
|
||||
client: Client,
|
||||
file: FileIdentifier,
|
||||
notes: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl AddNotesBuilder {
|
||||
/// Creates a new notes builder for the given file id
|
||||
pub fn new(client: Client, file: FileIdentifier) -> Self {
|
||||
Self {
|
||||
client,
|
||||
file,
|
||||
notes: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a single note
|
||||
pub fn add_note<S1: ToString, S2: ToString>(mut self, name: S1, note: S2) -> Self {
|
||||
self.notes.insert(name.to_string(), note.to_string());
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds multiple notes to the builder
|
||||
pub fn add_notes<I: IntoIterator<Item = (S1, S2)>, S1: ToString, S2: ToString>(
|
||||
mut self,
|
||||
notes: I,
|
||||
) -> Self {
|
||||
let notes_iter = notes
|
||||
.into_iter()
|
||||
.map(|(k, v): (S1, S2)| (k.to_string(), v.to_string()));
|
||||
self.notes.extend(notes_iter);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds all notes mentioned in the builder to the given file
|
||||
pub async fn run(self) -> Result<()> {
|
||||
self.client.set_notes(self.file, self.notes).await
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
use super::super::common;
|
||||
use crate::common::test_data::TEST_HASH_1;
|
||||
use hydrus_api::api_core::common::FileIdentifier;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_sets_notes() {
|
||||
let client = common::get_client();
|
||||
common::create_testdata(&client).await;
|
||||
let mut test_notes = HashMap::new();
|
||||
test_notes.insert("test".to_string(), "value".to_string());
|
||||
test_notes.insert("test2".to_string(), "value".to_string());
|
||||
|
||||
client
|
||||
.set_notes(FileIdentifier::hash(TEST_HASH_1), test_notes)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_deletes_notes() {
|
||||
let client = common::get_client();
|
||||
client
|
||||
.delete_notes(FileIdentifier::hash(TEST_HASH_1), vec!["test".to_string()])
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
pub const TEST_HASH_1: &str = "277a138cd1ee79fc1fdb2869c321b848d4861e45b82184487139ef66dd40b62d";
|
||||
pub const TEST_HASH_2: &str = "9641a590e66d9f2e5137b6bcba07fdf6cec3ffaa54de2565c3afcc2125ad1160";
|
||||
pub const EMPTY_HASH: &str = "0000000000000000000000000000000000000000000000000000000000000000";
|
||||
pub const TEST_HASHES: &[&str] = &[TEST_HASH_1, TEST_HASH_2];
|
||||
|
||||
pub const TEST_URL_1: &str =
|
||||
"https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium";
|
||||
pub const TEST_URL_2: &str = "https://yande.re/post/show/923576";
|
||||
pub const TEST_URLS: &[&str] = &[TEST_URL_1, TEST_URL_2];
|
||||
|
||||
pub fn get_test_hashes() -> Vec<String> {
|
||||
TEST_HASHES.iter().map(|h| String::from(*h)).collect()
|
||||
}
|
||||
|
||||
pub fn get_test_urls() -> Vec<String> {
|
||||
TEST_URLS.iter().map(|u| String::from(*u)).collect()
|
||||
}
|
Loading…
Reference in New Issue