refactor: restructure project into a workspace by introducing a plugin API crate and modularizing individual plugin definitions.
Release / check-release (push) Successful in 17s
Release / build (push) Skipped
Release / package (deb) (push) Skipped
Release / package (rpm) (push) Skipped
Release / publish (push) Skipped
CI / test (push) Failing after 2m6s

This commit is contained in:
Elias Wendland
2026-07-17 15:50:50 +02:00
parent 2ea317e117
commit eb76ed1937
43 changed files with 4243 additions and 2296 deletions
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "convertis-plugin-api"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
[dependencies]
serde.workspace = true
+126
View File
@@ -0,0 +1,126 @@
// Copyright (C) 2026 Elias Wendland <eliaswendland@pm.me>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 exclusively.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, path::PathBuf};
pub const API_VERSION: u32 = 1;
pub const ENGINE_VERSION: &str = "0.3.0";
pub const MANIFEST_SYMBOL: &[u8] = b"convertis_plugin_manifest_v1\0";
pub const FACTORY_SYMBOL: &[u8] = b"convertis_plugin_create_v1\0";
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum ArtifactKind {
File,
Directory,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum MediaKind {
Image,
Animation,
Video,
Audio,
Text,
Frames,
Document,
Unknown,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Conversion {
pub from: String,
pub to: String,
pub input_kind: ArtifactKind,
pub output_kind: ArtifactKind,
pub familiarity: u8,
pub quality: u8,
pub speed: u8,
}
impl Conversion {
pub fn file(from: &str, to: &str, scores: (u8, u8, u8)) -> Self {
Self {
from: from.to_owned(),
to: to.to_owned(),
input_kind: ArtifactKind::File,
output_kind: ArtifactKind::File,
familiarity: scores.0,
quality: scores.1,
speed: scores.2,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct OptionSpec {
pub name: String,
pub help: String,
pub default: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PluginMetadata {
pub id: String,
pub package: String,
pub description: String,
pub conversions: Vec<Conversion>,
pub options: Vec<OptionSpec>,
}
#[derive(Clone, Debug)]
pub struct ConversionRequest {
pub input: PathBuf,
pub output: PathBuf,
pub from: String,
pub to: String,
pub options: BTreeMap<String, String>,
}
pub trait Plugin: Send + Sync {
fn metadata(&self) -> PluginMetadata;
fn availability(&self) -> Result<(), String> {
Ok(())
}
fn convert(&self, request: &ConversionRequest) -> Result<(), String>;
}
pub type PluginFactory = unsafe fn() -> Box<dyn Plugin>;
pub type PluginManifest = unsafe extern "C" fn() -> *const std::ffi::c_char;
#[macro_export]
macro_rules! export_plugin {
($plugin:expr, $id:literal) => {
#[unsafe(no_mangle)]
pub extern "C" fn convertis_plugin_manifest_v1() -> *const std::ffi::c_char {
static MANIFEST: &str = concat!(
"{\"api_version\":1,\"engine_version\":\"",
env!("CARGO_PKG_VERSION"),
"\",\"plugin_id\":\"",
$id,
"\",\"rustc_version\":\"",
env!("CONVERTIS_RUSTC_VERSION"),
"\",\"target\":\"",
env!("CONVERTIS_TARGET"),
"\"}\0"
);
MANIFEST.as_ptr().cast()
}
#[unsafe(no_mangle)]
pub fn convertis_plugin_create_v1() -> Box<dyn $crate::Plugin> {
Box::new($plugin)
}
};
}