feat(misc): add misc endpoints (currency-converter, harga-emas, kurs-bca, server-info)
Deploy Scraper / build-and-deploy (push) Canceled after 0s
Deploy Scraper / build-and-deploy (push) Canceled after 0s
Ported from Shirokami-API scraper/misc/*.js: - /misc/currency-converter (wise.com scrape, amount/from/to) - /misc/harga-emas (harga-emas.org Antam table) - /misc/kurs-bca (bca.co.id jual/beli) - /misc/server-info (OS/CPU/RAM/disk from /proc) Also: remove /download/tiktok/v2 + /download/twitter/v2 as separate routes; douyin.wtf + twitsave now internal fallback steps in the primary fetch_tiktok/fetch_twitter chains (v2 = fallback per user directive).
This commit is contained in:
@@ -227,22 +227,6 @@ pub async fn download_videy(
|
||||
Ok(Json(DownloadResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// Handler for _tiktok_v2.
|
||||
pub async fn download_tiktok_v2(
|
||||
Query(params): Query<DownloadParams>,
|
||||
) -> Result<Json<DownloadResponse>, AppError> {
|
||||
let result = use_cases::download_tiktok_v2(¶ms.url).await?;
|
||||
Ok(Json(DownloadResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// Handler for _twitter_v2.
|
||||
pub async fn download_twitter_v2(
|
||||
Query(params): Query<DownloadParams>,
|
||||
) -> Result<Json<DownloadResponse>, AppError> {
|
||||
let result = use_cases::download_twitter_v2(¶ms.url).await?;
|
||||
Ok(Json(DownloadResponse::ok(result)))
|
||||
}
|
||||
|
||||
/// Handler for _bilibili.
|
||||
pub async fn download_bilibili(
|
||||
Query(params): Query<DownloadParams>,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//! Axum handlers for misc utility endpoints.
|
||||
//!
|
||||
//! Ported from Shirokami-API `scraper/misc/*.js`.
|
||||
|
||||
use axum::extract::Query;
|
||||
use axum::http::StatusCode;
|
||||
use axum::Json;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::application::misc as use_cases;
|
||||
use crate::presentation::error::AppError;
|
||||
|
||||
/// Query params for currency converter.
|
||||
#[derive(Deserialize)]
|
||||
pub struct CurrencyParams {
|
||||
pub amount: Option<f64>,
|
||||
pub from: Option<String>,
|
||||
pub to: Option<String>,
|
||||
}
|
||||
|
||||
/// GET /misc/currency-converter?amount=100&from=USD&to=IDR
|
||||
pub async fn currency_converter_handler(
|
||||
Query(params): Query<CurrencyParams>,
|
||||
) -> Result<(StatusCode, Json<Value>), AppError> {
|
||||
let amount = params.amount.unwrap_or(1.0);
|
||||
let from = params.from.unwrap_or_else(|| "USD".to_string());
|
||||
let to = params.to.unwrap_or_else(|| "IDR".to_string());
|
||||
|
||||
let result = use_cases::currency_converter(amount, &from, &to).await?;
|
||||
Ok((StatusCode::OK, Json(result)))
|
||||
}
|
||||
|
||||
/// GET /misc/harga-emas
|
||||
pub async fn harga_emas_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
||||
let result = use_cases::harga_emas().await?;
|
||||
Ok((StatusCode::OK, Json(result)))
|
||||
}
|
||||
|
||||
/// GET /misc/kurs-bca
|
||||
pub async fn kurs_bca_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
||||
let result = use_cases::kurs_bca().await?;
|
||||
Ok((StatusCode::OK, Json(result)))
|
||||
}
|
||||
|
||||
/// GET /misc/server-info
|
||||
pub async fn server_info_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
||||
let result = use_cases::server_info().await?;
|
||||
Ok((StatusCode::OK, Json(result)))
|
||||
}
|
||||
@@ -3,4 +3,5 @@ pub mod anime2;
|
||||
pub mod downloader;
|
||||
pub mod health;
|
||||
pub mod komik;
|
||||
pub mod misc;
|
||||
pub mod proxy;
|
||||
|
||||
@@ -252,18 +252,27 @@ pub fn build_router(app_state: Arc<AppState>) -> anyhow::Result<Router> {
|
||||
"/download/videy",
|
||||
axum::routing::get(crate::presentation::handler::downloader::download_videy),
|
||||
)
|
||||
.route(
|
||||
"/download/tiktok/v2",
|
||||
axum::routing::get(crate::presentation::handler::downloader::download_tiktok_v2),
|
||||
)
|
||||
.route(
|
||||
"/download/twitter/v2",
|
||||
axum::routing::get(crate::presentation::handler::downloader::download_twitter_v2),
|
||||
)
|
||||
.route(
|
||||
"/download/bilibili",
|
||||
axum::routing::get(crate::presentation::handler::downloader::download_bilibili),
|
||||
)
|
||||
// Misc routes
|
||||
.route(
|
||||
"/misc/currency-converter",
|
||||
axum::routing::get(crate::presentation::handler::misc::currency_converter_handler),
|
||||
)
|
||||
.route(
|
||||
"/misc/harga-emas",
|
||||
axum::routing::get(crate::presentation::handler::misc::harga_emas_handler),
|
||||
)
|
||||
.route(
|
||||
"/misc/kurs-bca",
|
||||
axum::routing::get(crate::presentation::handler::misc::kurs_bca_handler),
|
||||
)
|
||||
.route(
|
||||
"/misc/server-info",
|
||||
axum::routing::get(crate::presentation::handler::misc::server_info_handler),
|
||||
)
|
||||
// Health
|
||||
.route(
|
||||
"/health",
|
||||
|
||||
Reference in New Issue
Block a user