Initial commit

This commit is contained in:
DavidOnTop 2024-01-28 18:21:51 +01:00
commit 1286a3d991
No known key found for this signature in database
GPG key ID: FAB914DDC2F180EB
7 changed files with 1485 additions and 0 deletions

18
src/index.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang='en' style='background-color: #222;'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='0;{{REDIRECT}}' />
<!-- <meta property='og:title' content='{{TITLE}}' /> -->
<meta property='og:description' content='{{DESCRIPTION}}' />
<!-- <meta property='og:site_name' content='{{SITENAME}}' /> -->
<meta property='og:image' content='{{IMAGE}}' />
<meta content="#{{COLOR}}" data-react-helmet="true" name="theme-color" />
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link type="application/json+oembed" href="https://e.davidon.top/json?title={{TITLE}}&title_url={{TITURL}}&provider={{PROV}}&provider_url={{PROVURL}}">
<title>Embed Generator</title>
</head>
<body>
</body>
</html>

67
src/main.rs Normal file
View file

@ -0,0 +1,67 @@
use actix_web::{HttpServer, App, get, web, Responder, HttpResponse};
use serde::Deserialize;
pub static HTML: &'static str = include_str!("./index.html");
pub static JSON: &'static str = include_str!("./prov.json");
#[derive(Deserialize)]
struct Params {
redirect: Option<String>,
title: Option<String>,
description: Option<String>,
sitename: Option<String>,
image: Option<String>,
color: Option<String>,
title_url: Option<String>,
sitename_url: Option<String>,
}
#[get("/")]
async fn index(info: web::Query<Params>) -> impl Responder {
let info = info.into_inner();
HttpResponse::Ok().content_type("text/html").body(HTML
.replace("{{REDIRECT}}", &info.redirect.unwrap_or("https://davidon.top".to_string()))
.replace("{{TITLE}}", &info.title.unwrap_or_default())
.replace("{{DESCRIPTION}}", &info.description.unwrap_or_default())
.replace("{{PROV}}", &info.sitename.unwrap_or_default())
.replace("{{IMAGE}}", &info.image.unwrap_or_default())
.replace("{{COLOR}}", &info.color.unwrap_or_default())
.replace("{{TITURL}}", &info.title_url.unwrap_or_default())
.replace("{{PROVURL}}", &info.sitename_url.unwrap_or_default())
)
}
#[derive(Deserialize)]
struct ParamsJson {
title: Option<String>,
title_url: Option<String>,
provider: Option<String>,
provider_url: Option<String>,
}
#[get("/json")]
async fn json(info: web::Query<ParamsJson>) -> impl Responder {
let info = info.into_inner();
HttpResponse::Ok().content_type("application/json").body(JSON
.replace("{{TITLE}}", &info.title.unwrap_or_default())
.replace("{{TITURL}}", &info.title_url.unwrap_or_default())
.replace("{{PROV}}", &info.provider.unwrap_or_default())
.replace("{{PROVURL}}", &info.provider_url.unwrap_or_default())
)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
tracing_subscriber::fmt::init();
HttpServer::new(|| {
App::new()
.service(index)
.service(json)
})
.bind(("127.0.0.1", 3596))?
.run()
.await
}

8
src/prov.json Normal file
View file

@ -0,0 +1,8 @@
{
"success": true,
"version": "1.0",
"author_name": "{{TITLE}}",
"author_url": "{{TITURL}}",
"provider_name": "{{PROV}}",
"provider_url": "{{PROVURL}}"
}