You've already forked AstralRinth
forked from didirus/AstralRinth
Links (#763)
This commit is contained in:
@@ -3,8 +3,8 @@ use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models;
|
||||
use crate::models::ids::ImageId;
|
||||
use crate::models::projects::{DonationLink, Loader, Project, ProjectStatus};
|
||||
use crate::models::v2::projects::{LegacyProject, LegacySideType};
|
||||
use crate::models::projects::{Loader, Project, ProjectStatus};
|
||||
use crate::models::v2::projects::{DonationLink, LegacyProject, LegacySideType};
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::v3::project_creation::default_project_type;
|
||||
use crate::routes::v3::project_creation::{CreateError, NewGalleryItem};
|
||||
@@ -193,6 +193,25 @@ pub async fn project_create(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut link_urls = HashMap::new();
|
||||
if let Some(issue_url) = legacy_create.issues_url {
|
||||
link_urls.insert("issues".to_string(), issue_url);
|
||||
}
|
||||
if let Some(source_url) = legacy_create.source_url {
|
||||
link_urls.insert("source".to_string(), source_url);
|
||||
}
|
||||
if let Some(wiki_url) = legacy_create.wiki_url {
|
||||
link_urls.insert("wiki".to_string(), wiki_url);
|
||||
}
|
||||
if let Some(discord_url) = legacy_create.discord_url {
|
||||
link_urls.insert("discord".to_string(), discord_url);
|
||||
}
|
||||
if let Some(donation_urls) = legacy_create.donation_urls {
|
||||
for donation_url in donation_urls {
|
||||
link_urls.insert(donation_url.platform, donation_url.url);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(v3::project_creation::ProjectCreateData {
|
||||
title: legacy_create.title,
|
||||
slug: legacy_create.slug,
|
||||
@@ -201,12 +220,8 @@ pub async fn project_create(
|
||||
initial_versions,
|
||||
categories: legacy_create.categories,
|
||||
additional_categories: legacy_create.additional_categories,
|
||||
issues_url: legacy_create.issues_url,
|
||||
source_url: legacy_create.source_url,
|
||||
wiki_url: legacy_create.wiki_url,
|
||||
license_url: legacy_create.license_url,
|
||||
discord_url: legacy_create.discord_url,
|
||||
donation_urls: legacy_create.donation_urls,
|
||||
link_urls,
|
||||
is_draft: legacy_create.is_draft,
|
||||
license_id: legacy_create.license_id,
|
||||
gallery_items: legacy_create.gallery_items,
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
use crate::database::models::categories::LinkPlatform;
|
||||
use crate::database::models::{project_item, version_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models;
|
||||
use crate::models::projects::{
|
||||
DonationLink, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
||||
Link, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
||||
};
|
||||
use crate::models::v2::projects::{LegacyProject, LegacySideType};
|
||||
use crate::models::v2::projects::{DonationLink, LegacyProject, LegacySideType};
|
||||
use crate::models::v2::search::LegacySearchResults;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::v3::projects::ProjectIds;
|
||||
use crate::routes::{v2_reroute, v3, ApiError};
|
||||
use crate::search::{search_for_project, SearchConfig, SearchError};
|
||||
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
|
||||
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -360,18 +361,78 @@ pub async fn project_edit(
|
||||
// - change the loaders to mrpack only
|
||||
// - add categories to the project for the corresponding loaders
|
||||
|
||||
let mut new_links = HashMap::new();
|
||||
if let Some(issues_url) = v2_new_project.issues_url {
|
||||
if let Some(issues_url) = issues_url {
|
||||
new_links.insert("issues".to_string(), Some(issues_url));
|
||||
} else {
|
||||
new_links.insert("issues".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(source_url) = v2_new_project.source_url {
|
||||
if let Some(source_url) = source_url {
|
||||
new_links.insert("source".to_string(), Some(source_url));
|
||||
} else {
|
||||
new_links.insert("source".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(wiki_url) = v2_new_project.wiki_url {
|
||||
if let Some(wiki_url) = wiki_url {
|
||||
new_links.insert("wiki".to_string(), Some(wiki_url));
|
||||
} else {
|
||||
new_links.insert("wiki".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(discord_url) = v2_new_project.discord_url {
|
||||
if let Some(discord_url) = discord_url {
|
||||
new_links.insert("discord".to_string(), Some(discord_url));
|
||||
} else {
|
||||
new_links.insert("discord".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
// In v2, setting donation links resets all other donation links
|
||||
// (resetting to the new ones)
|
||||
if let Some(donation_urls) = v2_new_project.donation_urls {
|
||||
// Fetch current donation links from project so we know what to delete
|
||||
let fetched_example_project = project_item::Project::get(&info.0, &**pool, &redis).await?;
|
||||
let donation_links = fetched_example_project
|
||||
.map(|x| {
|
||||
x.urls
|
||||
.into_iter()
|
||||
.filter_map(|l| {
|
||||
if l.donation {
|
||||
Some(Link::from(l)) // TODO: tests
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
// Set existing donation links to None
|
||||
for old_link in donation_links {
|
||||
new_links.insert(old_link.platform, None);
|
||||
}
|
||||
|
||||
// Add new donation links
|
||||
for donation_url in donation_urls {
|
||||
new_links.insert(donation_url.id, Some(donation_url.url));
|
||||
}
|
||||
}
|
||||
|
||||
let new_project = v3::projects::EditProject {
|
||||
title: v2_new_project.title,
|
||||
description: v2_new_project.description,
|
||||
body: v2_new_project.body,
|
||||
categories: v2_new_project.categories,
|
||||
additional_categories: v2_new_project.additional_categories,
|
||||
issues_url: v2_new_project.issues_url,
|
||||
source_url: v2_new_project.source_url,
|
||||
wiki_url: v2_new_project.wiki_url,
|
||||
license_url: v2_new_project.license_url,
|
||||
discord_url: v2_new_project.discord_url,
|
||||
donation_urls: v2_new_project.donation_urls,
|
||||
link_urls: Some(new_links),
|
||||
license_id: v2_new_project.license_id,
|
||||
slug: v2_new_project.slug,
|
||||
status: v2_new_project.status,
|
||||
@@ -500,6 +561,70 @@ pub async fn projects_edit(
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let bulk_edit_project = bulk_edit_project.into_inner();
|
||||
|
||||
let mut link_urls = HashMap::new();
|
||||
|
||||
// If we are *setting* donation links, we will set every possible donation link to None, as
|
||||
// setting will delete all of them then 're-add' the ones we want to keep
|
||||
if let Some(donation_url) = bulk_edit_project.donation_urls {
|
||||
let link_platforms = LinkPlatform::list(&**pool, &redis).await?;
|
||||
for link in link_platforms {
|
||||
if link.donation {
|
||||
link_urls.insert(link.name, None);
|
||||
}
|
||||
}
|
||||
// add
|
||||
for donation_url in donation_url {
|
||||
link_urls.insert(donation_url.id, Some(donation_url.url));
|
||||
}
|
||||
}
|
||||
|
||||
// For every delete, we will set the link to None
|
||||
if let Some(donation_url) = bulk_edit_project.remove_donation_urls {
|
||||
for donation_url in donation_url {
|
||||
link_urls.insert(donation_url.id, None);
|
||||
}
|
||||
}
|
||||
|
||||
// For every add, we will set the link to the new url
|
||||
if let Some(donation_url) = bulk_edit_project.add_donation_urls {
|
||||
for donation_url in donation_url {
|
||||
link_urls.insert(donation_url.id, Some(donation_url.url));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(issue_url) = bulk_edit_project.issues_url {
|
||||
if let Some(issue_url) = issue_url {
|
||||
link_urls.insert("issues".to_string(), Some(issue_url));
|
||||
} else {
|
||||
link_urls.insert("issues".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(source_url) = bulk_edit_project.source_url {
|
||||
if let Some(source_url) = source_url {
|
||||
link_urls.insert("source".to_string(), Some(source_url));
|
||||
} else {
|
||||
link_urls.insert("source".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(wiki_url) = bulk_edit_project.wiki_url {
|
||||
if let Some(wiki_url) = wiki_url {
|
||||
link_urls.insert("wiki".to_string(), Some(wiki_url));
|
||||
} else {
|
||||
link_urls.insert("wiki".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(discord_url) = bulk_edit_project.discord_url {
|
||||
if let Some(discord_url) = discord_url {
|
||||
link_urls.insert("discord".to_string(), Some(discord_url));
|
||||
} else {
|
||||
link_urls.insert("discord".to_string(), None);
|
||||
}
|
||||
}
|
||||
|
||||
v3::projects::projects_edit(
|
||||
req,
|
||||
web::Query(ids),
|
||||
@@ -511,13 +636,7 @@ pub async fn projects_edit(
|
||||
additional_categories: bulk_edit_project.additional_categories,
|
||||
add_additional_categories: bulk_edit_project.add_additional_categories,
|
||||
remove_additional_categories: bulk_edit_project.remove_additional_categories,
|
||||
donation_urls: bulk_edit_project.donation_urls,
|
||||
add_donation_urls: bulk_edit_project.add_donation_urls,
|
||||
remove_donation_urls: bulk_edit_project.remove_donation_urls,
|
||||
issues_url: bulk_edit_project.issues_url,
|
||||
source_url: bulk_edit_project.source_url,
|
||||
wiki_url: bulk_edit_project.wiki_url,
|
||||
discord_url: bulk_edit_project.discord_url,
|
||||
link_urls: Some(link_urls),
|
||||
}),
|
||||
redis,
|
||||
session_queue,
|
||||
|
||||
@@ -4,7 +4,9 @@ use super::ApiError;
|
||||
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::v2::projects::LegacySideType;
|
||||
use crate::routes::v3::tags::{LoaderData as LoaderDataV3, LoaderFieldsEnumQuery};
|
||||
use crate::routes::v3::tags::{
|
||||
LinkPlatformQueryData, LoaderData as LoaderDataV3, LoaderFieldsEnumQuery,
|
||||
};
|
||||
use crate::routes::{v2_reroute, v3};
|
||||
use actix_web::{get, web, HttpResponse};
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -164,8 +166,10 @@ pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse,
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct DonationPlatformQueryData {
|
||||
short: String,
|
||||
name: String,
|
||||
// The difference between name and short is removed in v3.
|
||||
// Now, the 'id' becomes the name, and the 'name' is removed (the frontend uses the id as the name)
|
||||
// pub short: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[get("donation_platform")]
|
||||
@@ -173,7 +177,21 @@ pub async fn donation_platform_list(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
v3::tags::donation_platform_list(pool, redis).await
|
||||
let response = v3::tags::link_platform_list(pool, redis).await?;
|
||||
|
||||
// Convert to V2 format
|
||||
Ok(
|
||||
match v2_reroute::extract_ok_json::<Vec<LinkPlatformQueryData>>(response).await {
|
||||
Ok(platforms) => {
|
||||
let platforms = platforms
|
||||
.into_iter()
|
||||
.map(|p| DonationPlatformQueryData { name: p.name })
|
||||
.collect::<Vec<_>>();
|
||||
HttpResponse::Ok().json(platforms)
|
||||
}
|
||||
Err(response) => response,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[get("report_type")]
|
||||
|
||||
Reference in New Issue
Block a user