diff --git a/src/command/config/migrate/v20240701.rs b/src/command/config/migrate/v20240701.rs index 9bf19e0..7eb366e 100644 --- a/src/command/config/migrate/v20240701.rs +++ b/src/command/config/migrate/v20240701.rs @@ -1,5 +1,7 @@ //! `config migrate 20240701` subcommand +#![allow(clippy::type_complexity)] + use sqlx::{postgres::PgConnectOptions, ConnectOptions}; use std::{collections::HashMap, env, fs, io::Read}; use yaml_rust::{Yaml, YamlLoader}; @@ -64,6 +66,7 @@ fn read_default_yml() -> Result, ReadYamlConfigError> { Ok(res) } +#[derive(Debug)] struct Meta { name: Option, description: Option, @@ -79,14 +82,14 @@ struct Meta { enable_recaptcha: bool, recaptcha_site_key: Option, recaptcha_secret_key: Option, - local_drive_capacity_mb: u64, - remote_drive_capacity_mb: u64, + local_drive_capacity_mb: i32, + remote_drive_capacity_mb: i32, summaly_proxy: Option, enable_email: bool, email: Option, smtp_secure: bool, smtp_host: Option, - smtp_port: Option, + smtp_port: Option, smtp_user: Option, smtp_pass: Option, enable_service_worker: bool, @@ -104,12 +107,12 @@ struct Meta { object_storage_region: Option, object_storage_access_key: Option, object_storage_secret_key: Option, - object_storage_port: u16, + object_storage_port: Option, object_storage_use_ssl: bool, object_storage_set_public_read: bool, object_storage_s3_force_path_style: bool, - proxy_account_id: String, object_storage_use_proxy: bool, + proxy_account_id: Option, enable_hcaptcha: bool, hcaptcha_site_key: Option, hcaptcha_secret_key: Option, @@ -139,7 +142,8 @@ struct Meta { enable_identicon_generation: bool, donation_link: Option, mark_local_files_nsfw_by_default: bool, - antenna_limit: u8, + antenna_limit: i32, + // TODO: // more_urls: jsonb // experimental_features: jsonb } @@ -150,7 +154,7 @@ async fn read_meta_table( username: &str, password: &str, database: &str, -) -> Result<(), sqlx::Error> { +) -> Result { let mut conn = PgConnectOptions::new() .host(host) .port(port) @@ -160,14 +164,368 @@ async fn read_meta_table( .connect() .await?; - let (disable_local_timeline,): (bool,) = - sqlx::query_as(r#"SELECT "disableLocalTimeline" FROM "meta""#) - .fetch_one(&mut conn) - .await?; + let ( + name, + description, + maintainer_name, + maintainer_email, + disable_registration, + disable_local_timeline, + disable_global_timeline, + banner_url, + error_image_url, + icon_url, + cache_remote_files, + enable_recaptcha, + recaptcha_site_key, + recaptcha_secret_key, + local_drive_capacity_mb, + ): ( + Option, + Option, + Option, + Option, + bool, + bool, + bool, + Option, + Option, + Option, + bool, + bool, + Option, + Option, + i32, + ) = sqlx::query_as( + r#" + SELECT + "name", + "description", + "maintainerName", + "maintainerEmail", + "disableRegistration", + "disableLocalTimeline", + "disableGlobalTimeline", + "bannerUrl", + "errorImageUrl", + "iconUrl", + "cacheRemoteFiles", + "enableRecaptcha", + "recaptchaSiteKey", + "recaptchaSecretKey", + "localDriveCapacityMb" + FROM + "meta" + "#, + ) + .fetch_one(&mut conn) + .await?; - println!("enable_local_timeline: {}", !disable_local_timeline); + let ( + remote_drive_capacity_mb, + summaly_proxy, + enable_email, + email, + smtp_secure, + smtp_host, + smtp_port, + smtp_user, + smtp_pass, + enable_service_worker, + sw_public_key, + sw_private_key, + pinned_users, + tos_url, + repository_url, + ): ( + i32, + Option, + bool, + Option, + bool, + Option, + Option, + Option, + Option, + bool, + Option, + Option, + Vec, + Option, + String, + ) = sqlx::query_as( + r#" + SELECT + "remoteDriveCapacityMb", + "summalyProxy", + "enableEmail", + "email", + "smtpSecure", + "smtpHost", + "smtpPort", + "smtpUser", + "smtpPass", + "enableServiceWorker", + "swPublicKey", + "swPrivateKey", + "pinnedUsers", + "tosUrl", + "repositoryUrl" + FROM + "meta" + "#, + ) + .fetch_one(&mut conn) + .await?; - Ok(()) + let ( + feedback_url, + use_object_storage, + object_storage_bucket, + object_storage_prefix, + object_storage_base_url, + object_storage_endpoint, + object_storage_region, + object_storage_access_key, + object_storage_secret_key, + object_storage_port, + object_storage_use_ssl, + object_storage_set_public_read, + object_storage_s3_force_path_style, + object_storage_use_proxy, + proxy_account_id, + ): ( + Option, + bool, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + bool, + bool, + bool, + bool, + Option, + ) = sqlx::query_as( + r#" + SELECT + "feedbackUrl", + "useObjectStorage", + "objectStorageBucket", + "objectStoragePrefix", + "objectStorageBaseUrl", + "objectStorageEndpoint", + "objectStorageRegion", + "objectStorageAccessKey", + "objectStorageSecretKey", + "objectStoragePort", + "objectStorageUseSsl", + "objectStorageSetPublicRead", + "objectStorageS3ForcePathStyle", + "objectStorageUseProxy", + "proxyAccountId" + FROM + "meta" + "#, + ) + .fetch_one(&mut conn) + .await?; + + let ( + enable_hcaptcha, + hcaptcha_site_key, + hcaptcha_secret_key, + background_image_url, + logo_image_url, + pinned_clip_id, + allowed_hosts, + secure_mode, + private_mode, + deepl_auth_key, + deepl_is_pro, + email_required_for_signup, + theme_color, + default_light_theme, + default_dark_theme, + ): ( + bool, + Option, + Option, + Option, + Option, + Option, + Vec, + bool, + bool, + Option, + bool, + bool, + Option, + Option, + Option, + ) = sqlx::query_as( + r#" + SELECT + "enableHcaptcha", + "hcaptchaSiteKey", + "hcaptchaSecretKey", + "backgroundImageUrl", + "logoImageUrl", + "pinnedClipId", + "allowedHosts", + "secureMode", + "privateMode", + "deeplAuthKey", + "deeplIsPro", + "emailRequiredForSignup", + "themeColor", + "defaultLightTheme", + "defaultDarkTheme" + FROM + "meta" + "#, + ) + .fetch_one(&mut conn) + .await?; + + let ( + enable_ip_logging, + enable_active_email_validation, + custom_motd, + custom_splash_icons, + disable_recommended_timeline, + recommended_instances, + enable_guest_timeline, + default_reaction, + libre_translate_api_url, + libre_translate_api_key, + enable_server_machine_stats, + enable_identicon_generation, + donation_link, + mark_local_files_nsfw_by_default, + antenna_limit, + ): ( + bool, + bool, + Vec, + Vec, + bool, + Vec, + bool, + String, + Option, + Option, + bool, + bool, + Option, + bool, + i32, + ) = sqlx::query_as( + r#" + SELECT + "enableIpLogging", + "enableActiveEmailValidation", + "customMotd", + "customSplashIcons", + "disableRecommendedTimeline", + "recommendedInstances", + "enableGuestTimeline", + "defaultReaction", + "libreTranslateApiUrl", + "libreTranslateApiKey", + "enableServerMachineStats", + "enableIdenticonGeneration", + "donationLink", + "markLocalFilesNsfwByDefault", + "antennaLimit" + FROM + "meta" + "#, + ) + .fetch_one(&mut conn) + .await?; + + Ok(Meta { + name, + description, + maintainer_name, + maintainer_email, + disable_registration, + disable_local_timeline, + disable_global_timeline, + banner_url, + error_image_url, + icon_url, + cache_remote_files, + enable_recaptcha, + recaptcha_site_key, + recaptcha_secret_key, + local_drive_capacity_mb, + remote_drive_capacity_mb, + summaly_proxy, + enable_email, + email, + smtp_secure, + smtp_host, + smtp_port, + smtp_user, + smtp_pass, + enable_service_worker, + sw_public_key, + sw_private_key, + pinned_users, + tos_url, + repository_url, + feedback_url, + use_object_storage, + object_storage_bucket, + object_storage_prefix, + object_storage_base_url, + object_storage_endpoint, + object_storage_region, + object_storage_access_key, + object_storage_secret_key, + object_storage_port, + object_storage_use_ssl, + object_storage_set_public_read, + object_storage_s3_force_path_style, + object_storage_use_proxy, + proxy_account_id, + enable_hcaptcha, + hcaptcha_site_key, + hcaptcha_secret_key, + background_image_url, + logo_image_url, + pinned_clip_id, + allowed_hosts, + secure_mode, + private_mode, + deepl_auth_key, + deepl_is_pro, + email_required_for_signup, + theme_color, + default_light_theme, + default_dark_theme, + enable_ip_logging, + enable_active_email_validation, + custom_motd, + custom_splash_icons, + disable_recommended_timeline, + recommended_instances, + enable_guest_timeline, + default_reaction, + libre_translate_api_url, + libre_translate_api_key, + enable_server_machine_stats, + enable_identicon_generation, + donation_link, + mark_local_files_nsfw_by_default, + antenna_limit, + }) } pub(super) async fn run() -> Result<(), Error> { @@ -177,7 +535,7 @@ pub(super) async fn run() -> Result<(), Error> { println!("{}:\n {:?}", k, v); } - read_meta_table( + let meta = read_meta_table( old_config["db"]["host"].as_str().unwrap(), old_config["db"]["port"].as_i64().unwrap() as u16, old_config["db"]["user"].as_str().unwrap(), @@ -186,5 +544,7 @@ pub(super) async fn run() -> Result<(), Error> { ) .await?; + println!("Meta: {:#?}", meta); + Ok(()) }