update for google drive

main
reng 3 months ago
parent 8894f9815c
commit 68fde27c7c
  1. 16
      package-lock.json
  2. 1
      package.json
  3. 9
      src-tauri/2
  4. 188
      src-tauri/Cargo.lock
  5. 1
      src-tauri/Cargo.toml
  6. 18
      src-tauri/capabilities/default.json
  7. 40
      src-tauri/src/lib.rs
  8. 38
      src-tauri/src/raw_convert.rs
  9. 26
      src-tauri/src/util.rs
  10. 2
      src/App.jsx
  11. 9
      src/utils/backend.js
  12. 2
      src/utils/fs.js

16
package-lock.json generated

@ -12,6 +12,7 @@
"@tauri-apps/api": "^2", "@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2.3.2", "@tauri-apps/plugin-dialog": "^2.3.2",
"@tauri-apps/plugin-fs": "^2.4.1", "@tauri-apps/plugin-fs": "^2.4.1",
"@tauri-apps/plugin-http": "^2.5.2",
"@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-opener": "^2",
"firebase": "^12.0.0", "firebase": "^12.0.0",
"react": "^18.3.1", "react": "^18.3.1",
@ -2017,9 +2018,9 @@
} }
}, },
"node_modules/@tauri-apps/api": { "node_modules/@tauri-apps/api": {
"version": "2.7.0", "version": "2.8.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.7.0.tgz", "resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.8.0.tgz",
"integrity": "sha512-v7fVE8jqBl8xJFOcBafDzXFc8FnicoH3j8o8DNNs0tHuEBmXUDqrCOAzMRX0UkfpwqZLqvrvK0GNQ45DfnoVDg==", "integrity": "sha512-ga7zdhbS2GXOMTIZRT0mYjKJtR9fivsXzsyq5U3vjDL0s6DTMwYRm0UHNjzTY5dh4+LSC68Sm/7WEiimbQNYlw==",
"license": "Apache-2.0 OR MIT", "license": "Apache-2.0 OR MIT",
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",
@ -2261,6 +2262,15 @@
"@tauri-apps/api": "^2.6.0" "@tauri-apps/api": "^2.6.0"
} }
}, },
"node_modules/@tauri-apps/plugin-http": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.5.2.tgz",
"integrity": "sha512-x1mQKHSLDk4mS2S938OTeyk8L7QyLpCrKZCZcjkljGsvTvRMojCvI9SeJ1kaxc7t8xSilkC7WdId8xER9TIGLg==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.8.0"
}
},
"node_modules/@tauri-apps/plugin-opener": { "node_modules/@tauri-apps/plugin-opener": {
"version": "2.4.0", "version": "2.4.0",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.4.0.tgz", "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.4.0.tgz",

@ -14,6 +14,7 @@
"@tauri-apps/api": "^2", "@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2.3.2", "@tauri-apps/plugin-dialog": "^2.3.2",
"@tauri-apps/plugin-fs": "^2.4.1", "@tauri-apps/plugin-fs": "^2.4.1",
"@tauri-apps/plugin-http": "^2.5.2",
"@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-opener": "^2",
"firebase": "^12.0.0", "firebase": "^12.0.0",
"react": "^18.3.1", "react": "^18.3.1",

@ -1,7 +1,12 @@
up to date, audited 256 packages in 4s added 1 package, changed 1 package, and audited 257 packages in 5s
28 packages are looking for funding 28 packages are looking for funding
run `npm fund` for details run `npm fund` for details
found 0 vulnerabilities 1 low severity vulnerability
To address all issues, run:
npm audit fix
Run `npm audit` for details.

188
src-tauri/Cargo.lock generated

@ -87,7 +87,7 @@ dependencies = [
"num-traits", "num-traits",
"ouroboros", "ouroboros",
"pathfinder_geometry", "pathfinder_geometry",
"rustc-hash", "rustc-hash 1.1.0",
"tinyvec", "tinyvec",
"ucd-trie", "ucd-trie",
"unicode-canonical-combining-class", "unicode-canonical-combining-class",
@ -777,10 +777,29 @@ version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
dependencies = [ dependencies = [
"percent-encoding",
"time", "time",
"version_check", "version_check",
] ]
[[package]]
name = "cookie_store"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eac901828f88a5241ee0600950ab981148a18f2f756900ffba1b125ca6a3ef9"
dependencies = [
"cookie",
"document-features",
"idna",
"log",
"publicsuffix",
"serde",
"serde_derive",
"serde_json",
"time",
"url",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.4" version = "0.9.4"
@ -1118,6 +1137,15 @@ dependencies = [
"syn 2.0.104", "syn 2.0.104",
] ]
[[package]]
name = "document-features"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d"
dependencies = [
"litrs",
]
[[package]] [[package]]
name = "downcast-rs" name = "downcast-rs"
version = "1.2.1" version = "1.2.1"
@ -1700,8 +1728,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"wasi 0.11.1+wasi-snapshot-preview1", "wasi 0.11.1+wasi-snapshot-preview1",
"wasm-bindgen",
] ]
[[package]] [[package]]
@ -1711,9 +1741,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.2+wasi-0.2.4", "wasi 0.14.2+wasi-0.2.4",
"wasm-bindgen",
] ]
[[package]] [[package]]
@ -2063,6 +2095,7 @@ dependencies = [
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
"tower-service", "tower-service",
"webpki-roots",
] ]
[[package]] [[package]]
@ -2657,6 +2690,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"
[[package]]
name = "litrs"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.13" version = "0.4.13"
@ -2704,6 +2743,12 @@ dependencies = [
"weezl", "weezl",
] ]
[[package]]
name = "lru-slab"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
[[package]] [[package]]
name = "mac" name = "mac"
version = "0.1.1" version = "0.1.1"
@ -3738,6 +3783,7 @@ dependencies = [
"tauri-build", "tauri-build",
"tauri-plugin-dialog", "tauri-plugin-dialog",
"tauri-plugin-fs", "tauri-plugin-fs",
"tauri-plugin-http",
"tauri-plugin-opener", "tauri-plugin-opener",
"winprint", "winprint",
] ]
@ -3864,6 +3910,22 @@ dependencies = [
"syn 2.0.104", "syn 2.0.104",
] ]
[[package]]
name = "psl-types"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac"
[[package]]
name = "publicsuffix"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf"
dependencies = [
"idna",
"psl-types",
]
[[package]] [[package]]
name = "qoi" name = "qoi"
version = "0.4.1" version = "0.4.1"
@ -3897,6 +3959,61 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "quinn"
version = "0.11.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20"
dependencies = [
"bytes",
"cfg_aliases",
"pin-project-lite",
"quinn-proto",
"quinn-udp",
"rustc-hash 2.1.1",
"rustls",
"socket2 0.6.0",
"thiserror 2.0.12",
"tokio",
"tracing",
"web-time",
]
[[package]]
name = "quinn-proto"
version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31"
dependencies = [
"bytes",
"getrandom 0.3.3",
"lru-slab",
"rand 0.9.2",
"ring",
"rustc-hash 2.1.1",
"rustls",
"rustls-pki-types",
"slab",
"thiserror 2.0.12",
"tinyvec",
"tracing",
"web-time",
]
[[package]]
name = "quinn-udp"
version = "0.5.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd"
dependencies = [
"cfg_aliases",
"libc",
"once_cell",
"socket2 0.6.0",
"tracing",
"windows-sys 0.60.2",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.40" version = "1.0.40"
@ -4181,6 +4298,8 @@ checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"bytes", "bytes",
"cookie",
"cookie_store",
"encoding_rs", "encoding_rs",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -4199,6 +4318,8 @@ dependencies = [
"native-tls", "native-tls",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"quinn",
"rustls",
"rustls-pki-types", "rustls-pki-types",
"serde", "serde",
"serde_json", "serde_json",
@ -4206,6 +4327,7 @@ dependencies = [
"sync_wrapper", "sync_wrapper",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls",
"tokio-util", "tokio-util",
"tower", "tower",
"tower-http", "tower-http",
@ -4215,6 +4337,7 @@ dependencies = [
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasm-streams", "wasm-streams",
"web-sys", "web-sys",
"webpki-roots",
] ]
[[package]] [[package]]
@ -4321,6 +4444,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.4.1" version = "0.4.1"
@ -4350,6 +4479,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1" checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"ring",
"rustls-pki-types", "rustls-pki-types",
"rustls-webpki", "rustls-webpki",
"subtle", "subtle",
@ -4362,6 +4492,7 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79"
dependencies = [ dependencies = [
"web-time",
"zeroize", "zeroize",
] ]
@ -5320,6 +5451,30 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "tauri-plugin-http"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcde333d97e565a7765aad82f32d8672458f7bd77b6ee653830d5dded9d7b5c2"
dependencies = [
"bytes",
"cookie_store",
"data-url",
"http",
"regex",
"reqwest",
"schemars 0.8.22",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"tauri-plugin-fs",
"thiserror 2.0.12",
"tokio",
"url",
"urlpattern",
]
[[package]] [[package]]
name = "tauri-plugin-opener" name = "tauri-plugin-opener"
version = "2.4.0" version = "2.4.0"
@ -5618,10 +5773,22 @@ dependencies = [
"signal-hook-registry", "signal-hook-registry",
"slab", "slab",
"socket2 0.5.10", "socket2 0.5.10",
"tokio-macros",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "tokio-macros"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
]
[[package]] [[package]]
name = "tokio-native-tls" name = "tokio-native-tls"
version = "0.3.1" version = "0.3.1"
@ -6345,6 +6512,16 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "web-time"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]] [[package]]
name = "webkit2gtk" name = "webkit2gtk"
version = "2.0.1" version = "2.0.1"
@ -6389,6 +6566,15 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "webpki-roots"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8983c3ab33d6fb807cfcdad2491c4ea8cbc8ed839181c7dfd9c67c83e261b2"
dependencies = [
"rustls-pki-types",
]
[[package]] [[package]]
name = "webview2-com" name = "webview2-com"
version = "0.38.0" version = "0.38.0"

