#![allow(missing_docs)]
#![allow(clippy::redundant_locals)]
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const DECOPY_API_HOST: &str = "api.decopy.ai";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const DECOPY_API_BASE: &str = "https://api.decopy.ai";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const DECOPY_CREATE_JOB_PATH: &str = "/api/decopy/youtube-video/create-job2";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const DECOPY_PRODUCT_CODE: &str = "067003";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const NOIZ_API_HOST: &str = "backend.noiz.io";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const NOIZ_API_BASE: &str = "https://backend.noiz.io";
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) const NOIZ_SUBTITLES_PATH: &str = "/api/landing/youtube/subtitles";
macro_rules! endpoint {
($name:ident, $key:literal, $default:ident, $doc:literal) => {
#[doc(hidden)]
#[doc = $doc]
pub(crate) fn $name() -> String {
crate::config::tuning_string_or($key, $default)
}
};
}
endpoint!(
decopy_api_host,
"net.endpoints.decopy.host",
DECOPY_API_HOST,
"Host of the decopy provider API."
);
endpoint!(
decopy_api_base,
"net.endpoints.decopy.base",
DECOPY_API_BASE,
"Scheme and authority of the decopy provider API."
);
endpoint!(
decopy_create_job_path,
"net.endpoints.decopy.create_job_path",
DECOPY_CREATE_JOB_PATH,
"Path of the decopy create-job endpoint."
);
endpoint!(
decopy_product_code,
"net.endpoints.decopy.product_code",
DECOPY_PRODUCT_CODE,
"Product code the decopy API requires."
);
endpoint!(
noiz_api_host,
"net.endpoints.noiz.host",
NOIZ_API_HOST,
"Host of the noiz provider API."
);
endpoint!(
noiz_api_base,
"net.endpoints.noiz.base",
NOIZ_API_BASE,
"Scheme and authority of the noiz provider API."
);
endpoint!(
noiz_subtitles_path,
"net.endpoints.noiz.subtitles_path",
NOIZ_SUBTITLES_PATH,
"Path of the noiz subtitles endpoint."
);
#[cfg(test)]
mod tests {
#[test]
fn every_reserved_constant_is_doc_hidden() {
let source = include_str!("secret_endpoints.rs");
let lines: Vec<&str> = source.lines().collect();
let mut undeclared = Vec::new();
for (index, line) in lines.iter().enumerate() {
if !line.trim_start().starts_with("pub(crate) const ") {
continue;
}
let hidden = lines[..index]
.iter()
.rev()
.take_while(|prior| prior.trim_start().starts_with('#'))
.any(|prior| prior.contains("doc(hidden)"));
if !hidden {
undeclared.push(*line);
}
}
assert!(
undeclared.is_empty(),
"reserved constants without #[doc(hidden)]: {undeclared:?}"
);
}
#[test]
fn every_endpoint_accessor_falls_back_to_its_constant() {
assert_eq!(super::decopy_api_host(), super::DECOPY_API_HOST);
assert_eq!(super::decopy_api_base(), super::DECOPY_API_BASE);
assert_eq!(
super::decopy_create_job_path(),
super::DECOPY_CREATE_JOB_PATH
);
assert_eq!(super::decopy_product_code(), super::DECOPY_PRODUCT_CODE);
assert_eq!(super::noiz_api_host(), super::NOIZ_API_HOST);
assert_eq!(super::noiz_api_base(), super::NOIZ_API_BASE);
assert_eq!(super::noiz_subtitles_path(), super::NOIZ_SUBTITLES_PATH);
}
#[test]
fn api_hosts_never_reach_the_public_readme() {
let reserved = [super::DECOPY_API_HOST, super::NOIZ_API_HOST];
for doc in ["README.md", "README.pt-BR.md"] {
let Ok(body) = std::fs::read_to_string(doc) else {
continue;
};
for host in reserved {
assert!(!body.contains(host), "{doc} names the reserved host {host}");
}
}
}
}