Compare commits

..

10 commits

Author SHA1 Message Date
d97d02c0df
arm 2024-07-25 23:48:11 +02:00
fec4912476
update 2024-07-25 23:19:15 +02:00
56a4dc46c1
update 2024-07-25 23:15:24 +02:00
2a093b3a88
update 2024-07-25 22:58:01 +02:00
065ab4979d
docker 2024-07-25 22:50:22 +02:00
717d343acc
forgejo 2024-07-15 21:39:16 +02:00
ba6cb5ea6d
fix bs 2024-07-13 05:40:10 +02:00
aa594ec1d8
fix ua 2024-07-10 22:18:23 +02:00
a14bf93302
fix content type 2024-07-10 22:14:19 +02:00
25931b97cf
update dockerfile 2024-07-10 22:00:58 +02:00
6 changed files with 61 additions and 44 deletions

View file

@ -0,0 +1,35 @@
name: deploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: host
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: git.hydrar.de
username: ${{ secrets.registry_user }}
password: ${{ secrets.registry_password }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: git.hydrar.de/jmarya/me-site:latest

View file

@ -1,25 +0,0 @@
name: deploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Docker
run: curl -fsSL https://get.docker.com | sh
- name: Log in to Docker registry
run: echo "${{ secrets.registry_password }}" | docker login -u "${{ secrets.registry_user }}" --password-stdin git.hydrar.de
- name: Build and push Docker image
run: |
docker build -t git.hydrar.de/jmarya/me-site:latest -t git.hydrar.de/jmarya/me-site:latest-amd64 .
docker push git.hydrar.de/jmarya/me-site:latest

View file

@ -5,10 +5,10 @@ WORKDIR /app
RUN cargo build --release
FROM archlinux
FROM debian:buster
RUN pacman -Syu --noconfirm
RUN pacman -S --noconfirm gnupg ca-certificates openssl-1.1
RUN apt update && apt upgrade -y
RUN apt install -y gnupg ca-certificates openssl
COPY --from=builder /app/target/release/me-site /me-site
COPY ./rocket.toml /rocket.toml

View file

@ -11,21 +11,17 @@ async fn download_file(url: &str, file: &str) {
#[get("/bootstrap.min.css")]
pub async fn bootstrap_css() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap.mi.await.ok()n.css")
.await
.ok()
NamedFile::open("./cache/bootstrap.min.css").await.ok()
}
#[get("/bootstrap-icons.css")]
pub async fn bootstrap_icons() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap-icon.await.ok()s.css")
.await
.ok()
NamedFile::open("./cache/bootstrap-icons.css").await.ok()
}
#[get("/bootstrap.bundle.min.js")]
pub async fn bootstrap_js() -> Option<NamedFile> {
NamedFile::open("./cache/bootstrap.b.await.ok()undle.min.js")
NamedFile::open("./cache/bootstrap.bundle.min.js")
.await
.ok()
}

View file

@ -1,5 +1,6 @@
use crate::config::Config;
use maud::{html, PreEscaped, DOCTYPE};
use rocket::http::ContentType;
use rocket::request::{FromRequest, Outcome, Request};
pub enum RequestClient {
@ -24,7 +25,7 @@ impl<'r> FromRequest<'r> for RequestClient {
pub fn is_browser(req: &Request) -> bool {
let ua = req
.headers()
.get("usesr-agent")
.get("User-Agent")
.next()
.unwrap()
.to_lowercase();
@ -37,7 +38,7 @@ pub async fn build_site(
disable_color: bool,
shadow: bool,
config: &Config,
) -> String {
) -> (ContentType, String) {
let mut c_class = "bg-dark text-white justify-content-center text-center".to_string();
let mut c_style = String::new();
let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string();
@ -64,7 +65,10 @@ pub async fn build_site(
};
};
build_site_from_body(title, &body.into_string())
(
ContentType::HTML,
build_site_from_body(title, &body.into_string()),
)
}
pub fn build_site_from_body(title: &str, body: &str) -> String {

View file

@ -1,5 +1,6 @@
use crate::config;
use maud::{html, PreEscaped};
use rocket::http::ContentType;
use rocket::{form::Form, get, post, response::Redirect, uri, FromForm, State};
use serde::{Deserialize, Serialize};
@ -19,7 +20,7 @@ pub async fn message_post(msg: Form<MessageForm>, config: &State<config::Config>
}
#[get("/message")]
pub async fn message_page(config: &State<config::Config>) -> String {
pub async fn message_page(config: &State<config::Config>) -> (ContentType, String) {
let post_uri = uri!(message_post).to_string();
let resp = html! {
@ -39,7 +40,10 @@ pub async fn message_page(config: &State<config::Config>) -> String {
}
#[get("/mirrors.txt")]
pub async fn mirrors(r: RequestClient, config: &State<config::Config>) -> Option<String> {
pub async fn mirrors(
r: RequestClient,
config: &State<config::Config>,
) -> Option<(ContentType, String)> {
if let Ok(mirror_file) = std::fs::File::open("./config/mirrors.txt") {
let content = std::io::read_to_string(mirror_file).ok()?;
if matches!(r, RequestClient::Browser) {
@ -53,14 +57,17 @@ pub async fn mirrors(r: RequestClient, config: &State<config::Config>) -> Option
return Some(build_site(resp.into_string(), "Mirrors", false, true, config).await);
}
return Some(content);
return Some((ContentType::Plain, content));
}
None
}
#[get("/public_key")]
pub async fn public_key(r: RequestClient, config: &State<config::Config>) -> Option<String> {
pub async fn public_key(
r: RequestClient,
config: &State<config::Config>,
) -> Option<(ContentType, String)> {
if matches!(r, RequestClient::Browser) {
let host = config.base_url();
let key = std::io::read_to_string(
@ -90,7 +97,7 @@ pub async fn public_key(r: RequestClient, config: &State<config::Config>) -> Opt
if let Ok(key_f) = std::fs::File::open("./config/pub.key") {
if let Ok(key_data) = std::io::read_to_string(key_f) {
return Some(key_data);
return Some((ContentType::Plain, key_data));
}
}
@ -160,7 +167,7 @@ fn build_donation_block(conf: &config::Config) -> String {
}
#[get("/")]
pub async fn index(conf: &State<config::Config>) -> String {
pub async fn index(conf: &State<config::Config>) -> (ContentType, String) {
let information_block = build_information_block(conf);
let contact_block = build_contact_block(conf);
let donation_block = build_donation_block(conf);