1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-07-22 03:05:32 +02:00

refactor: extract archive core crate

This commit is contained in:
TheGeneralist 2026-06-01 22:37:57 +02:00
parent 0b2afe6398
commit 3cf2c9cd3a
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4
14 changed files with 34 additions and 13 deletions

12
Cargo.lock generated
View file

@ -93,8 +93,20 @@ name = "archivr-cli"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"archivr-core",
"chrono", "chrono",
"clap", "clap",
"regex",
"rusqlite",
"serde_json",
]
[[package]]
name = "archivr-core"
version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"hex", "hex",
"regex", "regex",
"rusqlite", "rusqlite",

View file

@ -1,5 +1,6 @@
[workspace] [workspace]
members = [ members = [
"crates/archivr-core",
"crates/archivr-cli", "crates/archivr-cli",
] ]
resolver = "2" resolver = "2"

View file

@ -8,12 +8,10 @@ name = "archivr"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
archivr-core = { path = "../archivr-core" }
anyhow.workspace = true anyhow.workspace = true
chrono.workspace = true chrono.workspace = true
clap.workspace = true clap.workspace = true
hex.workspace = true
regex.workspace = true regex.workspace = true
rusqlite.workspace = true rusqlite.workspace = true
serde_json.workspace = true serde_json.workspace = true
sha3.workspace = true
uuid.workspace = true

View file

@ -1,4 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use archivr_core::{database, downloader, twitter::parse_tweet_id};
use chrono::Local; use chrono::Local;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use serde_json::json; use serde_json::json;
@ -9,11 +10,6 @@ use std::{
process, process,
}; };
mod database;
mod downloader;
mod hash;
mod twitter;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Args { struct Args {
@ -87,8 +83,6 @@ enum Source {
Other, Other,
} }
use crate::twitter::parse_tweet_id;
fn expand_shorthand_to_url(path: &str, source: &Source) -> String { fn expand_shorthand_to_url(path: &str, source: &Source) -> String {
if *source == Source::X && (path.starts_with("tweet:media:") || path.starts_with("x:media:")) { if *source == Source::X && (path.starts_with("tweet:media:") || path.starts_with("x:media:")) {
if let Some(tweet_id) = path.split(':').next_back().and_then(parse_tweet_id) { if let Some(tweet_id) = path.split(':').next_back().and_then(parse_tweet_id) {

View file

@ -0,0 +1,14 @@
[package]
name = "archivr-core"
version.workspace = true
edition.workspace = true
[dependencies]
anyhow.workspace = true
chrono.workspace = true
hex.workspace = true
regex.workspace = true
rusqlite.workspace = true
serde_json.workspace = true
sha3.workspace = true
uuid.workspace = true

View file

@ -10,9 +10,7 @@ use std::{
sync::OnceLock, sync::OnceLock,
}; };
use crate::twitter::parse_tweet_id; use crate::{downloader::store, twitter::parse_tweet_id};
use super::store;
/// Extracts a tweet ID from an archivr path like `"tweet:123"` by taking the /// Extracts a tweet ID from an archivr path like `"tweet:123"` by taking the
/// last colon-separated segment and validating it as a numeric ID. /// last colon-separated segment and validating it as a numeric ID.

View file

@ -0,0 +1,4 @@
pub mod database;
pub mod downloader;
pub mod hash;
pub mod twitter;