+
Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

feat/changelog #253

Merged
merged 6 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The sections should follow the order `Packaging`, `Added`, `Changed`, `Fixed` an

## [Unreleased]
### Added
- It is now possible to open the addon website for more information by pressing the title in the catalog
- When pressing on either `local` or `remote` version in MyAddons you will see the changelog
- When pressing on the addon title inside the catalog Ajour will open the addon website

## [0.4.1] - 2020-10-11
### Added
Expand Down
24 changes: 24 additions & 0 deletions crates/core/src/addon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use std::path::PathBuf;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AddonVersionKey {
Local,
Remote,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RemotePackage {
pub version: String,
Expand Down Expand Up @@ -103,6 +109,12 @@ pub struct Addon {
#[cfg(feature = "gui")]
pub details_btn_state: iced_native::button::State,
#[cfg(feature = "gui")]
pub remote_btn_state: iced_native::button::State,
#[cfg(feature = "gui")]
pub local_btn_state: iced_native::button::State,
#[cfg(feature = "gui")]
pub full_changelog_btn_state: iced_native::button::State,
#[cfg(feature = "gui")]
pub update_btn_state: iced_native::button::State,
#[cfg(feature = "gui")]
pub force_btn_state: iced_native::button::State,
Expand Down Expand Up @@ -154,6 +166,12 @@ impl Addon {
#[cfg(feature = "gui")]
details_btn_state: Default::default(),
#[cfg(feature = "gui")]
remote_btn_state: Default::default(),
#[cfg(feature = "gui")]
local_btn_state: Default::default(),
#[cfg(feature = "gui")]
full_changelog_btn_state: Default::default(),
#[cfg(feature = "gui")]
update_btn_state: Default::default(),
#[cfg(feature = "gui")]
force_btn_state: Default::default(),
Expand Down Expand Up @@ -192,6 +210,12 @@ impl Addon {
#[cfg(feature = "gui")]
details_btn_state: Default::default(),
#[cfg(feature = "gui")]
remote_btn_state: Default::default(),
#[cfg(feature = "gui")]
local_btn_state: Default::default(),
#[cfg(feature = "gui")]
full_changelog_btn_state: Default::default(),
#[cfg(feature = "gui")]
update_btn_state: Default::default(),
#[cfg(feature = "gui")]
force_btn_state: Default::default(),
Expand Down
21 changes: 21 additions & 0 deletions crates/core/src/curse_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
config::Flavor,
error::ClientError,
network::{post_json_async, request_async},
utility::{regex_html_tags_to_newline, regex_html_tags_to_space, truncate},
Result,
};
use isahc::prelude::*;
Expand Down Expand Up @@ -129,6 +130,26 @@ pub async fn fetch_remote_packages_by_ids(curse_ids: &[u32]) -> Result<Vec<Packa
}
}

pub async fn fetch_changelog(id: u32, file_id: i64) -> Result<(String, String)> {
let url = format!("{}/addon/{}/file/{}/changelog", API_ENDPOINT, id, file_id);
let client = HttpClient::builder().build().unwrap();
let mut resp = request_async(&client, &url.clone(), vec![], None).await?;

if resp.status().is_success() {
let changelog: String = resp.text()?;

let c = regex_html_tags_to_newline()
.replace_all(&changelog, "\n")
.to_string();
let c = regex_html_tags_to_space().replace_all(&c, "").to_string();
let c = truncate(&c, 2500).to_string();

return Ok((c, url));
}

Ok(("No changelog found.".to_owned(), url))
}

pub async fn fetch_game_info() -> Result<GameInfo> {
let url = format!("{}/game/1", API_ENDPOINT);
let client = HttpClient::builder().build().unwrap();
Expand Down
59 changes: 58 additions & 1 deletion crates/core/src/tukui_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
use crate::{addon::Addon, config::Flavor, error::ClientError, network::request_async, Result};
use crate::{
addon::Addon,
config::Flavor,
error::ClientError,
network::request_async,
utility::{regex_html_tags_to_newline, regex_html_tags_to_space, truncate},
Result,
};
use isahc::config::RedirectPolicy;
use isahc::prelude::*;
use serde::Deserialize;
Expand Down Expand Up @@ -29,6 +36,20 @@ fn api_endpoint(id: &str, flavor: &Flavor) -> String {
}
}

fn changelog_endpoint(id: &str, flavor: &Flavor) -> String {
match flavor {
Flavor::Retail => match id {
"-1" => "https://www.tukui.org/ui/tukui/changelog".to_owned(),
"-2" => "https://www.tukui.org/ui/elvui/changelog".to_owned(),
_ => format!("https://www.tukui.org/addons.php?id={}&changelog", id),
},
Flavor::Classic => format!(
"https://www.tukui.org/classic-addons.php?id={}&changelog",
id
),
}
}

/// Function to fetch a remote addon package which contains
/// information about the addon on the repository.
pub async fn fetch_remote_package(id: &str, flavor: &Flavor) -> Result<TukuiPackage> {
Expand Down Expand Up @@ -75,3 +96,39 @@ pub async fn latest_stable_addon_from_id(

Ok((tukui_id, flavor, addon))
}

pub async fn fetch_changelog(id: &str, flavor: &Flavor) -> Result<(String, String)> {
let url = changelog_endpoint(id, &flavor);

match flavor {
Flavor::Retail => {
// Only TukUI and ElvUI main addons has changelog which can be fetched.
// The others is embeded into a page.
if id == "-1" || id == "-2" {
let client = HttpClient::builder().build().unwrap();
let mut resp = request_async(&client, &url.clone(), vec![], None).await?;

if resp.status().is_success() {
let changelog: String = resp.text()?;

let c = regex_html_tags_to_newline()
.replace_all(&changelog, "\n")
.to_string();
let c = regex_html_tags_to_space().replace_all(&c, "").to_string();
let c = truncate(&c, 2500).to_string();

return Ok((c, url));
}

return Ok(("No changelog found".to_string(), url));
}

Ok(("Please view this changelog in the browser by pressing 'Full Changelog' to the right".to_string(), url))
}
Flavor::Classic => Ok((
"Please view this changelog in the browser by pressing 'Full Changelog' to the right"
.to_string(),
url,
)),
}
}
15 changes: 15 additions & 0 deletions crates/core/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ pub fn strip_non_digits(string: &str) -> Option<String> {
Some(stripped)
}

pub fn truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
None => s,
Some((idx, _)) => &s[..idx],
}
}

pub fn regex_html_tags_to_newline() -> Regex {
regex::Regex::new(r"<br ?/?>|#.\s").unwrap()
}

pub fn regex_html_tags_to_space() -> Regex {
regex::Regex::new(r"&nbsp;|&quot;|&lt;|&gt;|&amp;|gt;|lt;|&#x27;|<.+?>").unwrap()
}

#[derive(Deserialize)]
struct Release {
tag_name: String,
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载