-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add akademik, koub, translite to fastside-actualizer (#21)
- Loading branch information
Showing
4 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{types::ServiceUpdater, ChangesSummary}; | ||
use async_trait::async_trait; | ||
use fastside_shared::serde_types::Instance; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
pub struct AkademikUpdater { | ||
pub instances_url: String, | ||
} | ||
|
||
impl AkademikUpdater { | ||
pub fn new() -> Self { | ||
Self { | ||
instances_url: | ||
"https://git.bloat.cat/gospodin/akademik/raw/branch/master/instances.json" | ||
.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for AkademikUpdater { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct AkademikInstance { | ||
url: Url, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct InstancesResponse(Vec<AkademikInstance>); | ||
|
||
#[async_trait] | ||
impl ServiceUpdater for AkademikUpdater { | ||
async fn update( | ||
&self, | ||
client: reqwest::Client, | ||
current_instances: &[Instance], | ||
changes_summary: ChangesSummary, | ||
) -> anyhow::Result<Vec<Instance>> { | ||
let response = client.get(&self.instances_url).send().await?; | ||
let response_str = response.text().await?; | ||
let parsed: InstancesResponse = serde_json::from_str(&response_str)?; | ||
|
||
let mut instances = current_instances.to_vec(); | ||
let mut new_instances = Vec::new(); | ||
|
||
for instance in parsed.0 { | ||
let url = instance.url; | ||
if current_instances.iter().any(|i| i.url == url) { | ||
continue; | ||
} | ||
new_instances.push(Instance::from(url.clone())); | ||
} | ||
|
||
changes_summary | ||
.set_new_instances_added( | ||
"akademik", | ||
new_instances.iter().map(|i| i.url.clone()).collect(), | ||
) | ||
.await; | ||
|
||
instances.extend(new_instances); | ||
|
||
Ok(instances) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{types::ServiceUpdater, ChangesSummary}; | ||
use async_trait::async_trait; | ||
use fastside_shared::serde_types::Instance; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
pub struct KoubUpdater { | ||
pub instances_url: String, | ||
} | ||
|
||
impl KoubUpdater { | ||
pub fn new() -> Self { | ||
Self { | ||
instances_url: "https://git.bloat.cat/gospodin/koub/raw/branch/master/instances.json" | ||
.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for KoubUpdater { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct KoubInstance { | ||
url: Url, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct InstancesResponse(Vec<KoubInstance>); | ||
|
||
#[async_trait] | ||
impl ServiceUpdater for KoubUpdater { | ||
async fn update( | ||
&self, | ||
client: reqwest::Client, | ||
current_instances: &[Instance], | ||
changes_summary: ChangesSummary, | ||
) -> anyhow::Result<Vec<Instance>> { | ||
let response = client.get(&self.instances_url).send().await?; | ||
let response_str = response.text().await?; | ||
let parsed: InstancesResponse = serde_json::from_str(&response_str)?; | ||
|
||
let mut instances = current_instances.to_vec(); | ||
let mut new_instances = Vec::new(); | ||
|
||
for instance in parsed.0 { | ||
let url = instance.url; | ||
if current_instances.iter().any(|i| i.url == url) { | ||
continue; | ||
} | ||
new_instances.push(Instance::from(url.clone())); | ||
} | ||
|
||
changes_summary | ||
.set_new_instances_added( | ||
"koub", | ||
new_instances.iter().map(|i| i.url.clone()).collect(), | ||
) | ||
.await; | ||
|
||
instances.extend(new_instances); | ||
|
||
Ok(instances) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{types::ServiceUpdater, ChangesSummary}; | ||
use async_trait::async_trait; | ||
use fastside_shared::serde_types::Instance; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
pub struct TransLiteUpdater { | ||
pub instances_url: String, | ||
} | ||
|
||
impl TransLiteUpdater { | ||
pub fn new() -> Self { | ||
Self { | ||
instances_url: | ||
"https://git.bloat.cat/gospodin/translite/raw/branch/master/instances.json" | ||
.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for TransLiteUpdater { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct TransLiteInstance { | ||
url: Url, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct InstancesResponse(Vec<TransLiteInstance>); | ||
|
||
#[async_trait] | ||
impl ServiceUpdater for TransLiteUpdater { | ||
async fn update( | ||
&self, | ||
client: reqwest::Client, | ||
current_instances: &[Instance], | ||
changes_summary: ChangesSummary, | ||
) -> anyhow::Result<Vec<Instance>> { | ||
let response = client.get(&self.instances_url).send().await?; | ||
let response_str = response.text().await?; | ||
let parsed: InstancesResponse = serde_json::from_str(&response_str)?; | ||
|
||
let mut instances = current_instances.to_vec(); | ||
let mut new_instances = Vec::new(); | ||
|
||
for instance in parsed.0 { | ||
let url = instance.url; | ||
if current_instances.iter().any(|i| i.url == url) { | ||
continue; | ||
} | ||
new_instances.push(Instance::from(url.clone())); | ||
} | ||
|
||
changes_summary | ||
.set_new_instances_added( | ||
"translite", | ||
new_instances.iter().map(|i| i.url.clone()).collect(), | ||
) | ||
.await; | ||
|
||
instances.extend(new_instances); | ||
|
||
Ok(instances) | ||
} | ||
} |