invert path

This commit is contained in:
Lily Tsuru 2024-09-30 07:01:20 -04:00
parent 7e4f4caeda
commit eb36172d6a
2 changed files with 20 additions and 23 deletions

View file

@ -1,6 +1,6 @@
use std::{collections::HashMap, time::Duration};
use chrono::Timelike;
use chrono::{Datelike, Timelike};
use tokio::task::JoinHandle;
use tracing::{Instrument, Level};
@ -66,24 +66,33 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("Adding node {id} : {:?}", node);
let mut clone = tx.subscribe();
let path = config.root_path.join(id);
let zone = tzfile::Tz::named("GMT")?;
let now = { chrono::Utc::now().with_timezone(&&zone) };
let date_path = config.root_path.join(format!(
"{:02}-{:02}-{:02}",
now.year(),
now.month(),
now.day()
));
if !date_path.exists() {
std::fs::create_dir_all(&date_path)?;
}
let id_clone = id.clone();
let node_clone = node.clone();
let _: JoinHandle<anyhow::Result<()>> = tokio::spawn(async move {
while let Some(_) = clone.recv().await? {
let span = tracing::span!(
Level::INFO,
"node screenshot",
// FIXME: This should NOT be hardcoded
node = id_clone.as_str()
);
let span = tracing::span!(Level::INFO, "node screenshot", node = id_clone.as_str());
match shotter::take_one_screenshot(
&node_clone.url,
&node_clone.origin,
&id_clone,
path.clone(),
date_path.clone().join(&id_clone),
config.webp_quality,
)
.instrument(span)

View file

@ -4,7 +4,7 @@ use base64::{
engine::general_purpose::{GeneralPurpose, GeneralPurposeConfig},
Engine,
};
use chrono::{Datelike, Timelike};
use chrono::Timelike;
use tokio::task::JoinHandle;
use tokio_tungstenite::tungstenite::client::IntoClientRequest;
@ -111,22 +111,10 @@ pub async fn take_one_screenshot(
// Layer 0 is the screen (it's also the only layer cvmts sends)
if msg[1].as_str() == "0" {
if msg[3].as_str() == "0" && msg[4].as_str() == "0" {
// same as darok's stuff except i'm not keeping nanos
let zone = tzfile::Tz::named("GMT")?;
let now = { chrono::Utc::now().with_timezone(&&zone) };
let date_path = root_path.join(format!(
"{:02}-{:02}-{:02}",
now.year(),
now.month(),
now.day()
));
if !date_path.exists() {
std::fs::create_dir_all(&date_path)?;
}
let file_path = date_path.join(format!(
let file_path = root_path.join(format!(
"{:02}-{:02}-{:02}.webp",
now.hour(),
now.minute(),