read meta table
This commit is contained in:
parent
43245624b1
commit
90fd380f70
1 changed files with 374 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
||||||
//! `config migrate 20240701` subcommand
|
//! `config migrate 20240701` subcommand
|
||||||
|
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use sqlx::{postgres::PgConnectOptions, ConnectOptions};
|
use sqlx::{postgres::PgConnectOptions, ConnectOptions};
|
||||||
use std::{collections::HashMap, env, fs, io::Read};
|
use std::{collections::HashMap, env, fs, io::Read};
|
||||||
use yaml_rust::{Yaml, YamlLoader};
|
use yaml_rust::{Yaml, YamlLoader};
|
||||||
|
@ -64,6 +66,7 @@ fn read_default_yml() -> Result<HashMap<String, Yaml>, ReadYamlConfigError> {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Meta {
|
struct Meta {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
|
@ -79,14 +82,14 @@ struct Meta {
|
||||||
enable_recaptcha: bool,
|
enable_recaptcha: bool,
|
||||||
recaptcha_site_key: Option<String>,
|
recaptcha_site_key: Option<String>,
|
||||||
recaptcha_secret_key: Option<String>,
|
recaptcha_secret_key: Option<String>,
|
||||||
local_drive_capacity_mb: u64,
|
local_drive_capacity_mb: i32,
|
||||||
remote_drive_capacity_mb: u64,
|
remote_drive_capacity_mb: i32,
|
||||||
summaly_proxy: Option<String>,
|
summaly_proxy: Option<String>,
|
||||||
enable_email: bool,
|
enable_email: bool,
|
||||||
email: Option<String>,
|
email: Option<String>,
|
||||||
smtp_secure: bool,
|
smtp_secure: bool,
|
||||||
smtp_host: Option<String>,
|
smtp_host: Option<String>,
|
||||||
smtp_port: Option<u16>,
|
smtp_port: Option<i32>,
|
||||||
smtp_user: Option<String>,
|
smtp_user: Option<String>,
|
||||||
smtp_pass: Option<String>,
|
smtp_pass: Option<String>,
|
||||||
enable_service_worker: bool,
|
enable_service_worker: bool,
|
||||||
|
@ -104,12 +107,12 @@ struct Meta {
|
||||||
object_storage_region: Option<String>,
|
object_storage_region: Option<String>,
|
||||||
object_storage_access_key: Option<String>,
|
object_storage_access_key: Option<String>,
|
||||||
object_storage_secret_key: Option<String>,
|
object_storage_secret_key: Option<String>,
|
||||||
object_storage_port: u16,
|
object_storage_port: Option<i32>,
|
||||||
object_storage_use_ssl: bool,
|
object_storage_use_ssl: bool,
|
||||||
object_storage_set_public_read: bool,
|
object_storage_set_public_read: bool,
|
||||||
object_storage_s3_force_path_style: bool,
|
object_storage_s3_force_path_style: bool,
|
||||||
proxy_account_id: String,
|
|
||||||
object_storage_use_proxy: bool,
|
object_storage_use_proxy: bool,
|
||||||
|
proxy_account_id: Option<String>,
|
||||||
enable_hcaptcha: bool,
|
enable_hcaptcha: bool,
|
||||||
hcaptcha_site_key: Option<String>,
|
hcaptcha_site_key: Option<String>,
|
||||||
hcaptcha_secret_key: Option<String>,
|
hcaptcha_secret_key: Option<String>,
|
||||||
|
@ -139,7 +142,8 @@ struct Meta {
|
||||||
enable_identicon_generation: bool,
|
enable_identicon_generation: bool,
|
||||||
donation_link: Option<String>,
|
donation_link: Option<String>,
|
||||||
mark_local_files_nsfw_by_default: bool,
|
mark_local_files_nsfw_by_default: bool,
|
||||||
antenna_limit: u8,
|
antenna_limit: i32,
|
||||||
|
// TODO:
|
||||||
// more_urls: jsonb
|
// more_urls: jsonb
|
||||||
// experimental_features: jsonb
|
// experimental_features: jsonb
|
||||||
}
|
}
|
||||||
|
@ -150,7 +154,7 @@ async fn read_meta_table(
|
||||||
username: &str,
|
username: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
database: &str,
|
database: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<Meta, sqlx::Error> {
|
||||||
let mut conn = PgConnectOptions::new()
|
let mut conn = PgConnectOptions::new()
|
||||||
.host(host)
|
.host(host)
|
||||||
.port(port)
|
.port(port)
|
||||||
|
@ -160,14 +164,368 @@ async fn read_meta_table(
|
||||||
.connect()
|
.connect()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (disable_local_timeline,): (bool,) =
|
let (
|
||||||
sqlx::query_as(r#"SELECT "disableLocalTimeline" FROM "meta""#)
|
name,
|
||||||
.fetch_one(&mut conn)
|
description,
|
||||||
.await?;
|
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<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
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<String>,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<i32>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Vec<String>,
|
||||||
|
Option<String>,
|
||||||
|
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<String>,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<i32>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
) = 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<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Vec<String>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
) = 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<String>,
|
||||||
|
Vec<String>,
|
||||||
|
bool,
|
||||||
|
Vec<String>,
|
||||||
|
bool,
|
||||||
|
String,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
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> {
|
pub(super) async fn run() -> Result<(), Error> {
|
||||||
|
@ -177,7 +535,7 @@ pub(super) async fn run() -> Result<(), Error> {
|
||||||
println!("{}:\n {:?}", k, v);
|
println!("{}:\n {:?}", k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
read_meta_table(
|
let meta = read_meta_table(
|
||||||
old_config["db"]["host"].as_str().unwrap(),
|
old_config["db"]["host"].as_str().unwrap(),
|
||||||
old_config["db"]["port"].as_i64().unwrap() as u16,
|
old_config["db"]["port"].as_i64().unwrap() as u16,
|
||||||
old_config["db"]["user"].as_str().unwrap(),
|
old_config["db"]["user"].as_str().unwrap(),
|
||||||
|
@ -186,5 +544,7 @@ pub(super) async fn run() -> Result<(), Error> {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
println!("Meta: {:#?}", meta);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue