Compare commits

...

4 commits

Author SHA1 Message Date
asonix e1707212a2 Bump version
Some checks failed
continuous-integration/drone/push Build is failing
2023-11-13 12:56:25 -06:00
asonix 3044b103fc Update dependencies (major) 2023-11-13 12:55:40 -06:00
asonix 2c0f40e2b5 Update dependencies (minor & point) 2023-11-13 12:30:09 -06:00
asonix 6c08946354 Add IDs to entries on edit page, set fragment when modifying entry 2023-11-13 12:29:50 -06:00
7 changed files with 791 additions and 642 deletions

1305
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
[package]
name = "pict-rs-aggregator"
description = "A simple image aggregation service for pict-rs"
version = "0.5.0-alpha.1"
version = "0.5.0-beta.1"
authors = ["asonix <asonix@asonix.dog>"]
license = "AGPL-3.0"
readme = "README.md"
@ -18,13 +18,14 @@ default = []
actix-rt = "2.7.0"
actix-web = { version = "4.0.0", default-features = false }
awc = { version = "3.0.0", default-features = false }
bcrypt = "0.14"
bcrypt = "0.15"
clap = { version = "4.0.2", features = ["derive", "env"] }
console-subscriber = "0.1"
console-subscriber = "0.2"
mime = "0.3"
minify-html = "0.11.1"
opentelemetry = { version = "0.19", features = ["rt-tokio"] }
opentelemetry-otlp = "0.12"
opentelemetry = "0.21"
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio"] }
opentelemetry-otlp = "0.14"
qrcodegen = "1.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
@ -34,8 +35,8 @@ thiserror = "1.0"
tracing = "0.1"
tracing-error = "0.2"
tracing-futures = "0.2"
tracing-log = "0.1"
tracing-opentelemetry = "0.19"
tracing-log = "0.2"
tracing-opentelemetry = "0.22"
tracing-subscriber = { version = "0.3", features = [
"ansi",
"env-filter",
@ -46,18 +47,18 @@ uuid = { version = "1", features = ["serde", "v4"] }
[dependencies.tracing-actix-web]
version = "0.7.5"
version = "0.7.8"
default-features = false
features = ["emit_event_on_error", "opentelemetry_0_19"]
features = ["emit_event_on_error", "opentelemetry_0_21"]
[dependencies.tracing-awc]
version = "0.1.7"
version = "0.1.8"
default-features = false
features = ["emit_event_on_error", "opentelemetry_0_19"]
features = ["emit_event_on_error", "opentelemetry_0_21"]
[dev-dependencies]
ructe = "0.16.0"
ructe = "0.17.0"
[build-dependencies]
dotenv = "0.15.0"
ructe = { version = "0.16.0", features = ["sass", "mime03"] }
ructe = { version = "0.17.0", features = ["sass", "mime03"] }

View file

@ -173,12 +173,21 @@ impl State {
self.scoped("")
}
fn edit_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{id}?token={}", token.token))
fn edit_collection_path(
&self,
collection_id: Uuid,
entry_id: Option<Uuid>,
token: &ValidToken,
) -> String {
if let Some(entry_id) = entry_id {
self.scoped(&format!("{collection_id}?token={}#{entry_id}", token.token))
} else {
self.scoped(&format!("{collection_id}?token={}", token.token))
}
}
fn update_collection_path(&self, id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{id}?token={}", token.token))
fn update_collection_path(&self, collection_id: Uuid, token: &ValidToken) -> String {
self.scoped(&format!("{collection_id}?token={}", token.token))
}
fn delete_collection_path(&self, id: Uuid, token: &ValidToken, confirmed: bool) -> String {
@ -314,9 +323,17 @@ pub fn configure(cfg: &mut web::ServiceConfig, state: State, client: Client) {
);
}
fn to_edit_page(id: Uuid, token: &ValidToken, state: &State) -> HttpResponse {
fn to_edit_page(
collection_id: Uuid,
entry_id: Option<Uuid>,
token: &ValidToken,
state: &State,
) -> HttpResponse {
HttpResponse::SeeOther()
.insert_header((LOCATION, state.edit_collection_path(id, token)))
.insert_header((
LOCATION,
state.edit_collection_path(collection_id, entry_id, token),
))
.finish()
}
@ -696,7 +713,12 @@ async fn upload(
.await
.stateful(&state)?;
Ok(to_edit_page(path.collection, &token, &state))
Ok(to_edit_page(
path.collection,
Some(entry_path.entry),
&token,
&state,
))
}
#[derive(Debug, serde::Deserialize)]
@ -845,6 +867,7 @@ async fn create_collection(
Ok(to_edit_page(
collection_path.collection,
None,
&ValidToken { token: token.token },
&state,
))
@ -865,7 +888,7 @@ async fn update_collection(
.await
.stateful(&state)?;
Ok(to_edit_page(path.collection, &token, &state))
Ok(to_edit_page(path.collection, None, &token, &state))
}
async fn move_entry(
@ -880,7 +903,12 @@ async fn move_entry(
.await
.stateful(&state)?;
Ok(to_edit_page(path.collection, &token, &state))
Ok(to_edit_page(
path.collection,
Some(path.entry),
&token,
&state,
))
}
#[tracing::instrument(name = "Update Entry")]
@ -898,7 +926,12 @@ async fn update_entry(
.await
.stateful(&state)?;
Ok(to_edit_page(entry_path.collection, &token, &state))
Ok(to_edit_page(
entry_path.collection,
Some(entry_path.entry),
&token,
&state,
))
}
#[derive(Debug, serde::Deserialize)]
@ -953,7 +986,7 @@ async fn delete_entry(
.await
.stateful(&state)?;
Ok(to_edit_page(entry_path.collection, &token, &state))
Ok(to_edit_page(entry_path.collection, None, &token, &state))
}
fn qr(req: &HttpRequest, path: &web::Path<CollectionPath>, state: &web::Data<State>) -> String {

View file

@ -2,11 +2,9 @@ use actix_web::{App, HttpServer};
use awc::Client;
use clap::Parser;
use console_subscriber::ConsoleLayer;
use opentelemetry::{
sdk::{propagation::TraceContextPropagator, Resource},
KeyValue,
};
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
use std::time::Duration;
use tracing::subscriber::set_global_default;
use tracing_actix_web::TracingLogger;
@ -102,18 +100,19 @@ where
for<'a> S: LookupSpan<'a>,
{
if let Some(url) = opentelemetry_url {
let tracer =
opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
Resource::new(vec![KeyValue::new("service.name", "pict-rs-aggregator")]),
))
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(url.as_str()),
)
.install_batch(opentelemetry::runtime::Tokio)?;
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![
KeyValue::new("service.name", "pict-rs-aggregator"),
])),
)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(url.as_str()),
)
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let otel_layer = tracing_opentelemetry::layer()
.with_tracer(tracer)

View file

@ -18,7 +18,7 @@
<div class="content-group">
<div class="button-group">
@:button_link_html("Delete Collection", &state.delete_collection_path(id, token, true), ButtonKind::Submit)
@:button_link_html("Cancel", &state.edit_collection_path(id, token), ButtonKind::Outline)
@:button_link_html("Cancel", &state.edit_collection_path(id, None, token), ButtonKind::Outline)
</div>
</div>
</article>

View file

@ -21,7 +21,7 @@
<p class="delete-confirmation">Are you sure you want to delete this image?</p>
<div class="button-group button-space">
@:button_link_html("Delete Image", &state.delete_entry_path(collection_id, id, token, true), ButtonKind::Submit)
@:button_link_html("Cancel", &state.edit_collection_path(collection_id, token), ButtonKind::Outline)
@:button_link_html("Cancel", &state.edit_collection_path(collection_id, Some(id), token), ButtonKind::Outline)
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
@use crate::{ui::ButtonKind, Collection, Direction, Entry, State, ValidToken};
@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html, text_input_html,
statics::file_upload_js};
@use super::{button_html, button_link_html, image_html, file_input_html, layout_html, return_home_html, text_area_html,
text_input_html, statics::file_upload_js};
@use uuid::Uuid;
@(collection: &Collection, collection_id: Uuid, entries: &[(Uuid, Entry)], token: &ValidToken, state: &State, qr: &str)
@ -29,7 +29,7 @@ statics::file_upload_js};
<h3>Edit Collection</h3>
</article>
<article class="content-group">
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, token)">Do not lose this link</a></p>
<p class="subtitle"><a href="@state.edit_collection_path(collection_id, None, token)">Do not lose this link</a></p>
</article>
<article class="content-group">
<form method="POST" action="@state.update_collection_path(collection_id, token)">
@ -44,7 +44,7 @@ statics::file_upload_js};
</article>
<ul>
@for (i, (id, entry)) in entries.iter().enumerate() {
<li class="content-group">
<li class="content-group" id="@id">
<article>
<div class="edit-row">
<div class="edit-item">
@ -61,7 +61,8 @@ statics::file_upload_js};
<div class="button-group button-space">
@if let Some(upload_id) = entry.upload_id() {
<input type="hidden" name="upload_id" value="@upload_id" />
@:button_link_html("Refresh", &state.edit_collection_path(collection_id, token), ButtonKind::Submit)
@:button_link_html("Refresh", &state.edit_collection_path(collection_id, Some(*id), token),
ButtonKind::Submit)
}
@if let Some((filename, delete_token)) = entry.file_parts() {
<input type="hidden" name="filename" value="@filename" />