melatonin 0.9.1

A version manager for the BYOND environment
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use anyhow::{anyhow, Context, Result};
use std::str::FromStr;

use super::REQUEST_TIMEOUT;
use crate::byondversion::ByondVersion;

const MIRROR_VERSION_URL: &str = "https://spacestation13.github.io/byond-builds/version.txt";

pub(super) fn latest_version(beta: bool) -> Result<ByondVersion> {
	log::debug!("Fetching version data from {MIRROR_VERSION_URL}");
	let version_txt = minreq::get(MIRROR_VERSION_URL).with_timeout(REQUEST_TIMEOUT).send()?;
	let mut version_txt = version_txt.as_str()?.trim().lines();
	version_txt
		.nth(if beta { 1 } else { 0 })
		.ok_or(anyhow!("Could not find desired version in version.txt"))
		.and_then(|version| ByondVersion::from_str(version).context("Failed to parse BYOND version"))
}