@ -30,3 +30,4 @@ tauri-plugin-fs = "2"
image = "0.25.6" image = "0.25.6"
flate2 = "1.1.2" flate2 = "1.1.2"
quick-xml = "0.38.0" quick-xml = "0.38.0"
tauri-plugin-http = "2"

@ -17,8 +17,12 @@
{ {
"identifier": "fs:scope", "identifier": "fs:scope",
"allow": [ "allow": [
{"path":"$DOCUMENT/**/*"}, {
{"path":"$DOCUMENT"}, "path": "$DOCUMENT/**/*"
},
{
"path": "$DOCUMENT"
},
{ {
"path": "$APPDATA" "path": "$APPDATA"
}, },
@ -26,6 +30,16 @@
"path": "$APPDATA/**/*" "path": "$APPDATA/**/*"
} }
] ]
},
{
"identifier": "http:default",
"allow": [
{
"url": "https://drive.google.com/uc?id=*"
},{
"url":"https://drive.usercontent.google.com/download?id=*"
}
]
} }
] ]
} }

@ -7,8 +7,8 @@ use winprint::ticket::{
PrintCapabilities, PrintTicket, PrintTicketBuilder, PrintCapabilities, PrintTicket, PrintTicketBuilder,
}; };
mod util;
mod raw_convert; mod raw_convert;
mod util;
#[tauri::command] #[tauri::command]
fn get_all_printers() -> Vec<String> { fn get_all_printers() -> Vec<String> {
@ -31,8 +31,7 @@ fn convert_pdf(document_path: String) -> Result<String, String> {
return Err(format!("File does not exist: {}", document_path)); return Err(format!("File does not exist: {}", document_path));
} }
match raw_convert::imageToPdf2(document_path.clone()) {
match raw_convert::imageToPdf2(document_path.clone()) {
Ok(pdf_path) => { Ok(pdf_path) => {
// Print the converted PDF using the printer // Print the converted PDF using the printer
// printer.print(Path::new(&pdf_path), ticket).unwrap(); // printer.print(Path::new(&pdf_path), ticket).unwrap();
@ -56,7 +55,7 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>>
} }
}; };
println!("My Printer: {:?}", my_device.name()); println!("My Printer: {:?}", my_device.name());
let mut map = HashMap::new(); let mut map = HashMap::new();
match PrintCapabilities::fetch_xml(&my_device) { match PrintCapabilities::fetch_xml(&my_device) {
@ -68,7 +67,6 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>>
println!("DPI Options: {:?}", quality_opts); println!("DPI Options: {:?}", quality_opts);
map.insert("quality_options".to_string(), quality_opts); map.insert("quality_options".to_string(), quality_opts);
} }
Err(e) => { Err(e) => {
println!("Failed to fetch capabilities: {:?}", e); println!("Failed to fetch capabilities: {:?}", e);
@ -95,7 +93,6 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>>
println!("Color Options: {:?}", color_opts_value); println!("Color Options: {:?}", color_opts_value);
println!("Size Options: {:?}", size_opts_value); println!("Size Options: {:?}", size_opts_value);
map.insert("dpi_options".to_string(), dpi_opts_value); map.insert("dpi_options".to_string(), dpi_opts_value);
map.insert("color_options".to_string(), color_opts_value); map.insert("color_options".to_string(), color_opts_value);
map.insert("size_options".to_string(), size_opts_value); map.insert("size_options".to_string(), size_opts_value);
@ -111,7 +108,8 @@ fn default_ticket(quality: Option<String>) -> PrintTicket {
// let mut ticket = PrintTicket::new(); // let mut ticket = PrintTicket::new();
let _quality = quality.unwrap_or_else(|| "psk:Normal".to_string()); let _quality = quality.unwrap_or_else(|| "psk:Normal".to_string());
let xml =format!(r#"<?xml version="1.0" encoding="UTF-8"?> let xml = format!(
r#"<?xml version="1.0" encoding="UTF-8"?>
<psf:PrintTicket version="1" <psf:PrintTicket version="1"
xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework" xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords"> xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords">
@ -121,7 +119,8 @@ fn default_ticket(quality: Option<String>) -> PrintTicket {
<psf:Feature name="psk:PageOutputQuality"> <psf:Feature name="psk:PageOutputQuality">
<psf:Option name="{_quality}" /> <psf:Option name="{_quality}" />
</psf:Feature> </psf:Feature>
</psf:PrintTicket>"#); </psf:PrintTicket>"#
);
let ticket = PrintTicket::from_xml(xml); let ticket = PrintTicket::from_xml(xml);
ticket ticket
@ -153,14 +152,7 @@ fn print_document(
{ {
match raw_convert::imageToPdf2(document_path.clone()) { match raw_convert::imageToPdf2(document_path.clone()) {
Ok(pdf_path) => { Ok(pdf_path) => {
print_document( print_document(device_name, pdf_path, dpi, color, size, quality);
device_name,
pdf_path,
dpi,
color,
size,
quality,
);
} }
Err(e) => { Err(e) => {
println!("Error converting image to PDF: {}", e); println!("Error converting image to PDF: {}", e);
@ -169,8 +161,6 @@ fn print_document(
return; return;
} }
let my_device = match get_my_device(device_name.clone()) { let my_device = match get_my_device(device_name.clone()) {
Some(device) => device, Some(device) => device,
None => { None => {
@ -195,8 +185,7 @@ fn print_document(
.expect("Media size not supported by printer"); .expect("Media size not supported by printer");
builder.merge(media).unwrap(); builder.merge(media).unwrap();
} }
// dpi // dpi
if let Some(dpi) = &dpi { if let Some(dpi) = &dpi {
let parsed_dpi = dpi let parsed_dpi = dpi
@ -226,18 +215,13 @@ fn print_document(
.expect("Color not supported by printer"); .expect("Color not supported by printer");
builder.merge(supported_color).unwrap(); builder.merge(supported_color).unwrap();
} }
// let default_ticket = default_ticket(quality); // let default_ticket = default_ticket(quality);
// if let Err(e) = builder.merge(default_ticket) { // if let Err(e) = builder.merge(default_ticket) {
// println!("Failed to merge default ticket: {:?}", e); // println!("Failed to merge default ticket: {:?}", e);
// } // }
let ticket = builder.build().unwrap(); let ticket = builder.build().unwrap();
// let xml=ticket.get_xml(); // let xml=ticket.get_xml();
@ -250,13 +234,11 @@ fn print_document(
// let theprinter = ImagePrinter::new(my_device); // let theprinter = ImagePrinter::new(my_device);
printer.print(path, ticket).unwrap(); printer.print(path, ticket).unwrap();
} }
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())

@ -1,29 +1,25 @@
use std::path::Path;
use flate2::write::ZlibEncoder; use flate2::write::ZlibEncoder;
use flate2::Compression; use flate2::Compression;
use image::{DynamicImage, GenericImageView}; use image::{DynamicImage, GenericImageView};
use std::fs::File; use std::fs::File;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::path::Path;
pub fn imageToPdf2(path: String) -> Result<String, String> { pub fn imageToPdf2(path: String) -> Result<String, String> {
let image_data = std::fs::read(&path).expect("Failed to read image"); let image_data = std::fs::read(&path).expect("Failed to read image");
let pdf_data = img2pdf_from_bytes(&image_data, 300.0).expect("Failed to convert image to PDF"); let pdf_data = match img2pdf_from_bytes(&image_data, 300.0) {
Ok(data) => data,
Err(e) => return Err(format!("Failed to convert image to PDF: {}", e)),
};
let pdf_path = Path::new(&path).with_extension("pdf"); let pdf_path = Path::new(&path).with_extension("pdf");
match std::fs::write(&pdf_path, pdf_data) { match std::fs::write(&pdf_path, pdf_data) {
Ok(_) => Ok(pdf_path.display().to_string()), Ok(_) => Ok(pdf_path.display().to_string()),
Err(e) => Err(format!("Failed to write PDF file: {}", e)), Err(e) => Err(format!("Failed to write PDF file: {}", e)),
} }
} }
/// Converts an image from binary data to a PDF as binary data. /// Converts an image from binary data to a PDF as binary data.
/// ///
/// # Arguments /// # Arguments
@ -34,8 +30,16 @@ pub fn imageToPdf2(path: String) -> Result<String, String> {
/// ///
/// A `Result` containing the PDF data as a `Vec<u8>` on success, or an `io::Error` on failure. /// A `Result` containing the PDF data as a `Vec<u8>` on success, or an `io::Error` on failure.
pub fn img2pdf_from_bytes(img_data: &[u8], dpi: f64) -> io::Result<Vec<u8>> { pub fn img2pdf_from_bytes(img_data: &[u8], dpi: f64) -> io::Result<Vec<u8>> {
let img = match image::load_from_memory(img_data) {
Ok(img) => img,
Err(e) => {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("Failed to open image: {}", e),
))
}
};
let img = image::load_from_memory(img_data).expect("Failed to open image");
let (width, height) = img.dimensions(); let (width, height) = img.dimensions();
let (page_width, page_height) = ( let (page_width, page_height) = (
@ -98,7 +102,9 @@ pub fn img2pdf_from_bytes(img_data: &[u8], dpi: f64) -> io::Result<Vec<u8>> {
let content = format!( let content = format!(
"q\n{} 0 0 {} 0 0 cm\n/Im{} Do\nQ", "q\n{} 0 0 {} 0 0 cm\n/Im{} Do\nQ",
// width, height, image_object_id // width, height, image_object_id
page_width, page_height, image_object_id page_width,
page_height,
image_object_id
); );
writeln!( writeln!(
pdf_data, pdf_data,
@ -184,7 +190,11 @@ fn separate_rgb_and_alpha(img: DynamicImage) -> (Vec<u8>, Vec<u8>) {
/// # Returns /// # Returns
/// ///
/// An `io::Result` indicating success or failure. /// An `io::Result` indicating success or failure.
pub fn img2pdf_from_file<P: AsRef<Path>>(input_path: P, output_path: P, dpi: f64) -> io::Result<()> { pub fn img2pdf_from_file<P: AsRef<Path>>(
input_path: P,
output_path: P,
dpi: f64,
) -> io::Result<()> {
let mut input_file = File::open(input_path)?; let mut input_file = File::open(input_path)?;
let mut img_data = Vec::new(); let mut img_data = Vec::new();
input_file.read_to_end(&mut img_data)?; input_file.read_to_end(&mut img_data)?;
@ -195,4 +205,4 @@ pub fn img2pdf_from_file<P: AsRef<Path>>(input_path: P, output_path: P, dpi: f64
output_file.write_all(&pdf_data)?; output_file.write_all(&pdf_data)?;
Ok(()) Ok(())
} }

@ -1,9 +1,8 @@
// use printpdf::*; // use printpdf::*;
use std::path::Path; use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader; use quick_xml::Reader;
use quick_xml::events::{Event, BytesStart};
use std::collections::HashSet; use std::collections::HashSet;
use std::path::Path;
// pub fn imageToPdf(path: String) -> Result<String, String> { // pub fn imageToPdf(path: String) -> Result<String, String> {
// let mut doc = PdfDocument::new("image_to_pdf"); // let mut doc = PdfDocument::new("image_to_pdf");
@ -11,7 +10,6 @@ use std::collections::HashSet;
// let image_bytes = std::fs::read(&path).map_err(|e| e.to_string())?; // let image_bytes = std::fs::read(&path).map_err(|e| e.to_string())?;
// let image = RawImage::decode_from_bytes(&image_bytes, &mut Vec::new()).unwrap(); // let image = RawImage::decode_from_bytes(&image_bytes, &mut Vec::new()).unwrap();
// let mut ops = Vec::new(); // let mut ops = Vec::new();
// // In the PDF, an image is an `XObject`, identified by a unique `ImageId` // // In the PDF, an image is an `XObject`, identified by a unique `ImageId`
@ -37,7 +35,7 @@ use std::collections::HashSet;
// dpi: Some(dpi), // dpi: Some(dpi),
// ..Default::default() // ..Default::default()
// }, // },
// }); // });
// let save_options= PdfSaveOptions { // let save_options= PdfSaveOptions {
@ -51,12 +49,11 @@ use std::collections::HashSet;
// ..Default::default() // ..Default::default()
// }; // };
// let page1 = PdfPage::new(Mm(output_width), Mm(output_height), ops); // let page1 = PdfPage::new(Mm(output_width), Mm(output_height), ops);
// let pdf_bytes: Vec<u8> = doc // let pdf_bytes: Vec<u8> = doc
// .with_pages(vec![page1]) // .with_pages(vec![page1])
// .save(&save_options, &mut Vec::new()); // .save(&save_options, &mut Vec::new());
// let pdf_path = Path::new(&path).with_extension("pdf"); // let pdf_path = Path::new(&path).with_extension("pdf");
// match std::fs::write(&pdf_path, pdf_bytes) { // match std::fs::write(&pdf_path, pdf_bytes) {
@ -71,9 +68,6 @@ use std::collections::HashSet;
// } // }
// } // }
pub fn get_output_quality_options(xml: &str) -> Vec<String> { pub fn get_output_quality_options(xml: &str) -> Vec<String> {
let mut reader = Reader::from_str(xml); let mut reader = Reader::from_str(xml);
// reader.trim_text(true); // reader.trim_text(true);
@ -88,13 +82,21 @@ pub fn get_output_quality_options(xml: &str) -> Vec<String> {
match reader.read_event() { match reader.read_event() {
Ok(Event::Start(ref e)) => { Ok(Event::Start(ref e)) => {
if e.name().as_ref() == b"psf:Feature" { if e.name().as_ref() == b"psf:Feature" {
if let Some(attr) = e.attributes().filter_map(Result::ok).find(|a| a.key.as_ref() == b"name") { if let Some(attr) = e
.attributes()
.filter_map(Result::ok)
.find(|a| a.key.as_ref() == b"name")
{
if attr.unescape_value().unwrap() == "psk:PageOutputQuality" { if attr.unescape_value().unwrap() == "psk:PageOutputQuality" {
inside_target_feature = true; inside_target_feature = true;
} }
} }
} else if inside_target_feature && e.name().as_ref() == b"psf:Option" { } else if inside_target_feature && e.name().as_ref() == b"psf:Option" {
if let Some(attr) = e.attributes().filter_map(Result::ok).find(|a| a.key.as_ref() == b"name") { if let Some(attr) = e
.attributes()
.filter_map(Result::ok)
.find(|a| a.key.as_ref() == b"name")
{
results.insert(attr.unescape_value().unwrap().to_string()); results.insert(attr.unescape_value().unwrap().to_string());
} }
} }

@ -131,7 +131,7 @@ function App() {
setPrinting(latestPrint.id); setPrinting(latestPrint.id);
// save url to local disk // save url to local disk
saveToDisk(latestPrint.id, latestPrint.url) saveToDisk(latestPrint.id, latestPrint.print_url)
.then((filePath) => { .then((filePath) => {
console.log("File saved to:", filePath); console.log("File saved to:", filePath);

@ -23,7 +23,14 @@ export function listenToPrints(callback) {
onSnapshot(printsRef, (snapshot) => { onSnapshot(printsRef, (snapshot) => {
const prints = []; const prints = [];
snapshot.forEach((doc) => { snapshot.forEach((doc) => {
prints.push({ id: doc.id, ...doc.data() });
const data= doc.data();
if(data.print_url === undefined || data.print_url === null) {
console.warn(`Document with id ${doc.id} has no print URL, skipping.`);
return;
}
console.log("Print data:", { id: doc.id, ...data });
prints.push({ id: doc.id, ...data });
}); });
callback(prints); callback(prints);
}); });

@ -1,5 +1,6 @@
import { writeFile, BaseDirectory, exists, mkdir, writeTextFile, readTextFile } from '@tauri-apps/plugin-fs'; import { writeFile, BaseDirectory, exists, mkdir, writeTextFile, readTextFile } from '@tauri-apps/plugin-fs';
import { path } from '@tauri-apps/api'; import { path } from '@tauri-apps/api';
import { fetch } from '@tauri-apps/plugin-http';
const OutputDir = 'prints'; const OutputDir = 'prints';
const settingsFile = 'settings.json'; const settingsFile = 'settings.json';
@ -10,6 +11,7 @@ export async function saveToDisk(id, url){
const response = await fetch(url); const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer(); const arrayBuffer = await response.arrayBuffer();
console.log('fetch data, size=', arrayBuffer.byteLength);
const base=BaseDirectory.Document; const base=BaseDirectory.Document;
const folder=`${OutputDir}`; const folder=`${OutputDir}`;

Loading…
Cancel
Save