use crate::BilibiliRequest;
use crate::BpiResult;
use crate::creativecenter::CreativeCenterClient;
use serde::{Deserialize, Serialize};
use serde_json::json;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EpisodeAdd {
pub title: String,
pub aid: u64,
pub cid: u64,
#[serde(default)]
pub charging_pay: i64,
#[serde(default)]
pub member_first: i64,
#[serde(default)]
pub limited_free: bool,
}
impl<'a> CreativeCenterClient<'a> {
pub async fn season_create(
&self,
title: &str,
desc: Option<&str>,
cover: &str,
season_price: Option<u32>,
) -> BpiResult<u64> {
let csrf = self.client.csrf()?;
let mut form = vec![
("title", title.to_string()),
("cover", cover.to_string()),
("csrf", csrf),
];
if let Some(d) = desc {
form.push(("desc", d.to_string()));
}
if let Some(price) = season_price {
form.push(("season_price", price.to_string()));
}
self.client
.post("https://member.bilibili.com/x2/creative/web/season/add")
.form(&form)
.send_bpi_payload("creativecenter.season.create")
.await
}
pub async fn season_delete(&self, season_id: u64) -> BpiResult<Option<serde_json::Value>> {
let csrf = self.client.csrf()?;
let form = vec![("id", season_id.to_string()), ("csrf", csrf)];
self.client
.post("https://member.bilibili.com/x2/creative/web/season/del")
.form(&form)
.send_bpi_optional_payload("creativecenter.season.delete")
.await
}
pub async fn season_episodes_add(
&self,
section_id: u64,
episodes: Vec<EpisodeAdd>,
) -> BpiResult<Option<serde_json::Value>> {
let csrf = self.client.csrf()?;
let payload = json!({
"sectionId": section_id,
"episodes": episodes
});
self.client
.post("https://member.bilibili.com/x2/creative/web/season/section/episodes/add")
.with_bilibili_headers()
.query(&[("csrf", csrf)])
.json(&payload)
.send_bpi_optional_payload("creativecenter.season.episodes.add")
.await
}
}
#[cfg(test)]
mod tests {}