|
| 1 | +use actix_web::{ResponseError, http::StatusCode}; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | +use thiserror::Error; |
| 4 | + |
| 5 | +#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)] |
| 6 | +pub enum LegacyVersion { |
| 7 | + #[serde(rename = "1.8.9")] |
| 8 | + OneEightNine, |
| 9 | + #[serde(rename = "1.12.2")] |
| 10 | + OneTwelveTwo |
| 11 | +} |
| 12 | + |
| 13 | +#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)] |
| 14 | +#[serde(rename_all = "lowercase")] |
| 15 | +pub enum LegacyLoader { |
| 16 | + Forge |
| 17 | +} |
| 18 | + |
| 19 | +impl LegacyLoader { |
| 20 | + pub fn get_loader_type(&self) -> &'static str { |
| 21 | + match self { |
| 22 | + LegacyLoader::Forge => "launchwrapper" |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)] |
| 28 | +pub struct LegacyArtifact { |
| 29 | + pub url: String, |
| 30 | + pub sha256: String |
| 31 | +} |
| 32 | + |
| 33 | +#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)] |
| 34 | +pub struct LegacyArtifactsResponse { |
| 35 | + pub release: LegacyArtifact, |
| 36 | + pub snapshot: LegacyArtifact, |
| 37 | + pub loader: LegacyArtifact |
| 38 | +} |
| 39 | + |
| 40 | +#[derive(Debug, Error)] |
| 41 | +pub enum LegacyArtifactsErrorResponse { |
| 42 | + #[error("unable to serialize serde enum variant name: {0}")] |
| 43 | + EnumVariantSerialization(#[source] serde_variant::UnsupportedType), |
| 44 | + #[error("unable to connect to maven: {0}")] |
| 45 | + MavenFetch(#[source] reqwest::Error), |
| 46 | + #[error("maven request returned non-2xx status code: {0}")] |
| 47 | + MavenResponse(#[source] reqwest::Error), |
| 48 | + #[error("decoding maven metadata response failed: {0}")] |
| 49 | + MavenMetadataDecoding(#[source] reqwest::Error), |
| 50 | + #[error("parsing maven metadata response as XML failed: {0}")] |
| 51 | + MavenMetadataParsing(#[source] maven::parsing::maven::ParseError) |
| 52 | +} |
| 53 | + |
| 54 | +impl ResponseError for LegacyArtifactsErrorResponse { |
| 55 | + fn status_code(&self) -> StatusCode { StatusCode::INTERNAL_SERVER_ERROR } |
| 56 | + |
| 57 | + // TODO: Implement RFC9457 problem details |
| 58 | +} |
0 commit comments