don't save Alias in Share

This commit is contained in:
Jörn-Michael Miehe 2025-05-28 14:07:29 +00:00
parent 5643ced9d1
commit 1ee56ac3da
3 changed files with 20 additions and 16 deletions

View file

@ -27,7 +27,7 @@ fn main() {
info!("share: {share:?}");
for file in args.files {
let file = file.create(&agent, &share).unwrap();
let file = file.create(&agent, &alias, &share).unwrap();
info!("file: {file:?}");
for chunk in file.chunked(args.chunk_size * 1024 * 1024) {
@ -39,5 +39,5 @@ fn main() {
}
}
share.notify(&agent).unwrap();
share.notify(&agent, &alias).unwrap();
}

View file

@ -4,7 +4,7 @@ use std::{
ffi::OsStr,
fs::metadata,
io::{self, ErrorKind},
path::PathBuf,
path::{Path, PathBuf},
};
use log::{debug, error};
@ -25,8 +25,8 @@ pub struct File {
}
impl File {
pub fn new(path: impl Into<PathBuf>) -> io::Result<Self> {
let path: PathBuf = path.into();
pub fn new(path: impl AsRef<Path>) -> io::Result<Self> {
let path = path.as_ref().to_owned();
let m = metadata(&path)?;
if !m.is_file() {
@ -45,15 +45,20 @@ impl File {
})
}
pub fn create(self, http: &ureq::Agent, share: &Share) -> Result<Self, ureq::Error> {
pub fn create(
self,
http: &ureq::Agent,
alias: &Alias,
share: &Share,
) -> Result<Self, ureq::Error> {
if self.patch_uri.is_some() {
return Err(Other("patch_uri already set".into()));
}
let endpoint = (share.alias).get_endpoint(format!("alias/upload/{}/files/tus", share.id));
let endpoint = alias.get_endpoint(format!("alias/upload/{}/files/tus", share.id));
let res = (http.post(endpoint))
.sharry_header(share.alias)
.sharry_header(alias)
.header("Sharry-File-Name", &self.name)
.header("Upload-Length", self.size)
.send_empty()?;

View file

@ -6,15 +6,14 @@ use super::{
};
#[derive(Debug)]
pub struct Share<'t> {
pub(super) alias: &'t Alias,
pub struct Share {
pub(super) id: String,
}
impl<'t> Share<'t> {
impl Share {
pub fn create(
http: &ureq::Agent,
alias: &'t Alias,
alias: &Alias,
data: NewShareRequest,
) -> Result<Self, ureq::Error> {
let res = (http.post(alias.get_endpoint("alias/upload/new")))
@ -29,14 +28,14 @@ impl<'t> Share<'t> {
return Err(ureq::Error::Other("unexpected json response".into()));
}
Ok(Self { alias, id: res.id })
Ok(Self { id: res.id })
}
pub fn notify(&self, http: &ureq::Agent) -> Result<(), ureq::Error> {
let endpoint = (self.alias).get_endpoint(format!("alias/mail/notify/{}", self.id));
pub fn notify(&self, http: &ureq::Agent, alias: &Alias) -> Result<(), ureq::Error> {
let endpoint = alias.get_endpoint(format!("alias/mail/notify/{}", self.id));
let res = (http.post(endpoint))
.sharry_header(self.alias)
.sharry_header(alias)
.send_empty()?
.body_mut()
.read_json::<NotifyShareResponse>()?;