mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
nextcloud_login: Remove unused assets stuff
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
body {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{% block title %}RustiCal{% endblock %}</title>
|
<title>{% block title %}RustiCal{% endblock %}</title>
|
||||||
<link rel="stylesheet" href="/frontend/assets/style.css" />
|
|
||||||
{% block imports %}{% endblock %}
|
{% block imports %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use actix_web::{
|
|
||||||
body::BoxBody,
|
|
||||||
dev::{
|
|
||||||
HttpServiceFactory, ResourceDef, Service, ServiceFactory, ServiceRequest, ServiceResponse,
|
|
||||||
},
|
|
||||||
http::{header, Method},
|
|
||||||
HttpResponse,
|
|
||||||
};
|
|
||||||
use futures_core::future::LocalBoxFuture;
|
|
||||||
use rust_embed::RustEmbed;
|
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
|
||||||
#[folder = "public/assets"]
|
|
||||||
pub struct Assets;
|
|
||||||
|
|
||||||
pub struct EmbedService<E>
|
|
||||||
where
|
|
||||||
E: 'static + RustEmbed,
|
|
||||||
{
|
|
||||||
_embed: PhantomData<E>,
|
|
||||||
prefix: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> EmbedService<E>
|
|
||||||
where
|
|
||||||
E: 'static + RustEmbed,
|
|
||||||
{
|
|
||||||
pub fn new(prefix: String) -> Self {
|
|
||||||
Self {
|
|
||||||
prefix,
|
|
||||||
_embed: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> HttpServiceFactory for EmbedService<E>
|
|
||||||
where
|
|
||||||
E: 'static + RustEmbed,
|
|
||||||
{
|
|
||||||
fn register(self, config: &mut actix_web::dev::AppService) {
|
|
||||||
let resource_def = if config.is_root() {
|
|
||||||
ResourceDef::root_prefix(&self.prefix)
|
|
||||||
} else {
|
|
||||||
ResourceDef::prefix(&self.prefix)
|
|
||||||
};
|
|
||||||
config.register_service(resource_def, None, self, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> ServiceFactory<ServiceRequest> for EmbedService<E>
|
|
||||||
where
|
|
||||||
E: 'static + RustEmbed,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse;
|
|
||||||
type Error = actix_web::Error;
|
|
||||||
type Config = ();
|
|
||||||
type Service = EmbedService<E>;
|
|
||||||
type InitError = ();
|
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
|
||||||
|
|
||||||
fn new_service(&self, _: ()) -> Self::Future {
|
|
||||||
let prefix = self.prefix.clone();
|
|
||||||
Box::pin(async move {
|
|
||||||
Ok(Self {
|
|
||||||
prefix,
|
|
||||||
_embed: PhantomData,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> Service<ServiceRequest> for EmbedService<E>
|
|
||||||
where
|
|
||||||
E: 'static + RustEmbed,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse<BoxBody>;
|
|
||||||
type Error = actix_web::Error;
|
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
|
||||||
|
|
||||||
actix_web::dev::always_ready!();
|
|
||||||
|
|
||||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
|
||||||
Box::pin(async move {
|
|
||||||
if req.method() != Method::GET && req.method() != Method::HEAD {
|
|
||||||
return Ok(req.into_response(HttpResponse::MethodNotAllowed()));
|
|
||||||
}
|
|
||||||
let path = req.match_info().unprocessed().trim_start_matches('/');
|
|
||||||
|
|
||||||
match E::get(path) {
|
|
||||||
Some(file) => {
|
|
||||||
let data = file.data;
|
|
||||||
let hash = hex::encode(file.metadata.sha256_hash());
|
|
||||||
let mime = mime_guess::from_path(path).first_or_octet_stream();
|
|
||||||
|
|
||||||
let body = if req.method() == Method::HEAD {
|
|
||||||
Default::default()
|
|
||||||
} else {
|
|
||||||
data
|
|
||||||
};
|
|
||||||
Ok(req.into_response(
|
|
||||||
HttpResponse::Ok()
|
|
||||||
.content_type(mime)
|
|
||||||
.insert_header((header::ETAG, hash))
|
|
||||||
.body(body),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
None => Ok(req.into_response(HttpResponse::NotFound())),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,14 +4,12 @@ use actix_web::{
|
|||||||
HttpRequest, HttpResponse, Responder,
|
HttpRequest, HttpResponse, Responder,
|
||||||
};
|
};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use assets::{Assets, EmbedService};
|
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider, User};
|
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider, User};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
mod assets;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct NextcloudFlow {
|
struct NextcloudFlow {
|
||||||
@@ -212,7 +210,6 @@ pub fn configure_nextcloud_login<AP: AuthenticationProvider>(
|
|||||||
.wrap(AuthenticationMiddleware::new(auth_provider.clone()))
|
.wrap(AuthenticationMiddleware::new(auth_provider.clone()))
|
||||||
.app_data(Data::from(nextcloud_flows_state))
|
.app_data(Data::from(nextcloud_flows_state))
|
||||||
.app_data(Data::from(auth_provider.clone()))
|
.app_data(Data::from(auth_provider.clone()))
|
||||||
.service(EmbedService::<Assets>::new("/assets".to_owned()))
|
|
||||||
.service(web::resource("/index.php/login/v2").post(post_nextcloud_login))
|
.service(web::resource("/index.php/login/v2").post(post_nextcloud_login))
|
||||||
.service(
|
.service(
|
||||||
web::resource("/login/v2/poll/{flow}")
|
web::resource("/login/v2/poll/{flow}")
|
||||||
|
|||||||
Reference in New Issue
Block a user