-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02900da
commit 77fe150
Showing
17 changed files
with
352 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::HashMap; | ||
use chrono::{DateTime, Utc}; | ||
use log::info; | ||
use tokio::sync::RwLock; | ||
use uuid::Uuid; | ||
|
||
pub struct LinkDownloadManager { | ||
links: RwLock<HashMap<String, (LinkDownloadTarget, DateTime<Utc>)>>, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum LinkDownloadTarget { | ||
Savefile { id: String }, | ||
} | ||
|
||
impl LinkDownloadManager { | ||
pub fn new() -> LinkDownloadManager { | ||
// TODO periodic job to expire out links | ||
LinkDownloadManager { | ||
links: RwLock::new(HashMap::new()), | ||
} | ||
} | ||
|
||
pub async fn create_link(&self, target: LinkDownloadTarget) -> String { | ||
let mut w_guard = self.links.write().await; | ||
let link = Uuid::new_v4().as_simple().to_string(); | ||
info!("Generating download link: {} -> {:?}", link, target); | ||
w_guard.insert(link.clone(), (target, Utc::now())); | ||
link | ||
} | ||
|
||
pub async fn get_link(&self, link: String) -> Option<LinkDownloadTarget> { | ||
let r_guard = self.links.read().await; | ||
r_guard.get(&link).map(|(target, _dt)| target.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.