mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
chore(license): relicense artwork and move non-free media out (#3173)
This commit is contained in:
1 parent
71b7cffabc
commit
e7347b582c
145 files changed
+806
-3424
No files matched your search
@@ -105,7 +105,7 @@ async fn resolve_html(ctx: &ResolveContext<'_>) -> anyhow::Result<ResolverResult
|
||||
http_client: ctx.http_client.clone(),
|
||||
nsfw_mode: ctx.nsfw_mode,
|
||||
media_proxy: ctx.media_proxy,
|
||||
static_cdn_endpoint: ctx.static_cdn_endpoint,
|
||||
self_hosted: ctx.self_hosted,
|
||||
youtube_api_key: ctx.youtube_api_key.clone(),
|
||||
klipy_api_key: ctx.klipy_api_key.clone(),
|
||||
};
|
||||
|
||||
@@ -1073,7 +1073,7 @@ mod tests {
|
||||
http_client: reqwest::Client::new(),
|
||||
nsfw_mode: crate::types::NsfwMode::Block,
|
||||
media_proxy,
|
||||
static_cdn_endpoint: "https://static.example.test",
|
||||
self_hosted: false,
|
||||
youtube_api_key: None,
|
||||
klipy_api_key: None,
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use url::Url;
|
||||
const HN_API_BASE: &str = "https://hacker-news.firebaseio.com/v0";
|
||||
const HN_SITE_BASE: &str = "https://news.ycombinator.com";
|
||||
const HN_COLOR: u32 = 0xFF6600;
|
||||
const HN_ICON_PATH: &str = "embeds/icons/hn.webp";
|
||||
const HN_ICON_URL: &str = "https://fluxer.app/static/img/app-hn-icon.4237980ebe2ba783.webp";
|
||||
const MAX_DESCRIPTION: usize = 400;
|
||||
|
||||
pub struct HackerNewsResolver;
|
||||
@@ -89,11 +89,7 @@ impl Resolver for HackerNewsResolver {
|
||||
embed.timestamp = Some(format_unix_timestamp(time));
|
||||
}
|
||||
|
||||
embed.footer = Some(EmbedFooter {
|
||||
text: "Hacker News".to_owned(),
|
||||
icon_url: ctx.static_asset_url(HN_ICON_PATH),
|
||||
..Default::default()
|
||||
});
|
||||
embed.footer = Some(hn_footer(ctx.self_hosted));
|
||||
|
||||
let has_title = item
|
||||
.item_type
|
||||
@@ -125,6 +121,14 @@ impl Resolver for HackerNewsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
fn hn_footer(self_hosted: bool) -> EmbedFooter {
|
||||
EmbedFooter {
|
||||
text: "Hacker News".to_owned(),
|
||||
icon_url: (!self_hosted).then(|| HN_ICON_URL.to_owned()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn format_unix_timestamp(secs: u64) -> String {
|
||||
chrono_lite(secs)
|
||||
}
|
||||
@@ -277,6 +281,13 @@ mod tests {
|
||||
assert!(!r.matches(&u("https://news.ycombinator.com/")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hn_footer_icon_is_hosted_only() {
|
||||
assert_eq!(hn_footer(false).icon_url.as_deref(), Some(HN_ICON_URL));
|
||||
assert_eq!(hn_footer(true).icon_url, None);
|
||||
assert_eq!(hn_footer(true).text, "Hacker News");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chrono_lite_leap_year() {
|
||||
assert_eq!(chrono_lite(1582934400), "2020-02-29T00:00:00Z");
|
||||
|
||||
@@ -25,21 +25,11 @@ pub struct ResolveContext<'mp> {
|
||||
pub http_client: reqwest::Client,
|
||||
pub nsfw_mode: NsfwMode,
|
||||
pub media_proxy: &'mp MediaProxyClient,
|
||||
pub static_cdn_endpoint: &'mp str,
|
||||
pub self_hosted: bool,
|
||||
pub youtube_api_key: Option<String>,
|
||||
pub klipy_api_key: Option<String>,
|
||||
}
|
||||
|
||||
impl ResolveContext<'_> {
|
||||
pub fn static_asset_url(&self, path: &str) -> Option<String> {
|
||||
let endpoint = self.static_cdn_endpoint.trim().trim_end_matches('/');
|
||||
if endpoint.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(format!("{}/{}", endpoint, path.trim_start_matches('/')))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ResolverResult {
|
||||
pub embeds: Vec<MessageEmbed>,
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ pub struct UnfurlShard {
|
||||
http_client: reqwest::Client,
|
||||
resolvers: Vec<Box<dyn crate::resolvers::Resolver>>,
|
||||
media_proxy: MediaProxyClient,
|
||||
static_cdn_endpoint: String,
|
||||
self_hosted: bool,
|
||||
}
|
||||
|
||||
impl UnfurlShard {
|
||||
@@ -37,11 +37,7 @@ impl UnfurlShard {
|
||||
let media_proxy_secret = optional_env("FLUXER_MEDIA_PROXY_SECRET_KEY");
|
||||
let media_proxy_public_endpoint = optional_env("FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT")
|
||||
.map(|v| fluxer_common::config::normalize_public_endpoint_from_env(&v));
|
||||
let static_cdn_endpoint = fluxer_common::config::normalize_public_endpoint_from_env(
|
||||
&optional_env("FLUXER_UNFURL_STATIC_CDN_ENDPOINT")
|
||||
.or_else(|| optional_env("FLUXER_STATIC_CDN_ENDPOINT"))
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let self_hosted = fluxer_common::config::read_bool_env("FLUXER_SELF_HOSTED", false);
|
||||
let (media_proxy_endpoint, media_proxy_secret) = match (
|
||||
media_proxy_endpoint,
|
||||
media_proxy_secret,
|
||||
@@ -81,7 +77,7 @@ impl UnfurlShard {
|
||||
http_client,
|
||||
resolvers,
|
||||
media_proxy,
|
||||
static_cdn_endpoint,
|
||||
self_hosted,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +99,7 @@ impl UnfurlShard {
|
||||
None,
|
||||
internal_http_client(),
|
||||
),
|
||||
static_cdn_endpoint: String::new(),
|
||||
self_hosted: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +124,7 @@ impl UnfurlShard {
|
||||
http_client: self.http_client.clone(),
|
||||
nsfw_mode,
|
||||
media_proxy: &self.media_proxy,
|
||||
static_cdn_endpoint: &self.static_cdn_endpoint,
|
||||
self_hosted: self.self_hosted,
|
||||
youtube_api_key: youtube_api_key.map(str::to_owned),
|
||||
klipy_api_key: klipy_api_key.map(str::to_owned),
|
||||
};
|
||||
@@ -328,12 +324,11 @@ mod tests {
|
||||
|
||||
static ENV_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
const PUBLIC_ENDPOINT_ENV: [&str; 8] = [
|
||||
const PUBLIC_ENDPOINT_ENV: [&str; 7] = [
|
||||
"FLUXER_MEDIA_PROXY_ENDPOINT",
|
||||
"FLUXER_MEDIA_PROXY_SECRET_KEY",
|
||||
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
|
||||
"FLUXER_UNFURL_STATIC_CDN_ENDPOINT",
|
||||
"FLUXER_STATIC_CDN_ENDPOINT",
|
||||
"FLUXER_SELF_HOSTED",
|
||||
"FLUXER_BASE_DOMAIN",
|
||||
"FLUXER_PUBLIC_PORT",
|
||||
"FLUXER_PUBLIC_ORIGIN",
|
||||
@@ -355,7 +350,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_non_default_public_port_reaches_the_public_media_and_static_endpoints() {
|
||||
fn a_non_default_public_port_reaches_the_public_media_endpoint() {
|
||||
let shard = shard_from_env(&[
|
||||
("FLUXER_MEDIA_PROXY_ENDPOINT", "http://media-proxy:8080"),
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
@@ -363,12 +358,10 @@ mod tests {
|
||||
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
|
||||
"http://fluxer.example/media",
|
||||
),
|
||||
("FLUXER_STATIC_CDN_ENDPOINT", "http://fluxer.example"),
|
||||
("FLUXER_BASE_DOMAIN", "fluxer.example"),
|
||||
("FLUXER_PUBLIC_PORT", "19080"),
|
||||
]);
|
||||
|
||||
assert_eq!(shard.static_cdn_endpoint, "http://fluxer.example:19080");
|
||||
assert!(
|
||||
shard
|
||||
.media_proxy
|
||||
@@ -379,7 +372,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_default_public_port_leaves_the_public_media_and_static_endpoints_alone() {
|
||||
fn a_default_public_port_leaves_the_public_media_endpoint_alone() {
|
||||
let shard = shard_from_env(&[
|
||||
("FLUXER_MEDIA_PROXY_ENDPOINT", "http://media-proxy:8080"),
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
@@ -387,12 +380,10 @@ mod tests {
|
||||
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
|
||||
"https://fluxer.example/media",
|
||||
),
|
||||
("FLUXER_STATIC_CDN_ENDPOINT", "https://fluxer.example"),
|
||||
("FLUXER_BASE_DOMAIN", "fluxer.example"),
|
||||
("FLUXER_PUBLIC_PORT", "443"),
|
||||
]);
|
||||
|
||||
assert_eq!(shard.static_cdn_endpoint, "https://fluxer.example");
|
||||
assert!(
|
||||
shard
|
||||
.media_proxy
|
||||
@@ -402,6 +393,18 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_hosted_follows_the_fluxer_self_hosted_env() {
|
||||
let media_proxy = [
|
||||
("FLUXER_MEDIA_PROXY_ENDPOINT", "http://media-proxy:8080"),
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
];
|
||||
assert!(!shard_from_env(&media_proxy).self_hosted);
|
||||
let mut vars = media_proxy.to_vec();
|
||||
vars.push(("FLUXER_SELF_HOSTED", "true"));
|
||||
assert!(shard_from_env(&vars).self_hosted);
|
||||
}
|
||||
|
||||
fn unfurl(url: &str, youtube_api_key: Option<&str>) -> UnfurlRequest {
|
||||
UnfurlRequest::Unfurl {
|
||||
url: url.to_owned(),
|
||||
|
||||
Reference in new issue
Block a user