mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 16:58:55 +00:00
Clean up unused beatmap ids
This commit is contained in:
parent
2cd5c744d6
commit
604be4ca9b
3 changed files with 7 additions and 9 deletions
|
@ -41,6 +41,7 @@
|
||||||
++ (with pkgs; [
|
++ (with pkgs; [
|
||||||
openssl
|
openssl
|
||||||
cargo
|
cargo
|
||||||
|
rustc
|
||||||
rustfmt
|
rustfmt
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn dot_osu_hook<'a>(
|
||||||
async move {
|
async move {
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let oppai = data.get::<BeatmapCache>().unwrap();
|
let oppai = data.get::<BeatmapCache>().unwrap();
|
||||||
let (beatmap, _) = oppai.download_beatmap_from_url(&url, None).await.ok()?;
|
let (beatmap, _) = oppai.download_beatmap_from_url(&url).await.ok()?;
|
||||||
let embed_fn = crate::discord::embeds::beatmap_offline_embed(
|
let embed_fn = crate::discord::embeds::beatmap_offline_embed(
|
||||||
&beatmap,
|
&beatmap,
|
||||||
Mode::from(beatmap.content.mode as u8), /*For now*/
|
Mode::from(beatmap.content.mode as u8), /*For now*/
|
||||||
|
|
|
@ -9,7 +9,6 @@ use youmubot_prelude::*;
|
||||||
/// the information collected from a download/Oppai request.
|
/// the information collected from a download/Oppai request.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BeatmapContent {
|
pub struct BeatmapContent {
|
||||||
id: Option<u64>,
|
|
||||||
pub metadata: MetadataSection,
|
pub metadata: MetadataSection,
|
||||||
pub content: Arc<Beatmap>,
|
pub content: Arc<Beatmap>,
|
||||||
}
|
}
|
||||||
|
@ -131,13 +130,12 @@ impl BeatmapCache {
|
||||||
BeatmapCache { client, pool }
|
BeatmapCache { client, pool }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_beatmap(content: impl AsRef<str>, id: Option<u64>) -> Result<BeatmapContent> {
|
fn parse_beatmap(content: impl AsRef<str>) -> Result<BeatmapContent> {
|
||||||
let content = content.as_ref();
|
let content = content.as_ref();
|
||||||
let metadata = osuparse::parse_beatmap(content)
|
let metadata = osuparse::parse_beatmap(content)
|
||||||
.map_err(|e| Error::msg(format!("Cannot parse metadata: {:?}", e)))?
|
.map_err(|e| Error::msg(format!("Cannot parse metadata: {:?}", e)))?
|
||||||
.metadata;
|
.metadata;
|
||||||
Ok(BeatmapContent {
|
Ok(BeatmapContent {
|
||||||
id,
|
|
||||||
metadata,
|
metadata,
|
||||||
content: Arc::new(Beatmap::parse(content.as_bytes())?),
|
content: Arc::new(Beatmap::parse(content.as_bytes())?),
|
||||||
})
|
})
|
||||||
|
@ -172,7 +170,7 @@ impl BeatmapCache {
|
||||||
};
|
};
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
v.read_to_string(&mut content).pls_ok()?;
|
v.read_to_string(&mut content).pls_ok()?;
|
||||||
Self::parse_beatmap(content, None).pls_ok()
|
Self::parse_beatmap(content).pls_ok()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Ok(osu_files)
|
Ok(osu_files)
|
||||||
|
@ -183,7 +181,6 @@ impl BeatmapCache {
|
||||||
pub async fn download_beatmap_from_url(
|
pub async fn download_beatmap_from_url(
|
||||||
&self,
|
&self,
|
||||||
url: impl reqwest::IntoUrl,
|
url: impl reqwest::IntoUrl,
|
||||||
id: Option<u64>,
|
|
||||||
) -> Result<(BeatmapContent, String)> {
|
) -> Result<(BeatmapContent, String)> {
|
||||||
let content = self
|
let content = self
|
||||||
.client
|
.client
|
||||||
|
@ -194,13 +191,13 @@ impl BeatmapCache {
|
||||||
.await?
|
.await?
|
||||||
.text()
|
.text()
|
||||||
.await?;
|
.await?;
|
||||||
let bm = Self::parse_beatmap(&content, id)?;
|
let bm = Self::parse_beatmap(&content)?;
|
||||||
Ok((bm, content))
|
Ok((bm, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_beatmap(&self, id: u64) -> Result<BeatmapContent> {
|
async fn download_beatmap(&self, id: u64) -> Result<BeatmapContent> {
|
||||||
let (bm, content) = self
|
let (bm, content) = self
|
||||||
.download_beatmap_from_url(&format!("https://osu.ppy.sh/osu/{}", id), Some(id))
|
.download_beatmap_from_url(&format!("https://osu.ppy.sh/osu/{}", id))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut bc = models::CachedBeatmapContent {
|
let mut bc = models::CachedBeatmapContent {
|
||||||
|
@ -215,7 +212,7 @@ impl BeatmapCache {
|
||||||
async fn get_beatmap_db(&self, id: u64) -> Result<Option<BeatmapContent>> {
|
async fn get_beatmap_db(&self, id: u64) -> Result<Option<BeatmapContent>> {
|
||||||
Ok(models::CachedBeatmapContent::by_id(id as i64, &self.pool)
|
Ok(models::CachedBeatmapContent::by_id(id as i64, &self.pool)
|
||||||
.await?
|
.await?
|
||||||
.map(|v| Self::parse_beatmap(String::from_utf8(v.content)?, Some(id)))
|
.map(|v| Self::parse_beatmap(String::from_utf8(v.content)?))
|
||||||
.transpose()?)
|
.transpose()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue