cleanup
This commit is contained in:
parent
7b0178e3af
commit
412cca7cde
1 changed files with 2 additions and 47 deletions
49
src/main.rs
49
src/main.rs
|
|
@ -1,22 +1,15 @@
|
||||||
use anyhow::Error;
|
use reqwest::{multipart, Client, StatusCode, Url};
|
||||||
use reqwest::redirect::Policy;
|
|
||||||
use reqwest::{multipart, Client, RequestBuilder, Response, StatusCode, Url};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::os::unix::fs::MetadataExt;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use keyring::Entry;
|
|
||||||
use log::{debug, error, info};
|
|
||||||
use notify_rust::{Hint, Notification, NotificationHandle};
|
use notify_rust::{Hint, Notification, NotificationHandle};
|
||||||
use reqwest::header::{HeaderValue, AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE};
|
use reqwest::header::{HeaderValue, AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE};
|
||||||
use rusqlite::{Connection, OpenFlags};
|
|
||||||
use serde::de::DeserializeOwned;
|
|
||||||
use wl_clipboard_rs::copy::{ClipboardType, MimeType, Options, Source};
|
use wl_clipboard_rs::copy::{ClipboardType, MimeType, Options, Source};
|
||||||
|
|
||||||
type GodriveToken = String;
|
type GodriveToken = String;
|
||||||
|
|
@ -38,16 +31,6 @@ struct GodriveSharePermissions {
|
||||||
can_upload: bool,
|
can_upload: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GodriveSharePermissions {
|
|
||||||
fn download_only() -> Self {
|
|
||||||
GodriveSharePermissions {
|
|
||||||
can_edit: false,
|
|
||||||
can_download: true,
|
|
||||||
can_upload: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
|
@ -190,34 +173,6 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fire<T: DeserializeOwned>(req_builder: RequestBuilder) -> Result<T, Error> {
|
|
||||||
let resp = req_builder.send().await;
|
|
||||||
match resp {
|
|
||||||
Ok(resp) => {
|
|
||||||
let resp_dbg = format!("{:?}", resp);
|
|
||||||
let result_text = resp
|
|
||||||
.text()
|
|
||||||
.await
|
|
||||||
.expect("apparently they didnt send us text");
|
|
||||||
let result = serde_json::from_str((&result_text).as_str());
|
|
||||||
match result {
|
|
||||||
Ok(good) => Ok(good),
|
|
||||||
Err(bad) => {
|
|
||||||
eprintln!(
|
|
||||||
"{:?}, serialization error or something, idk\nResp: {:?}\nBody: {:?}",
|
|
||||||
bad, resp_dbg, result_text
|
|
||||||
);
|
|
||||||
Err(Error::msg(bad))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
eprintln!("{:?}, networking error or something, idk", error);
|
|
||||||
return Err(Error::from(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn godrive_get_share_link(
|
async fn godrive_get_share_link(
|
||||||
ctx: &CommunicationContext,
|
ctx: &CommunicationContext,
|
||||||
auth_token: &GodriveToken,
|
auth_token: &GodriveToken,
|
||||||
|
|
@ -284,7 +239,7 @@ async fn post_upload(
|
||||||
}
|
}
|
||||||
form = form.text("json", serde_json::to_string(&file_infos).unwrap());
|
form = form.text("json", serde_json::to_string(&file_infos).unwrap());
|
||||||
for (i, file) in files.iter().enumerate() {
|
for (i, file) in files.iter().enumerate() {
|
||||||
form = match form.file(format!("file-{i}"), file.clone()).await {
|
form = match form.file(format!("file-{i}"), file).await {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to add multipart file-{i} {file:?}: {e}");
|
eprintln!("Failed to add multipart file-{i} {file:?}: {e}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue