1use std::fmt::Display;
4
5use serde::{Deserialize, Serialize};
6use soar_db::{models::types::PackageProvide, repository::core::InstalledPackageWithPortable};
7use soar_package::PackageExt;
8
9#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct Maintainer {
12 pub name: String,
13 pub contact: String,
14}
15
16impl Display for Maintainer {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 write!(f, "{} ({})", self.name, self.contact)
19 }
20}
21
22#[derive(Debug, Clone, Default)]
24pub struct Package {
25 pub id: u64,
26 pub repo_name: String,
27 pub disabled: Option<bool>,
28 pub disabled_reason: Option<String>,
29 pub pkg_id: String,
30 pub pkg_name: String,
31 pub pkg_family: Option<String>,
32 pub pkg_type: Option<String>,
33 pub pkg_webpage: Option<String>,
34 pub app_id: Option<String>,
35 pub description: String,
36 pub version: String,
37 pub version_upstream: Option<String>,
38 pub licenses: Option<Vec<String>>,
39 pub download_url: String,
40 pub size: Option<u64>,
41 pub ghcr_pkg: Option<String>,
42 pub ghcr_size: Option<u64>,
43 pub ghcr_files: Option<Vec<String>>,
44 pub ghcr_blob: Option<String>,
45 pub ghcr_url: Option<String>,
46 pub bsum: Option<String>,
47 pub homepages: Option<Vec<String>>,
48 pub notes: Option<Vec<String>>,
49 pub source_urls: Option<Vec<String>>,
50 pub tags: Option<Vec<String>>,
51 pub categories: Option<Vec<String>>,
52 pub icon: Option<String>,
53 pub desktop: Option<String>,
54 pub appstream: Option<String>,
55 pub build_id: Option<String>,
56 pub build_date: Option<String>,
57 pub build_action: Option<String>,
58 pub build_script: Option<String>,
59 pub build_log: Option<String>,
60 pub provides: Option<Vec<PackageProvide>>,
61 pub snapshots: Option<Vec<String>>,
62 pub repology: Option<Vec<String>>,
63 pub maintainers: Option<Vec<Maintainer>>,
64 pub replaces: Option<Vec<String>>,
65 pub soar_syms: bool,
66 pub deprecated: bool,
67 pub desktop_integration: Option<bool>,
68 pub portable: Option<bool>,
69 pub recurse_provides: Option<bool>,
70}
71
72impl PackageExt for Package {
73 fn pkg_name(&self) -> &str {
74 &self.pkg_name
75 }
76
77 fn pkg_id(&self) -> &str {
78 &self.pkg_id
79 }
80
81 fn version(&self) -> &str {
82 &self.version
83 }
84
85 fn repo_name(&self) -> &str {
86 &self.repo_name
87 }
88}
89
90#[derive(Debug, Clone)]
92pub struct InstalledPackage {
93 pub id: u64,
94 pub repo_name: String,
95 pub pkg_id: String,
96 pub pkg_name: String,
97 pub pkg_type: Option<String>,
98 pub version: String,
99 pub size: u64,
100 pub checksum: Option<String>,
101 pub installed_path: String,
102 pub installed_date: String,
103 pub profile: String,
104 pub pinned: bool,
105 pub is_installed: bool,
106 pub with_pkg_id: bool,
107 pub detached: bool,
108 pub unlinked: bool,
109 pub provides: Option<Vec<PackageProvide>>,
110 pub portable_path: Option<String>,
111 pub portable_home: Option<String>,
112 pub portable_config: Option<String>,
113 pub portable_share: Option<String>,
114 pub portable_cache: Option<String>,
115 pub install_patterns: Option<Vec<String>>,
116}
117
118impl PackageExt for InstalledPackage {
119 fn pkg_name(&self) -> &str {
120 &self.pkg_name
121 }
122
123 fn pkg_id(&self) -> &str {
124 &self.pkg_id
125 }
126
127 fn version(&self) -> &str {
128 &self.version
129 }
130
131 fn repo_name(&self) -> &str {
132 &self.repo_name
133 }
134}
135
136impl From<InstalledPackageWithPortable> for InstalledPackage {
138 fn from(pkg: InstalledPackageWithPortable) -> Self {
139 Self {
140 id: pkg.id as u64,
141 repo_name: pkg.repo_name,
142 pkg_id: pkg.pkg_id,
143 pkg_name: pkg.pkg_name,
144 pkg_type: pkg.pkg_type,
145 version: pkg.version,
146 size: pkg.size as u64,
147 checksum: pkg.checksum,
148 installed_path: pkg.installed_path,
149 installed_date: pkg.installed_date,
150 profile: pkg.profile,
151 pinned: pkg.pinned,
152 is_installed: pkg.is_installed,
153 with_pkg_id: pkg.with_pkg_id,
154 detached: pkg.detached,
155 unlinked: pkg.unlinked,
156 provides: pkg.provides,
157 portable_path: pkg.portable_path,
158 portable_home: pkg.portable_home,
159 portable_config: pkg.portable_config,
160 portable_share: pkg.portable_share,
161 portable_cache: pkg.portable_cache,
162 install_patterns: pkg.install_patterns,
163 }
164 }
165}
166
167impl From<soar_db::repository::core::InstalledPackage> for InstalledPackage {
169 fn from(pkg: soar_db::repository::core::InstalledPackage) -> Self {
170 Self {
171 id: pkg.id as u64,
172 repo_name: pkg.repo_name,
173 pkg_id: pkg.pkg_id,
174 pkg_name: pkg.pkg_name,
175 pkg_type: pkg.pkg_type,
176 version: pkg.version,
177 size: pkg.size as u64,
178 checksum: pkg.checksum,
179 installed_path: pkg.installed_path,
180 installed_date: pkg.installed_date,
181 profile: pkg.profile,
182 pinned: pkg.pinned,
183 is_installed: pkg.is_installed,
184 with_pkg_id: pkg.with_pkg_id,
185 detached: pkg.detached,
186 unlinked: pkg.unlinked,
187 provides: pkg.provides,
188 portable_path: None,
189 portable_home: None,
190 portable_config: None,
191 portable_share: None,
192 portable_cache: None,
193 install_patterns: pkg.install_patterns,
194 }
195 }
196}
197
198impl From<soar_db::models::metadata::Package> for Package {
200 fn from(pkg: soar_db::models::metadata::Package) -> Self {
201 Self {
202 id: pkg.id as u64,
203 repo_name: String::new(), disabled: None,
205 disabled_reason: None,
206 pkg_id: pkg.pkg_id,
207 pkg_name: pkg.pkg_name,
208 pkg_family: None,
209 pkg_type: pkg.pkg_type,
210 pkg_webpage: pkg.pkg_webpage,
211 app_id: pkg.app_id,
212 description: pkg.description.unwrap_or_default(),
213 version: pkg.version,
214 version_upstream: pkg.version_upstream,
215 licenses: pkg.licenses,
216 download_url: pkg.download_url,
217 size: pkg.size.map(|s| s as u64),
218 ghcr_pkg: pkg.ghcr_pkg,
219 ghcr_size: pkg.ghcr_size.map(|s| s as u64),
220 ghcr_files: None,
221 ghcr_blob: pkg.ghcr_blob,
222 ghcr_url: pkg.ghcr_url,
223 bsum: pkg.bsum,
224 homepages: pkg.homepages,
225 notes: pkg.notes,
226 source_urls: pkg.source_urls,
227 tags: pkg.tags,
228 categories: pkg.categories,
229 icon: pkg.icon,
230 desktop: pkg.desktop,
231 appstream: pkg.appstream,
232 build_id: pkg.build_id,
233 build_date: pkg.build_date,
234 build_action: pkg.build_action,
235 build_script: pkg.build_script,
236 build_log: pkg.build_log,
237 provides: pkg.provides,
238 snapshots: pkg.snapshots,
239 repology: None,
240 maintainers: None,
241 replaces: pkg.replaces,
242 soar_syms: pkg.soar_syms,
243 deprecated: false,
244 desktop_integration: pkg.desktop_integration,
245 portable: pkg.portable,
246 recurse_provides: pkg.recurse_provides,
247 }
248 }
249}
250
251impl From<soar_db::models::metadata::PackageWithRepo> for Package {
253 fn from(pkg_with_repo: soar_db::models::metadata::PackageWithRepo) -> Self {
254 let mut pkg: Package = pkg_with_repo.package.into();
255 pkg.repo_name = pkg_with_repo.repo_name;
256 pkg
257 }
258}