adding guids to the rss feed
This commit is contained in:
+2
-3
@@ -1,4 +1,3 @@
|
||||
#![feature(lazy_cell)]
|
||||
mod writer;
|
||||
|
||||
use axum::{
|
||||
@@ -27,12 +26,12 @@ static SECRET_KEY: LazyLock<Key> = LazyLock::new(Key::generate);
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() < 3 {
|
||||
if args.len() < 4 {
|
||||
println!("Need file argument.");
|
||||
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()
|
||||
.route("/rss.xml", get(get_rss))
|
||||
|
||||
+21
-3
@@ -5,7 +5,7 @@ use reqwest::Client;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
@@ -14,6 +14,7 @@ const TEMPLATE_STRING: &str = "
|
||||
<item>
|
||||
<title> {{ title }} </title>
|
||||
<link> {{ link }} </link>
|
||||
<guid isPermaLink=\"false\"> {{ link }}/{{ guid }} </guid>
|
||||
</item>
|
||||
|
||||
";
|
||||
@@ -22,6 +23,7 @@ pub struct LinkFile {
|
||||
client: Client,
|
||||
path: PathBuf,
|
||||
copy_path: PathBuf,
|
||||
guid_path: PathBuf,
|
||||
}
|
||||
|
||||
async fn get_link_title(client: &Client, link: &str) -> Result<String> {
|
||||
@@ -61,12 +63,17 @@ fn prepend_file(
|
||||
}
|
||||
|
||||
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();
|
||||
Self {
|
||||
client,
|
||||
path: path.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(),
|
||||
};
|
||||
|
||||
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();
|
||||
env.add_template("rss_fragment", TEMPLATE_STRING)?;
|
||||
let template = env.get_template("rss_fragment")?;
|
||||
@@ -85,6 +102,7 @@ impl LinkFile {
|
||||
.render(context! {
|
||||
title => title,
|
||||
link => escape(link).to_string(),
|
||||
guid => format!("{}", guid),
|
||||
})?
|
||||
.as_bytes(),
|
||||
self.path.clone(),
|
||||
@@ -106,7 +124,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user