pytauri_core/plugins/upload/
mod.rs1use std::{
2 error::Error,
3 fmt::{Debug, Display, Formatter},
4};
5
6use pyo3::{exceptions::PyRuntimeError, prelude::*};
7use tauri_plugin_upload::{self as plugin};
8
9use crate::{ext_mod::plugin::Plugin, tauri_runtime::Runtime};
10
11#[derive(Debug)]
12struct PluginError(plugin::Error);
13
14impl Display for PluginError {
15 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16 Display::fmt(&self.0, f)
17 }
18}
19
20impl Error for PluginError {}
21
22impl From<PluginError> for PyErr {
23 fn from(value: PluginError) -> Self {
24 match value.0 {
25 plugin::Error::Io(e) => e.into(),
26 e @ (plugin::Error::Request(_)
27 | plugin::Error::ContentLength(_)
28 | plugin::Error::HttpErrorCode(_, _)) => PyRuntimeError::new_err(e.to_string()),
29 }
30 }
31}
32
33impl From<plugin::Error> for PluginError {
34 fn from(value: plugin::Error) -> Self {
35 Self(value)
36 }
37}
38
39#[pyfunction]
41pub fn init() -> Plugin {
42 Plugin::new(Box::new(|| Box::new(plugin::init::<Runtime>())))
43}
44
45#[pymodule(submodule, gil_used = false)]
47pub mod upload {
48 #[pymodule_export]
49 pub use super::init;
50}