2021-01-05 15:13:19 +01:00
|
|
|
use crate::util::IntoTableRow;
|
2020-12-05 22:20:08 +01:00
|
|
|
use anyhow::{anyhow, Result};
|
2020-12-05 12:08:24 +01:00
|
|
|
use serde::Deserialize;
|
2020-12-05 22:20:08 +01:00
|
|
|
use term_table::{row::Row, table_cell::TableCell};
|
2020-12-05 12:08:24 +01:00
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-05 12:08:24 +01:00
|
|
|
pub struct UpResp {
|
|
|
|
pub files: Vec<String>,
|
|
|
|
}
|
2020-12-05 12:32:01 +01:00
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-05 12:32:01 +01:00
|
|
|
pub struct CatsResp {
|
|
|
|
pub categories: Vec<Category>,
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-19 19:43:23 +01:00
|
|
|
pub struct UsersResp {
|
|
|
|
pub users: Vec<User>,
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-19 19:43:23 +01:00
|
|
|
pub struct MemesResp {
|
|
|
|
pub memes: Vec<Meme>,
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-05 12:32:01 +01:00
|
|
|
pub struct Category {
|
|
|
|
pub id: String,
|
|
|
|
pub name: String,
|
|
|
|
}
|
2020-12-05 22:20:08 +01:00
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
impl IntoTableRow for Category {
|
|
|
|
fn into_table_row(&self) -> Row<'_> {
|
|
|
|
Row::new(vec![TableCell::new(&self.id), TableCell::new(&self.name)])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-05 22:20:08 +01:00
|
|
|
pub struct Meme {
|
|
|
|
pub id: String,
|
|
|
|
pub link: String,
|
|
|
|
pub path: String,
|
|
|
|
pub category: String,
|
|
|
|
pub user: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Meme {
|
|
|
|
pub fn file_name(&self) -> Result<&str> {
|
|
|
|
self.path
|
|
|
|
.split('/')
|
|
|
|
.last()
|
|
|
|
.ok_or_else(|| anyhow!("failed to get file name. server response invalid"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
impl IntoTableRow for Meme {
|
|
|
|
fn into_table_row(&self) -> Row<'_> {
|
2020-12-05 22:20:08 +01:00
|
|
|
Row::new(vec![
|
|
|
|
TableCell::new(&self.link),
|
|
|
|
TableCell::new(&self.category),
|
|
|
|
TableCell::new(&self.user),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
|
2020-12-19 19:43:23 +01:00
|
|
|
pub struct User {
|
|
|
|
pub name: String,
|
|
|
|
pub id: Option<String>,
|
|
|
|
pub tokenhash: Option<String>,
|
|
|
|
pub userdir: Option<String>,
|
|
|
|
pub dayuploads: String,
|
2020-12-05 22:20:08 +01:00
|
|
|
}
|
2020-12-19 19:43:23 +01:00
|
|
|
|
|
|
|
impl User {
|
|
|
|
pub fn get_id(&self) -> Option<&String> {
|
2020-12-20 20:52:22 +01:00
|
|
|
self.id
|
|
|
|
.as_ref()
|
2020-12-19 19:43:23 +01:00
|
|
|
.or(self.tokenhash.as_ref())
|
|
|
|
.or(self.userdir.as_ref())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:13:19 +01:00
|
|
|
impl IntoTableRow for User {
|
|
|
|
fn into_table_row(&self) -> Row<'_> {
|
2020-12-19 19:43:23 +01:00
|
|
|
Row::new(vec![
|
|
|
|
TableCell::new(&self.name),
|
|
|
|
TableCell::new(&self.get_id().map(String::as_ref).unwrap_or("[No ID]")),
|
|
|
|
TableCell::new(&self.dayuploads),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|