File tree 4 files changed +316
-315
lines changed
4 files changed +316
-315
lines changed Original file line number Diff line number Diff line change 1
- pub mod mod_tags;
1
+ pub mod mod_tags;
2
+ pub mod mods;
Original file line number Diff line number Diff line change
1
+ use crate :: types:: api:: ApiError ;
2
+ use sqlx:: PgConnection ;
3
+
4
+ pub async fn exists ( id : & str , conn : & mut PgConnection ) -> Result < bool , ApiError > {
5
+ Ok ( sqlx:: query!( "SELECT id FROM mods WHERE id = $1" , id)
6
+ . fetch_optional ( & mut * conn)
7
+ . await
8
+ . map_err ( |e| {
9
+ log:: error!( "Failed to check if mod {} exists: {}" , id, e) ;
10
+ ApiError :: DbError
11
+ } ) ?
12
+ . is_some ( ) )
13
+ }
14
+
15
+ pub async fn get_logo ( id : & str , conn : & mut PgConnection ) -> Result < Option < Vec < u8 > > , ApiError > {
16
+ struct QueryResult {
17
+ image : Option < Vec < u8 > > ,
18
+ }
19
+
20
+ let vec = sqlx:: query_as!(
21
+ QueryResult ,
22
+ "SELECT
23
+ m.image
24
+ FROM mods m
25
+ INNER JOIN mod_versions mv ON mv.mod_id = m.id
26
+ INNER JOIN mod_version_statuses mvs ON mvs.mod_version_id = mv.id
27
+ WHERE m.id = $1" ,
28
+ id
29
+ )
30
+ . fetch_optional ( & mut * conn)
31
+ . await
32
+ . map_err ( |e| {
33
+ log:: error!( "Failed to fetch mod logo for {}: {}" , id, e) ;
34
+ ApiError :: DbError
35
+ } ) ?
36
+ . map ( |optional| optional. image )
37
+ . flatten ( ) ;
38
+
39
+ // Empty vec is basically no image
40
+ if vec. as_ref ( ) . is_some_and ( |v| v. is_empty ( ) ) {
41
+ Ok ( None )
42
+ } else {
43
+ Ok ( vec)
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -212,8 +212,10 @@ pub async fn get_logo(
212
212
data : web:: Data < AppData > ,
213
213
path : web:: Path < String > ,
214
214
) -> Result < impl Responder , ApiError > {
215
+ use crate :: database:: repository:: * ;
215
216
let mut pool = data. db . acquire ( ) . await . or ( Err ( ApiError :: DbAcquireError ) ) ?;
216
- let image = Mod :: get_logo_for_mod ( & path, & mut pool) . await ?;
217
+ let image = mods:: get_logo ( & path. into_inner ( ) , & mut pool) . await ?;
218
+
217
219
match image {
218
220
Some ( i) => {
219
221
if i. is_empty ( ) {
You can’t perform that action at this time.
0 commit comments