adding guids to the rss feed
This commit is contained in:
Generated
+678
-415
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
FROM rust:1.73-buster as builder
|
FROM rust:1.97-bookworm as builder
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ COPY ./Cargo.toml /build/Cargo.toml
|
|||||||
RUN rustup update nightly && rustup default nightly && \
|
RUN rustup update nightly && rustup default nightly && \
|
||||||
cargo clean && cargo build --release
|
cargo clean && cargo build --release
|
||||||
|
|
||||||
FROM debian:buster
|
FROM debian:bookworm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ RUN apt-get update && apt-get install libssl-dev -y
|
|||||||
|
|
||||||
RUN mkdir /store
|
RUN mkdir /store
|
||||||
|
|
||||||
RUN touch /store/store.xmlfrag && touch /store/tmpfile.xmlfrag
|
RUN touch /store/store.xmlfrag && touch /store/tmpfile.xmlfrag && touch /store/guid && echo "1" > /store/guid
|
||||||
|
|
||||||
COPY ./templates/ /app/templates
|
COPY ./templates/ /app/templates
|
||||||
|
|
||||||
CMD [ "/app/linky", "/store/store.xmlfrag", "/store/tmpfile.xmlfrag" ]
|
CMD [ "/app/linky", "/store/store.xmlfrag", "/store/tmpfile.xmlfrag", "/store/guid" ]
|
||||||
|
|||||||
+2
-3
@@ -1,4 +1,3 @@
|
|||||||
#![feature(lazy_cell)]
|
|
||||||
mod writer;
|
mod writer;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
@@ -27,12 +26,12 @@ static SECRET_KEY: LazyLock<Key> = LazyLock::new(Key::generate);
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
if args.len() < 3 {
|
if args.len() < 4 {
|
||||||
println!("Need file argument.");
|
println!("Need file argument.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = Arc::new(Mutex::new(LinkFile::new(&args[1], &args[2])));
|
let store = Arc::new(Mutex::new(LinkFile::new(&args[1], &args[2], &args[3])));
|
||||||
|
|
||||||
let authenticated = Router::new()
|
let authenticated = Router::new()
|
||||||
.route("/rss.xml", get(get_rss))
|
.route("/rss.xml", get(get_rss))
|
||||||
|
|||||||
+21
-3
@@ -5,7 +5,7 @@ use reqwest::Client;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::{Read, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
@@ -14,6 +14,7 @@ const TEMPLATE_STRING: &str = "
|
|||||||
<item>
|
<item>
|
||||||
<title> {{ title }} </title>
|
<title> {{ title }} </title>
|
||||||
<link> {{ link }} </link>
|
<link> {{ link }} </link>
|
||||||
|
<guid isPermaLink=\"false\"> {{ link }}/{{ guid }} </guid>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
";
|
";
|
||||||
@@ -22,6 +23,7 @@ pub struct LinkFile {
|
|||||||
client: Client,
|
client: Client,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
copy_path: PathBuf,
|
copy_path: PathBuf,
|
||||||
|
guid_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_link_title(client: &Client, link: &str) -> Result<String> {
|
async fn get_link_title(client: &Client, link: &str) -> Result<String> {
|
||||||
@@ -61,12 +63,17 @@ fn prepend_file(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LinkFile {
|
impl LinkFile {
|
||||||
pub fn new(path: impl AsRef<Path> + Clone, tempfile: impl AsRef<Path> + Clone) -> Self {
|
pub fn new(
|
||||||
|
path: impl AsRef<Path> + Clone,
|
||||||
|
tempfile: impl AsRef<Path> + Clone,
|
||||||
|
guidfile: impl AsRef<Path> + Clone,
|
||||||
|
) -> Self {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
Self {
|
Self {
|
||||||
client,
|
client,
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
copy_path: tempfile.as_ref().to_path_buf(),
|
copy_path: tempfile.as_ref().to_path_buf(),
|
||||||
|
guid_path: guidfile.as_ref().to_path_buf(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +83,16 @@ impl LinkFile {
|
|||||||
Err(_) => escape(link).to_string(),
|
Err(_) => escape(link).to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut guid_file = File::open(&self.guid_path)?;
|
||||||
|
|
||||||
|
let mut guid_string = String::new();
|
||||||
|
|
||||||
|
guid_file.read_to_string(&mut guid_string)?;
|
||||||
|
|
||||||
|
let guid: usize = str::parse(str::trim(&guid_string))?;
|
||||||
|
|
||||||
|
fs::write(&self.guid_path, format!("{}", guid + 1))?;
|
||||||
|
|
||||||
let mut env = Environment::new();
|
let mut env = Environment::new();
|
||||||
env.add_template("rss_fragment", TEMPLATE_STRING)?;
|
env.add_template("rss_fragment", TEMPLATE_STRING)?;
|
||||||
let template = env.get_template("rss_fragment")?;
|
let template = env.get_template("rss_fragment")?;
|
||||||
@@ -85,6 +102,7 @@ impl LinkFile {
|
|||||||
.render(context! {
|
.render(context! {
|
||||||
title => title,
|
title => title,
|
||||||
link => escape(link).to_string(),
|
link => escape(link).to_string(),
|
||||||
|
guid => format!("{}", guid),
|
||||||
})?
|
})?
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
self.path.clone(),
|
self.path.clone(),
|
||||||
@@ -106,7 +124,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_linkfile() {
|
fn test_linkfile() {
|
||||||
let mut linkfile = LinkFile::new("./store.xmlfrag", "./copy_store.xmlfrag");
|
let mut linkfile = LinkFile::new("./store.xmlfrag", "./copy_store.xmlfrag", "./guid");
|
||||||
linkfile.add_link("https://evilmuff.in").unwrap();
|
linkfile.add_link("https://evilmuff.in").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user