Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b1ab165665 | |||
| b8d01b567c | |||
| 3a5dde9ee3 | |||
| 9e09110b16 | |||
| 511e62b58c | |||
| 41aa78b672 | |||
| 21163b277d | |||
| 7a0d3b7f40 | |||
| 6d2b8c77b2 | |||
| 8bdd9edbb0 | |||
| 5e6b0b21a6 | |||
| 19274d444d | |||
| 63e2f9f791 | |||
| 8964d1c069 | |||
| 8808126905 | |||
| d36aaac836 | |||
| bb2c6c4683 | |||
| f8d457a096 | |||
| 165adb2775 | |||
| e832ccf07e | |||
| 6df6de098b | |||
| 364b23e62a | |||
| 7b2ed32043 | |||
| d094f7bbef | |||
| f98429159f | |||
| 3dca408356 | |||
| 1655e342b7 | |||
| 7223c35658 | |||
| b85bcd1c7a | |||
| 8536d335bc | |||
| b34f7436c2 |
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkou code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Build
|
- name: Set up Docker Build
|
||||||
@@ -33,5 +33,7 @@ jobs:
|
|||||||
file: AobaServer/Dockerfile
|
file: AobaServer/Dockerfile
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: git.kaisei.app/amatsugu/aoba:${{ env.VERSION }}
|
tags: |
|
||||||
|
git.kaisei.app/amatsugu/aoba:${{ env.VERSION }}
|
||||||
|
git.kaisei.app/amatsugu/aoba:latest
|
||||||
build-args: VERSION=${{ env.VERSION }}
|
build-args: VERSION=${{ env.VERSION }}
|
||||||
|
|||||||
Generated
+1893
-573
File diff suppressed because it is too large
Load Diff
@@ -6,8 +6,8 @@ edition = "2024"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus = { version = "0.6.0", features = ["router"] }
|
dioxus = { version = "0.7.3", features = ["router"] }
|
||||||
serde = "1.0.219"
|
serde = "1.0.228"
|
||||||
serde_repr = "0.1.20"
|
serde_repr = "0.1.20"
|
||||||
tonic = { version = "*", default-features = false, features = [
|
tonic = { version = "*", default-features = false, features = [
|
||||||
"codegen",
|
"codegen",
|
||||||
@@ -15,7 +15,8 @@ tonic = { version = "*", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
prost = "0.13"
|
prost = "0.13"
|
||||||
tonic-web-wasm-client = "0.7"
|
tonic-web-wasm-client = "0.7"
|
||||||
web-sys = { version = "0.3.77", features = ["Storage", "Window"] }
|
web-sys = { version = "0.3.91", features = ["Storage", "Window"] }
|
||||||
|
dioxus-primitives = { git = "https://github.com/DioxusLabs/components", version = "0.0.1", default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = { version = "*", default-features = false, features = ["prost"] }
|
tonic-build = { version = "*", default-features = false, features = ["prost"] }
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/* This file contains the global styles for the styled dioxus components. You only
|
||||||
|
* need to import this file once in your project root.
|
||||||
|
*/
|
||||||
|
@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");
|
||||||
|
|
||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: var(--secondary-color-4);
|
||||||
|
font-family: Inter, sans-serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--dark: initial;
|
||||||
|
--light: ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
--dark: ;
|
||||||
|
--light: initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* Primary colors */
|
||||||
|
--primary-color: var(--dark, #000) var(--light, #fff);
|
||||||
|
--primary-color-1: var(--dark, #0e0e0e) var(--light, #fbfbfb);
|
||||||
|
--primary-color-2: var(--dark, #0a0a0a) var(--light, #fff);
|
||||||
|
--primary-color-3: var(--dark, #141313) var(--light, #f8f8f8);
|
||||||
|
--primary-color-4: var(--dark, #1a1a1a) var(--light, #f8f8f8);
|
||||||
|
--primary-color-5: var(--dark, #262626) var(--light, #f5f5f5);
|
||||||
|
--primary-color-6: var(--dark, #232323) var(--light, #e5e5e5);
|
||||||
|
--primary-color-7: var(--dark, #3e3e3e) var(--light, #b0b0b0);
|
||||||
|
|
||||||
|
/* Secondary colors */
|
||||||
|
--secondary-color: var(--dark, #fff) var(--light, #000);
|
||||||
|
--secondary-color-1: var(--dark, #fafafa) var(--light, #000);
|
||||||
|
--secondary-color-2: var(--dark, #e6e6e6) var(--light, #0d0d0d);
|
||||||
|
--secondary-color-3: var(--dark, #dcdcdc) var(--light, #2b2b2b);
|
||||||
|
--secondary-color-4: var(--dark, #d4d4d4) var(--light, #111);
|
||||||
|
--secondary-color-5: var(--dark, #a1a1a1) var(--light, #848484);
|
||||||
|
--secondary-color-6: var(--dark, #5d5d5d) var(--light, #d0d0d0);
|
||||||
|
|
||||||
|
/* Highlight colors */
|
||||||
|
--focused-border-color: var(--dark, #2b7fff) var(--light, #2b7fff);
|
||||||
|
--primary-success-color: var(--dark, #02271c) var(--light, #ecfdf5);
|
||||||
|
--secondary-success-color: var(--dark, #b6fae3) var(--light, #10b981);
|
||||||
|
--primary-warning-color: var(--dark, #342203) var(--light, #fffbeb);
|
||||||
|
--secondary-warning-color: var(--dark, #feeac7) var(--light, #f59e0b);
|
||||||
|
--primary-error-color: var(--dark, #a22e2e) var(--light, #dc2626);
|
||||||
|
--secondary-error-color: var(--dark, #9b1c1c) var(--light, #ef4444);
|
||||||
|
--contrast-error-color: var(--dark, var(--secondary-color-3))
|
||||||
|
var(--light, var(--primary-color));
|
||||||
|
--primary-info-color: var(--dark, var(--primary-color-5))
|
||||||
|
var(--light, var(--primary-color));
|
||||||
|
--secondary-info-color: var(--dark, var(--primary-color-7))
|
||||||
|
var(--light, var(--secondary-color-3));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Modern browsers with `scrollbar-*` support */
|
||||||
|
@supports (scrollbar-width: auto) {
|
||||||
|
:not(:hover) {
|
||||||
|
scrollbar-color: rgb(0 0 0 / 0%) rgb(0 0 0 / 0%);
|
||||||
|
}
|
||||||
|
|
||||||
|
:hover {
|
||||||
|
scrollbar-color: var(--secondary-color-2) rgb(0 0 0 / 0%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Legacy browsers with `::-webkit-scrollbar-*` support */
|
||||||
|
@supports selector(::-webkit-scrollbar) {
|
||||||
|
:root::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
$mainBGColor: #584577;
|
$mainBGColor: #584577;
|
||||||
$featureColor: #ce2d4f;
|
$featureColor: #ce2d4f;
|
||||||
|
$focusColor: #ff3862;
|
||||||
$accentColor: #f0eaf8;
|
$accentColor: #f0eaf8;
|
||||||
|
|
||||||
$mainTextColor: #eee;
|
$mainTextColor: #eee;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@import "colors";
|
||||||
|
div[role="menu"] {
|
||||||
|
backdrop-filter: blur(10px) brightness(0.5) grayscale(1);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-width: 300px;
|
||||||
|
width: auto;
|
||||||
|
outline: none;
|
||||||
|
width: max-content;
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
@import "colors";
|
@import "colors";
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
scrollbar-color: $accentColor transparent;
|
||||||
|
scrollbar-width: thin;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
@@ -18,6 +20,9 @@
|
|||||||
.stickyTop {
|
.stickyTop {
|
||||||
top: 0;
|
top: 0;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
z-index: 100;
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
box-shadow: 0 3px 10px $mainBGColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -34,6 +39,8 @@ body {
|
|||||||
#content {
|
#content {
|
||||||
grid-area: Content;
|
grid-area: Content;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
height: 100dvh;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
/* margin-left: $navBarSize; */
|
/* margin-left: $navBarSize; */
|
||||||
}
|
}
|
||||||
@@ -105,6 +112,14 @@ $mediaItemSize: 300px;
|
|||||||
|
|
||||||
&.placeholder {
|
&.placeholder {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.nsfw img {
|
||||||
|
filter: blur(20px);
|
||||||
|
transition: filter 0.25s ease-out;
|
||||||
|
}
|
||||||
|
&.nsfw:hover img {
|
||||||
|
filter: blur(0px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,3 +167,70 @@ form {
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
user-select: all;
|
user-select: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.contextMenu {
|
||||||
|
backdrop-filter: blur(10px) brightness(0.5) grayscale(1);
|
||||||
|
position: absolute;
|
||||||
|
z-index: 100;
|
||||||
|
|
||||||
|
.itemList {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.contextItem {
|
||||||
|
border-left: 4px solid $featureColor;
|
||||||
|
$size: 30px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: $size 1fr;
|
||||||
|
grid-template-areas: "Icon Label";
|
||||||
|
height: $size;
|
||||||
|
transition: border 0.1s ease-out;
|
||||||
|
cursor: default;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
grid-area: Label;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
grid-area: Icon;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $accentColor;
|
||||||
|
color: $invertTextColor;
|
||||||
|
border-left: 10px solid $focusColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5;
|
||||||
|
padding: 10px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
transition: all 0.25s ease-out;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
padding: 5px 10px;
|
||||||
|
background-color: $featureColor;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $focusColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub struct InputProps {
|
|||||||
pub label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub placeholder: Option<String>,
|
pub placeholder: Option<String>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub oninput: Option<EventHandler<FormEvent>>,
|
pub oninput: Option<EventHandler<Event<FormData>>>,
|
||||||
pub required: Option<bool>,
|
pub required: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +25,9 @@ pub fn Input(props: InputProps) -> Element {
|
|||||||
if let Some(mut s) = props.value {
|
if let Some(mut s) = props.value {
|
||||||
s.set(e.value());
|
s.set(e.value());
|
||||||
}
|
}
|
||||||
|
if let Some(handler) = props.oninput{
|
||||||
|
handler.call(e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
name: props.name,
|
name: props.name,
|
||||||
placeholder: ph,
|
placeholder: ph,
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_primitives::context_menu::{
|
||||||
|
self, ContextMenuContentProps, ContextMenuItemProps, ContextMenuProps, ContextMenuTriggerProps,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ContextMenu(props: ContextMenuProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: asset!("./style.css") }
|
||||||
|
context_menu::ContextMenu {
|
||||||
|
disabled: props.disabled,
|
||||||
|
open: props.open,
|
||||||
|
default_open: props.default_open,
|
||||||
|
on_open_change: props.on_open_change,
|
||||||
|
roving_loop: props.roving_loop,
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ContextMenuTrigger(props: ContextMenuTriggerProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
context_menu::ContextMenuTrigger {
|
||||||
|
padding: "20px",
|
||||||
|
background: "var(--primary-color)",
|
||||||
|
border: "1px dashed var(--primary-color-6)",
|
||||||
|
border_radius: ".5rem",
|
||||||
|
cursor: "context-menu",
|
||||||
|
user_select: "none",
|
||||||
|
text_align: "center",
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ContextMenuContent(props: ContextMenuContentProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
context_menu::ContextMenuContent {
|
||||||
|
class: "context-menu-content",
|
||||||
|
id: props.id,
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ContextMenuItem(props: ContextMenuItemProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
context_menu::ContextMenuItem {
|
||||||
|
class: "context-menu-item",
|
||||||
|
disabled: props.disabled,
|
||||||
|
value: props.value,
|
||||||
|
index: props.index,
|
||||||
|
on_select: props.on_select,
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
mod component;
|
||||||
|
pub use component::*;
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
.context-menu-content {
|
||||||
|
z-index: 1000;
|
||||||
|
min-width: 220px;
|
||||||
|
padding: 0.25rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: var(--dark, var(--primary-color-5))
|
||||||
|
var(--light, var(--primary-color));
|
||||||
|
box-shadow: inset 0 0 0 1px var(--dark, var(--primary-color-7))
|
||||||
|
var(--light, var(--primary-color-6));
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
will-change: transform, opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-content[data-state="closed"] {
|
||||||
|
animation: context-menu-animate-out 150ms ease-in forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes context-menu-animate-out {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1) translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.95) translateY(-2px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-content[data-state="open"] {
|
||||||
|
animation: context-menu-animate-in 150ms ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes context-menu-animate-in {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.95) translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1) translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: calc(0.5rem - 0.25rem);
|
||||||
|
color: var(--secondary-color-4);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
outline: none;
|
||||||
|
transition: background-color 100ms ease-out;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-item[data-disabled="true"] {
|
||||||
|
color: var(--secondary-color-5);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-item:hover:not([data-disabled="true"]),
|
||||||
|
.context-menu-item:focus-visible {
|
||||||
|
background: var(--light, var(--primary-color-4))
|
||||||
|
var(--dark, var(--primary-color-7));
|
||||||
|
color: var(--light, var(--secondary-color-1))
|
||||||
|
var(--dark, var(--secondary-color-4));
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ use crate::{
|
|||||||
#[derive(PartialEq, Clone, Props)]
|
#[derive(PartialEq, Clone, Props)]
|
||||||
pub struct MediaGridProps {
|
pub struct MediaGridProps {
|
||||||
pub query: Option<String>,
|
pub query: Option<String>,
|
||||||
|
pub max_page: Signal<i32>,
|
||||||
|
pub total_items: Signal<i32>,
|
||||||
#[props(default = Some(1))]
|
#[props(default = Some(1))]
|
||||||
pub page: Option<i32>,
|
pub page: Option<i32>,
|
||||||
#[props(default = Some(100))]
|
#[props(default = Some(100))]
|
||||||
@@ -33,12 +35,13 @@ impl Into<PageFilter> for MediaGridProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn MediaGrid(props: MediaGridProps) -> Element {
|
pub fn MediaGrid(mut props: MediaGridProps) -> Element {
|
||||||
let media_result = use_resource(use_reactive!(|(props)| async move {
|
let media_result = use_resource(use_reactive!(|(props)| async move {
|
||||||
let mut client = get_rpc_client();
|
let mut client = get_rpc_client();
|
||||||
let result = client.list_media(props.into_request()).await;
|
let result = client.list_media(props.into_request()).await;
|
||||||
if let Ok(items) = result {
|
if let Ok(items) = result {
|
||||||
return Ok(items.into_inner());
|
let res = items.into_inner();
|
||||||
|
return Ok(res);
|
||||||
} else {
|
} else {
|
||||||
let err = result.err().unwrap();
|
let err = result.err().unwrap();
|
||||||
let message = err.message();
|
let message = err.message();
|
||||||
@@ -48,14 +51,24 @@ pub fn MediaGrid(props: MediaGridProps) -> Element {
|
|||||||
|
|
||||||
match media_result.cloned() {
|
match media_result.cloned() {
|
||||||
Some(value) => match value {
|
Some(value) => match value {
|
||||||
Ok(result) => rsx! {
|
Ok(result) => {
|
||||||
|
let pagination = result.pagination.unwrap();
|
||||||
|
let total_pages = pagination.total_pages;
|
||||||
|
let total_items = pagination.total_items;
|
||||||
|
props.max_page.set(total_pages.max(1));
|
||||||
|
props.total_items.set(total_items.max(1));
|
||||||
|
return rsx! {
|
||||||
div {
|
div {
|
||||||
class: "mediaGrid",
|
class: "mediaGrid",
|
||||||
|
// oncontextmenu: oncontext,
|
||||||
{result.items.iter().map(|itm| rsx!{
|
{result.items.iter().map(|itm| rsx!{
|
||||||
MediaItem { item: Some(itm.clone()) }
|
MediaItem {
|
||||||
|
item: itm.clone()
|
||||||
|
}
|
||||||
})},
|
})},
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
}
|
||||||
Err(msg) => rsx! {
|
Err(msg) => rsx! {
|
||||||
div {
|
div {
|
||||||
class: "mediaGrid",
|
class: "mediaGrid",
|
||||||
@@ -69,7 +82,7 @@ pub fn MediaGrid(props: MediaGridProps) -> Element {
|
|||||||
div{
|
div{
|
||||||
class: "mediaGrid",
|
class: "mediaGrid",
|
||||||
{(0..50).map(|_| rsx!{
|
{(0..50).map(|_| rsx!{
|
||||||
MediaItem {}
|
MediaItem { }
|
||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,21 +1,53 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_primitives::context_menu::{ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger};
|
||||||
|
use tonic::{Response, Status};
|
||||||
|
use web_sys::window;
|
||||||
|
|
||||||
use crate::{HOST, rpc::aoba::MediaModel};
|
use crate::{
|
||||||
|
HOST,
|
||||||
|
route::Route,
|
||||||
|
rpc::{
|
||||||
|
aoba::{Id, MediaClass, MediaModel, SetMediaClassRequest},
|
||||||
|
get_rpc_client,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Props)]
|
#[derive(PartialEq, Clone, Props)]
|
||||||
pub struct MediaItemProps {
|
pub struct MediaItemProps
|
||||||
|
{
|
||||||
pub item: Option<MediaModel>,
|
pub item: Option<MediaModel>,
|
||||||
|
// pub oncontextmenu: Option<EventHandler<Event<MouseData>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn MediaItem(props: MediaItemProps) -> Element {
|
pub fn MediaItem(props: MediaItemProps) -> Element
|
||||||
if let Some(item) = props.item {
|
{
|
||||||
|
let mut class_signal = use_signal(|| "");
|
||||||
|
if let Some(item) = props.item
|
||||||
|
{
|
||||||
let mtype = item.media_type().as_str_name();
|
let mtype = item.media_type().as_str_name();
|
||||||
let filename = item.file_name;
|
let filename = item.file_name;
|
||||||
let id = item.id.unwrap().value;
|
let id = item.id.unwrap().value;
|
||||||
let thumb = item.thumb_url;
|
let thumb = item.thumb_url;
|
||||||
|
let class = item.class;
|
||||||
|
let url = item.media_url;
|
||||||
|
let download = format!("{HOST}{url}");
|
||||||
|
|
||||||
|
match class
|
||||||
|
{
|
||||||
|
1 => class_signal.set("nsfw"),
|
||||||
|
2 => class_signal.set("secret"),
|
||||||
|
_ => class_signal.set(""),
|
||||||
|
};
|
||||||
|
|
||||||
return rsx! {
|
return rsx! {
|
||||||
a { class: "mediaItem", href: "{HOST}/m/{id}", target: "_blank",
|
ContextMenu{
|
||||||
|
ContextMenuTrigger{
|
||||||
|
a {
|
||||||
|
class: "mediaItem {class_signal()}",
|
||||||
|
href: "{HOST}{url}",
|
||||||
|
target: "_blank",
|
||||||
|
"data-id" : id.clone(),
|
||||||
img { src: "{HOST}{thumb}" }
|
img { src: "{HOST}{thumb}" }
|
||||||
span { class: "info",
|
span { class: "info",
|
||||||
span { class: "name", "{filename}" }
|
span { class: "name", "{filename}" }
|
||||||
@@ -24,9 +56,116 @@ pub fn MediaItem(props: MediaItemProps) -> Element {
|
|||||||
span { "{item.view_count}" }
|
span { "{item.view_count}" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ContextMenuContent{
|
||||||
|
ContextMenuItem {
|
||||||
|
index: 0 as usize,
|
||||||
|
value: id.clone(),
|
||||||
|
on_select: move |id: String|{
|
||||||
|
window().expect("Failed to get window")
|
||||||
|
.location().set_href(&format!("/media/{}", id))
|
||||||
|
.expect("Failed to open Url");
|
||||||
|
},
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Details"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ContextMenuItem {
|
||||||
|
index: 1 as usize,
|
||||||
|
value: "{download}",
|
||||||
|
on_select: move |url: String|{
|
||||||
|
window().expect("Failed to get window").open_with_url_and_target(&url, "_blank").expect("Failed to open url");
|
||||||
|
},
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
if class != 0 {
|
||||||
|
rsx!{ContextMenuItem {
|
||||||
|
index: 2 as usize,
|
||||||
|
value: "{id}",
|
||||||
|
on_select: async |id: String|{
|
||||||
|
_ = set_class(id, 0).await;
|
||||||
|
},
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Mark Standard"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}else{
|
||||||
|
rsx!{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if class != 1 {
|
||||||
|
rsx!{ContextMenuItem {
|
||||||
|
index: 2 as usize,
|
||||||
|
value: "{id}",
|
||||||
|
on_select: async |id: String|{
|
||||||
|
_ = set_class(id, 1).await;
|
||||||
|
},
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Mark NSFW"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}else{
|
||||||
|
rsx!{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if class != 1 {
|
||||||
|
rsx!{ContextMenuItem {
|
||||||
|
index: 2 as usize,
|
||||||
|
value: "{id}",
|
||||||
|
on_select: async |id: String|{
|
||||||
|
_ = set_class(id, 2).await;
|
||||||
|
},
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Mark Secret"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}else{
|
||||||
|
rsx!{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContextMenuItem {
|
||||||
|
index: 2 as usize,
|
||||||
|
value: "",
|
||||||
|
div{
|
||||||
|
class: "contextItem",
|
||||||
|
div{
|
||||||
|
class: "label",
|
||||||
|
"Delete"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return rsx! {
|
return rsx! {
|
||||||
div { class: "mediaItem placeholder",
|
div { class: "mediaItem placeholder",
|
||||||
img { },
|
img { },
|
||||||
@@ -41,3 +180,14 @@ pub fn MediaItem(props: MediaItemProps) -> Element {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn set_class(id: String, class: i32) -> Result<Response<()>, Status>
|
||||||
|
{
|
||||||
|
let mut client = get_rpc_client();
|
||||||
|
return client
|
||||||
|
.set_media_class(SetMediaClassRequest {
|
||||||
|
class: class,
|
||||||
|
id: Some(Id { value: id }),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
pub mod basic;
|
pub mod basic;
|
||||||
|
// mod context_menu;
|
||||||
|
mod icons;
|
||||||
mod media_grid;
|
mod media_grid;
|
||||||
mod media_item;
|
mod media_item;
|
||||||
mod metrics_token;
|
mod metrics_token;
|
||||||
mod navbar;
|
mod navbar;
|
||||||
mod notif;
|
mod notif;
|
||||||
|
mod pagination;
|
||||||
|
mod passkey;
|
||||||
mod search;
|
mod search;
|
||||||
|
// pub use context_menu::*;
|
||||||
pub use media_grid::*;
|
pub use media_grid::*;
|
||||||
pub use media_item::*;
|
pub use media_item::*;
|
||||||
pub use metrics_token::*;
|
pub use metrics_token::*;
|
||||||
pub use navbar::*;
|
pub use navbar::*;
|
||||||
pub use notif::*;
|
pub use notif::*;
|
||||||
|
pub use pagination::*;
|
||||||
|
pub use passkey::*;
|
||||||
pub use search::*;
|
pub use search::*;
|
||||||
mod icons;
|
pub mod radio_group;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub fn Navbar() -> Element {
|
|||||||
pub fn MainNaviagation() -> Element {
|
pub fn MainNaviagation() -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
div { class: "mainNav",
|
div { class: "mainNav",
|
||||||
Link { class: "navItem", to: Route::Home {}, "Home" }
|
Link { class: "navItem", to: Route::Home { }, "Home" }
|
||||||
Link { class: "navItem", to: Route::Settings {}, "Settings" }
|
Link { class: "navItem", to: Route::Settings {}, "Settings" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use dioxus::prelude::*;
|
||||||
|
use web_sys::window;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Pagination(page: Signal<i32>, max_page: Signal<i32>, item_count: Signal<i32>) -> Element
|
||||||
|
{
|
||||||
|
let cur_page_val = page.cloned();
|
||||||
|
let max_page_val = max_page.cloned();
|
||||||
|
let item_count_val = item_count.cloned();
|
||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
class: "pagination",
|
||||||
|
a {
|
||||||
|
onclick: move|_| {
|
||||||
|
page.set(1);
|
||||||
|
on_page_change();
|
||||||
|
},
|
||||||
|
"First"
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
onclick: move|_| {
|
||||||
|
let p = (cur_page_val - 1).max(1);
|
||||||
|
page.set(p);
|
||||||
|
on_page_change();
|
||||||
|
},
|
||||||
|
"Prev"
|
||||||
|
}
|
||||||
|
div { "Page {cur_page_val} of {max_page_val} ({item_count_val} Media Items)" }
|
||||||
|
a {
|
||||||
|
onclick: move|_| {
|
||||||
|
let p = (cur_page_val + 1).min(max_page_val);
|
||||||
|
page.set(p);
|
||||||
|
on_page_change();
|
||||||
|
},
|
||||||
|
"Next"
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
onclick: move|_| {
|
||||||
|
page.set(max_page_val);
|
||||||
|
on_page_change();
|
||||||
|
},
|
||||||
|
"Last"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_page_change()
|
||||||
|
{
|
||||||
|
let window = window().expect("Failed to get window");
|
||||||
|
let document = window.document().expect("Failed to get document");
|
||||||
|
document
|
||||||
|
.query_selector("#content")
|
||||||
|
.expect("Failed to find content")
|
||||||
|
.expect("Failed to find content")
|
||||||
|
.scroll_to_with_x_and_y(0.0, 0.0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
use crate::components::basic::Button;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn PasskeyRegistrationButton() -> Element
|
||||||
|
{
|
||||||
|
rsx! {
|
||||||
|
Button{
|
||||||
|
text: "Register Passkey",
|
||||||
|
onclick: move |e| {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_passkey_registration() {}
|
||||||
|
|
||||||
|
fn create_credential() {}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn PasskeyLoginButton() -> Element
|
||||||
|
{
|
||||||
|
rsx! {
|
||||||
|
Button{
|
||||||
|
text: "Login with Passkey"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_primitives::radio_group::{self, RadioGroupProps, RadioItemProps};
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn RadioGroup(props: RadioGroupProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: asset!("./style.css") }
|
||||||
|
radio_group::RadioGroup {
|
||||||
|
class: "radio-group",
|
||||||
|
value: props.value,
|
||||||
|
default_value: props.default_value,
|
||||||
|
on_value_change: props.on_value_change,
|
||||||
|
disabled: props.disabled,
|
||||||
|
required: props.required,
|
||||||
|
name: props.name,
|
||||||
|
horizontal: props.horizontal,
|
||||||
|
roving_loop: props.roving_loop,
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn RadioItem(props: RadioItemProps) -> Element {
|
||||||
|
rsx! {
|
||||||
|
radio_group::RadioItem {
|
||||||
|
class: "radio-item",
|
||||||
|
value: props.value,
|
||||||
|
index: props.index,
|
||||||
|
disabled: props.disabled,
|
||||||
|
attributes: props.attributes,
|
||||||
|
{props.children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
mod component;
|
||||||
|
pub use component::*;
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
.radio-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
background-color: transparent;
|
||||||
|
color: var(--secondary-color-4);
|
||||||
|
font-size: 14px;
|
||||||
|
gap: .75rem;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
display: block;
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 1.5rem;
|
||||||
|
background: var(--light, var(--primary-color)) var(--dark, var(--primary-color-3));
|
||||||
|
box-shadow: 0 0 0 1px var(--light, var(--primary-color-6))
|
||||||
|
var(--dark, var(--primary-color-7));
|
||||||
|
content: "";
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible::before {
|
||||||
|
box-shadow: 0 0 0 2px var(--focused-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-state="checked"]::before {
|
||||||
|
border: 0.25rem solid var(--light, var(--primary-color)) var(--dark, var(--primary-color-3));
|
||||||
|
background: var(--secondary-color-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-disabled="true"]::before {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Search(query: Signal<String>) -> Element {
|
pub fn Search(query: Signal<String>, page: Signal<i32>) -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
div { class: "searchBar stickyTop",
|
div { class: "searchBar",
|
||||||
input {
|
input {
|
||||||
r#type: "search",
|
r#type: "search",
|
||||||
placeholder: "Search Files",
|
placeholder: "Search Files",
|
||||||
value: query,
|
value: query,
|
||||||
oninput: move |event| query.set(event.value()),
|
oninput: move |event| {query.set(event.value()); page.set(1);},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use dioxus::signals::{Signal, Writable};
|
use dioxus::signals::{Signal, WritableExt};
|
||||||
use web_sys::window;
|
use web_sys::window;
|
||||||
|
|
||||||
use crate::rpc::{login, logout};
|
use crate::rpc::{login, logout};
|
||||||
|
|||||||
@@ -3,17 +3,31 @@ use dioxus::prelude::*;
|
|||||||
use crate::{Route, components::Navbar, contexts::AuthContext, views::Login};
|
use crate::{Route, components::Navbar, contexts::AuthContext, views::Login};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn MainLayout() -> Element {
|
pub fn MainLayout() -> Element
|
||||||
|
{
|
||||||
let auth_context = use_context::<AuthContext>();
|
let auth_context = use_context::<AuthContext>();
|
||||||
|
|
||||||
if auth_context.jwt.cloned().is_none() {
|
if auth_context.jwt.cloned().is_none()
|
||||||
|
{
|
||||||
return rsx! {
|
return rsx! {
|
||||||
Login {}
|
Login { }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let mut ct_renderer = use_context::<ContextMenuRenderer>();
|
||||||
|
|
||||||
return rsx! {
|
return rsx! {
|
||||||
Navbar {}
|
// ContextMenuRoot { }
|
||||||
div { id: "content", Outlet::<Route> {} }
|
Navbar { }
|
||||||
|
div {
|
||||||
|
id: "content",
|
||||||
|
// onclick: move |_| {
|
||||||
|
// ct_renderer.close();
|
||||||
|
// },
|
||||||
|
// oncontextmenu: move |_| {
|
||||||
|
// ct_renderer.close();
|
||||||
|
// },
|
||||||
|
Outlet::<Route> { }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -23,24 +23,30 @@ pub const HOST: &'static str = "https://aoba.app";
|
|||||||
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||||
const MAIN_CSS: Asset = asset!("/assets/style/main.scss");
|
const MAIN_CSS: Asset = asset!("/assets/style/main.scss");
|
||||||
const INPUT_CSS: Asset = asset!("/assets/style/inputs.scss");
|
const INPUT_CSS: Asset = asset!("/assets/style/inputs.scss");
|
||||||
|
const DX_COMPONENTS: Asset = asset!("/assets/style/dx-components.scss");
|
||||||
|
|
||||||
fn main() {
|
fn main()
|
||||||
|
{
|
||||||
dioxus::launch(App);
|
dioxus::launch(App);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn App() -> Element {
|
fn App() -> Element
|
||||||
let _auth_state = use_context_provider(|| AuthContext::new());
|
{
|
||||||
|
use_context_provider(|| AuthContext::new());
|
||||||
|
// use_context_provider(|| ContextMenuRenderer::default());
|
||||||
rsx! {
|
rsx! {
|
||||||
document::Link { rel: "icon", href: FAVICON }
|
document::Link { rel: "icon", href: FAVICON }
|
||||||
document::Link { rel: "preconnect", href: "https://fonts.googleapis.com" }
|
document::Link { rel: "preconnect", href: "https://fonts.googleapis.com" }
|
||||||
document::Link { rel: "preconnect", href: "https://fonts.gstatic.com" }
|
document::Link { rel: "preconnect", href: "https://fonts.gstatic.com" }
|
||||||
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
||||||
document::Link { rel: "stylesheet", href: INPUT_CSS }
|
document::Link { rel: "stylesheet", href: INPUT_CSS }
|
||||||
|
document::Link { rel: "stylesheet", href: DX_COMPONENTS }
|
||||||
document::Link {
|
document::Link {
|
||||||
rel: "stylesheet",
|
rel: "stylesheet",
|
||||||
href: "https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap",
|
href: "https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap",
|
||||||
}
|
}
|
||||||
Router::<Route> {}
|
|
||||||
|
Router::<Route> { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
layouts::MainLayout,
|
layouts::MainLayout,
|
||||||
views::{Home, Settings},
|
views::{Home, HomePaged, Media, Settings},
|
||||||
};
|
};
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
@@ -8,8 +8,13 @@ use dioxus::prelude::*;
|
|||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub enum Route {
|
pub enum Route {
|
||||||
#[layout(MainLayout)]
|
#[layout(MainLayout)]
|
||||||
|
|
||||||
#[route("/")]
|
#[route("/")]
|
||||||
Home {},
|
Home { },
|
||||||
|
#[route("/?:page&:q")]
|
||||||
|
HomePaged { page: i32, q: String },
|
||||||
|
#[route("/media/:id")]
|
||||||
|
Media { id: String },
|
||||||
#[route("/settings")]
|
#[route("/settings")]
|
||||||
Settings {},
|
Settings {},
|
||||||
// #[end_layout]
|
// #[end_layout]
|
||||||
|
|||||||
+32
-16
@@ -9,7 +9,8 @@ use crate::{
|
|||||||
rpc::aoba::{auth_rpc_client::AuthRpcClient, metrics_rpc_client::MetricsRpcClient},
|
rpc::aoba::{auth_rpc_client::AuthRpcClient, metrics_rpc_client::MetricsRpcClient},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod aoba {
|
pub mod aoba
|
||||||
|
{
|
||||||
tonic::include_proto!("aoba");
|
tonic::include_proto!("aoba");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,31 +22,38 @@ static RPC_CLIENT: RpcConnection = RpcConnection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct RpcConnection {
|
pub struct RpcConnection
|
||||||
|
{
|
||||||
aoba: RwLock<Option<AobaRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
aoba: RwLock<Option<AobaRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
||||||
auth: RwLock<Option<AuthRpcClient<Client>>>,
|
auth: RwLock<Option<AuthRpcClient<Client>>>,
|
||||||
metrics: RwLock<Option<MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
metrics: RwLock<Option<MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
|
||||||
jwt: RwLock<Option<String>>,
|
jwt: RwLock<Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RpcConnection {
|
impl RpcConnection
|
||||||
pub fn get_client(&self) -> AobaRpcClient<InterceptedService<Client, AuthInterceptor>> {
|
{
|
||||||
|
pub fn get_client(&self) -> AobaRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||||
|
{
|
||||||
self.ensure_client();
|
self.ensure_client();
|
||||||
return self.aoba.read().unwrap().clone().unwrap();
|
return self.aoba.read().unwrap().clone().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_auth_client(&self) -> AuthRpcClient<Client> {
|
pub fn get_auth_client(&self) -> AuthRpcClient<Client>
|
||||||
|
{
|
||||||
self.ensure_client();
|
self.ensure_client();
|
||||||
return self.auth.read().unwrap().clone().unwrap();
|
return self.auth.read().unwrap().clone().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_metrics_client(&self) -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>> {
|
pub fn get_metrics_client(&self) -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||||
|
{
|
||||||
self.ensure_client();
|
self.ensure_client();
|
||||||
return self.metrics.read().unwrap().clone().unwrap();
|
return self.metrics.read().unwrap().clone().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_client(&self) {
|
fn ensure_client(&self)
|
||||||
if self.aoba.read().unwrap().is_none() {
|
{
|
||||||
|
if self.aoba.read().unwrap().is_none()
|
||||||
|
{
|
||||||
let wasm_client = Client::new(RPC_HOST.into());
|
let wasm_client = Client::new(RPC_HOST.into());
|
||||||
let aoba_client = AobaRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor);
|
let aoba_client = AobaRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor);
|
||||||
*self.aoba.write().unwrap() = Some(aoba_client);
|
*self.aoba.write().unwrap() = Some(aoba_client);
|
||||||
@@ -58,9 +66,12 @@ impl RpcConnection {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AuthInterceptor;
|
pub struct AuthInterceptor;
|
||||||
impl Interceptor for AuthInterceptor {
|
impl Interceptor for AuthInterceptor
|
||||||
fn call(&mut self, mut request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status> {
|
{
|
||||||
if let Some(jwt) = RPC_CLIENT.jwt.read().unwrap().clone() {
|
fn call(&mut self, mut request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status>
|
||||||
|
{
|
||||||
|
if let Some(jwt) = RPC_CLIENT.jwt.read().unwrap().clone()
|
||||||
|
{
|
||||||
request
|
request
|
||||||
.metadata_mut()
|
.metadata_mut()
|
||||||
.insert("authorization", format!("Bearer {jwt}").parse().unwrap());
|
.insert("authorization", format!("Bearer {jwt}").parse().unwrap());
|
||||||
@@ -69,21 +80,26 @@ impl Interceptor for AuthInterceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rpc_client() -> AobaRpcClient<InterceptedService<Client, AuthInterceptor>> {
|
pub fn get_rpc_client() -> AobaRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||||
|
{
|
||||||
return RPC_CLIENT.get_client();
|
return RPC_CLIENT.get_client();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_auth_rpc_client() -> AuthRpcClient<Client> {
|
pub fn get_auth_rpc_client() -> AuthRpcClient<Client>
|
||||||
|
{
|
||||||
return RPC_CLIENT.get_auth_client();
|
return RPC_CLIENT.get_auth_client();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_metrics_rpc_client() -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>> {
|
pub fn get_metrics_rpc_client() -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>
|
||||||
|
{
|
||||||
return RPC_CLIENT.get_metrics_client();
|
return RPC_CLIENT.get_metrics_client();
|
||||||
}
|
}
|
||||||
pub fn login(jwt: String) {
|
pub fn login(jwt: String)
|
||||||
|
{
|
||||||
*RPC_CLIENT.jwt.write().unwrap() = Some(jwt);
|
*RPC_CLIENT.jwt.write().unwrap() = Some(jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logout() {
|
pub fn logout()
|
||||||
|
{
|
||||||
*RPC_CLIENT.jwt.write().unwrap() = None;
|
*RPC_CLIENT.jwt.write().unwrap() = None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,36 @@
|
|||||||
use crate::components::{MediaGrid, Search};
|
use crate::components::{MediaGrid, Pagination, Search};
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Home() -> Element {
|
pub fn Home() -> Element
|
||||||
|
{
|
||||||
let query = use_signal(|| "".to_string());
|
let query = use_signal(|| "".to_string());
|
||||||
|
let page = use_signal(|| 1 as i32);
|
||||||
|
let max_page = use_signal(|| 1 as i32);
|
||||||
|
let item_count = use_signal(|| 0 as i32);
|
||||||
rsx! {
|
rsx! {
|
||||||
Search { query }
|
div {
|
||||||
MediaGrid { query: query.cloned() }
|
class: "stickyTop",
|
||||||
|
Search { query, page },
|
||||||
|
Pagination { page, max_page, item_count },
|
||||||
|
}
|
||||||
|
MediaGrid { query: query.cloned(), page: page.cloned(), max_page, total_items: item_count }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn HomePaged(page: i32, q: String) -> Element
|
||||||
|
{
|
||||||
|
let query = use_signal(|| q);
|
||||||
|
let page = use_signal(|| page);
|
||||||
|
let max_page = use_signal(|| 1 as i32);
|
||||||
|
let item_count = use_signal(|| 0 as i32);
|
||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
class: "stickyTop",
|
||||||
|
Search { query, page },
|
||||||
|
Pagination { page, max_page, item_count },
|
||||||
|
}
|
||||||
|
MediaGrid { query: query.cloned(), page: page.cloned(), max_page, total_items: item_count }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
use crate::HOST;
|
||||||
|
use crate::components::radio_group::{RadioGroup, RadioItem};
|
||||||
|
use crate::rpc::aoba::SetMediaClassRequest;
|
||||||
|
use crate::rpc::{
|
||||||
|
aoba::{Id, MediaModel},
|
||||||
|
get_rpc_client,
|
||||||
|
};
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Media(id: String) -> Element
|
||||||
|
{
|
||||||
|
let media_result = use_resource(use_reactive!(|(id)| async move {
|
||||||
|
let mut client = get_rpc_client();
|
||||||
|
let result = client.get_media(Id { value: id.clone() }).await;
|
||||||
|
if let Ok(item) = result
|
||||||
|
{
|
||||||
|
let res = item.into_inner();
|
||||||
|
return res.value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
return match media_result.cloned().unwrap_or(None)
|
||||||
|
{
|
||||||
|
Some(media) =>
|
||||||
|
{
|
||||||
|
return rsx! {MediaPage{media: media}};
|
||||||
|
}
|
||||||
|
None => rsx! {"Not Found"},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn MediaPage(media: MediaModel) -> Element
|
||||||
|
{
|
||||||
|
let url = media.thumb_url;
|
||||||
|
let id = media.id.expect("Media has no id").value.clone();
|
||||||
|
let cur_class = match media.class
|
||||||
|
{
|
||||||
|
0 => "Standard",
|
||||||
|
1 => "NSFW",
|
||||||
|
2 => "Secret",
|
||||||
|
_ => "Unkown",
|
||||||
|
};
|
||||||
|
rsx! {
|
||||||
|
img { src: "{HOST}{url}", }
|
||||||
|
label { "Media Class: {cur_class}" }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
mod home;
|
mod home;
|
||||||
mod login;
|
mod login;
|
||||||
|
mod media;
|
||||||
pub use home::*;
|
pub use home::*;
|
||||||
pub use login::*;
|
pub use login::*;
|
||||||
|
pub use media::*;
|
||||||
|
|
||||||
mod settings;
|
mod settings;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
use crate::{components::MetricsToken, rpc::get_rpc_client};
|
use crate::{
|
||||||
|
components::{MetricsToken, PasskeyRegistrationButton},
|
||||||
|
rpc::get_rpc_client,
|
||||||
|
};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Settings() -> Element {
|
pub fn Settings() -> Element
|
||||||
|
{
|
||||||
let dst = use_resource(async move || {
|
let dst = use_resource(async move || {
|
||||||
let result = get_rpc_client().get_share_x_destination(()).await;
|
let result = get_rpc_client().get_share_x_destination(()).await;
|
||||||
if let Ok(d) = result {
|
if let Ok(d) = result
|
||||||
if let Some(r) = d.into_inner().dst_result {
|
{
|
||||||
return match r {
|
if let Some(r) = d.into_inner().dst_result
|
||||||
|
{
|
||||||
|
return match r
|
||||||
|
{
|
||||||
crate::rpc::aoba::share_x_response::DstResult::Destination(json) => json,
|
crate::rpc::aoba::share_x_response::DstResult::Destination(json) => json,
|
||||||
crate::rpc::aoba::share_x_response::DstResult::Error(err) => err,
|
crate::rpc::aoba::share_x_response::DstResult::Error(err) => err,
|
||||||
};
|
};
|
||||||
@@ -28,5 +35,6 @@ pub fn Settings() -> Element {
|
|||||||
pre { class: "codeSelect", "{d}" }
|
pre { class: "codeSelect", "{d}" }
|
||||||
}
|
}
|
||||||
MetricsToken { }
|
MetricsToken { }
|
||||||
|
PasskeyRegistrationButton { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -1,22 +1,22 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FFMpegCore" Version="5.2.0" />
|
<PackageReference Include="FFMpegCore" Version="5.4.0" />
|
||||||
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.6" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.3" />
|
||||||
<PackageReference Include="MaybeError" Version="1.1.0" />
|
<PackageReference Include="MaybeError" Version="1.2.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.6" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.3" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="3.4.0" />
|
<PackageReference Include="MongoDB.Driver" Version="3.6.0" />
|
||||||
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="2.1.0" />
|
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="3.0.0" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.6" />
|
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
|
||||||
<PackageReference Include="ZLinq" Version="1.4.12" />
|
<PackageReference Include="ZLinq" Version="1.5.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
|
||||||
namespace AobaCore.Models;
|
namespace AobaCore.Models;
|
||||||
|
|
||||||
[BsonIgnoreExtraElements]
|
[BsonIgnoreExtraElements]
|
||||||
@@ -16,23 +18,28 @@ public class Media
|
|||||||
public ObjectId Owner { get; set; }
|
public ObjectId Owner { get; set; }
|
||||||
public DateTime UploadDate { get; set; }
|
public DateTime UploadDate { get; set; }
|
||||||
public string[] Tags { get; set; } = [];
|
public string[] Tags { get; set; } = [];
|
||||||
|
public Size? Dimensions { get; set; }
|
||||||
public Dictionary<ThumbnailSize, ObjectId> Thumbnails { get; set; } = [];
|
public Dictionary<ThumbnailSize, ObjectId> Thumbnails { get; set; } = [];
|
||||||
|
public MediaClass Class { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public static readonly Dictionary<string, MediaType> KnownTypes = new()
|
public static readonly Dictionary<string, MediaType> KnownTypes = new()
|
||||||
{
|
{
|
||||||
{ ".jpg", MediaType.Image },
|
{ ".jpg", MediaType.Image },
|
||||||
{ ".avif", MediaType.Image },
|
|
||||||
{ ".jpeg", MediaType.Image },
|
{ ".jpeg", MediaType.Image },
|
||||||
|
{ ".jxr", MediaType.Image },
|
||||||
|
{ ".avif", MediaType.Image },
|
||||||
{ ".png", MediaType.Image },
|
{ ".png", MediaType.Image },
|
||||||
{ ".apng", MediaType.Image },
|
{ ".apng", MediaType.Image },
|
||||||
{ ".webp", MediaType.Image },
|
{ ".webp", MediaType.Image },
|
||||||
|
{ ".qoi", MediaType.Image },
|
||||||
{ ".ico", MediaType.Image },
|
{ ".ico", MediaType.Image },
|
||||||
{ ".gif", MediaType.Image },
|
{ ".gif", MediaType.Image },
|
||||||
{ ".mp3", MediaType.Audio },
|
{ ".mp3", MediaType.Audio },
|
||||||
{ ".flac", MediaType.Audio },
|
{ ".flac", MediaType.Audio },
|
||||||
{ ".alac", MediaType.Audio },
|
{ ".alac", MediaType.Audio },
|
||||||
{ ".mp4", MediaType.Video },
|
{ ".mp4", MediaType.Video },
|
||||||
|
{ ".m4v", MediaType.Video },
|
||||||
{ ".webm", MediaType.Video },
|
{ ".webm", MediaType.Video },
|
||||||
{ ".mov", MediaType.Video },
|
{ ".mov", MediaType.Video },
|
||||||
{ ".avi", MediaType.Video },
|
{ ".avi", MediaType.Video },
|
||||||
@@ -79,7 +86,7 @@ public class Media
|
|||||||
{
|
{
|
||||||
return this switch
|
return this switch
|
||||||
{
|
{
|
||||||
//Media { MediaType: MediaType.Raw or MediaType.Text or MediaType.Code} => $"/i/dl/{MediaId}/{Filename}",
|
Media { MediaType: MediaType.Raw or MediaType.Text or MediaType.Code } => $"/m/{MediaId}/{Uri.EscapeDataString(Filename)}",
|
||||||
_ => $"/m/{MediaId}"
|
_ => $"/m/{MediaId}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -111,3 +118,10 @@ public enum MediaType
|
|||||||
Code,
|
Code,
|
||||||
Raw
|
Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MediaClass
|
||||||
|
{
|
||||||
|
Standard,
|
||||||
|
NSFW,
|
||||||
|
Secret
|
||||||
|
}
|
||||||
@@ -5,13 +5,13 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AobaCore.Models;
|
namespace AobaCore.Models;
|
||||||
public class PagedResult<T>(List<T> items, int page, int pageSize, long totalItems)
|
public class PagedResult<T>(List<T> items, int page, int pageSize, int totalItems)
|
||||||
{
|
{
|
||||||
public List<T> Items { get; set; } = items;
|
public List<T> Items { get; set; } = items;
|
||||||
public int Page { get; set; } = page;
|
public int Page { get; set; } = page;
|
||||||
public int PageSize { get; set; } = pageSize;
|
public int PageSize { get; set; } = pageSize;
|
||||||
public long TotalItems { get; set; } = totalItems;
|
public int TotalItems { get; set; } = totalItems;
|
||||||
public long TotalPages { get; set; } = totalItems / pageSize;
|
public int TotalPages { get; set; } = (totalItems / pageSize) + 1;
|
||||||
public string? Query { get; set; }
|
public string? Query { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using MongoDB.Driver.GridFS;
|
|||||||
|
|
||||||
namespace AobaCore.Services;
|
namespace AobaCore.Services;
|
||||||
|
|
||||||
public class AobaService(IMongoDatabase db, ThumbnailService thumbnailService, ILogger<AobaService> logger)
|
public class AobaService(IMongoDatabase db)
|
||||||
{
|
{
|
||||||
private readonly IMongoCollection<Media> _media = db.GetCollection<Media>("media");
|
private readonly IMongoCollection<Media> _media = db.GetCollection<Media>("media");
|
||||||
private readonly GridFSBucket _gridFs = new(db);
|
private readonly GridFSBucket _gridFs = new(db);
|
||||||
@@ -20,32 +20,47 @@ public class AobaService(IMongoDatabase db, ThumbnailService thumbnailService, I
|
|||||||
return await _media.Find(m => m.LegacyId == id).FirstOrDefaultAsync(cancellationToken);
|
return await _media.Find(m => m.LegacyId == id).FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Media?> GetMediaFromFileAsync(ObjectId id, CancellationToken cancellationToken = default)
|
public async Task<Media?> GetMediaAsync(ObjectId id, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100)
|
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var filters = new List<FilterDefinition<Media>>()
|
||||||
{
|
{
|
||||||
var filter = Builders<Media>.Filter.And([
|
|
||||||
string.IsNullOrWhiteSpace(query) ? "{}" : Builders<Media>.Filter.Text(query),
|
string.IsNullOrWhiteSpace(query) ? "{}" : Builders<Media>.Filter.Text(query),
|
||||||
Builders<Media>.Filter.Eq(m => m.Owner, userId)
|
Builders<Media>.Filter.Eq(m => m.Owner, userId)
|
||||||
]);
|
};
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
filters.Add(Builders<Media>.Filter.Ne(m => m.Class, MediaClass.Secret));
|
||||||
var sort = Builders<Media>.Sort.Descending(m => m.UploadDate);
|
var sort = Builders<Media>.Sort.Descending(m => m.UploadDate);
|
||||||
var find = _media.Find(filter);
|
var find = _media.Find(Builders<Media>.Filter.And(filters));
|
||||||
|
|
||||||
var total = await find.CountDocumentsAsync();
|
var total = await find.CountDocumentsAsync(cancellationToken);
|
||||||
page -= 1;
|
page -= 1;
|
||||||
var items = await find.Sort(sort).Skip(page * pageSize).Limit(pageSize).ToListAsync();
|
var items = await find.Sort(sort).Skip(page * pageSize).Limit(pageSize).ToListAsync(cancellationToken);
|
||||||
return new PagedResult<Media>(items, page, pageSize, total);
|
return new PagedResult<Media>(items, page, pageSize, (int)total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<Media>> FindMediaWithExtAsync(string ext, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var filter = Builders<Media>.Filter.Eq(m => m.Ext, ext);
|
||||||
|
return await _media.Find(filter).ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public Task AddMediaAsync(Media media, CancellationToken cancellationToken = default)
|
public Task AddMediaAsync(Media media, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return _media.InsertOneAsync(media, null, cancellationToken);
|
return _media.InsertOneAsync(media, null, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SetMediaClassAsync(ObjectId mediaId, MediaClass mediaClass, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var update = Builders<Media>.Update
|
||||||
|
.Set(m => m.Class, mediaClass);
|
||||||
|
await _media.UpdateOneAsync(m => m.MediaId == mediaId, update, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task AddThumbnailAsync(ObjectId mediaId, ObjectId thumbId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public async Task AddThumbnailAsync(ObjectId mediaId, ObjectId thumbId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var upate = Builders<Media>.Update.Set(m => m.Thumbnails[size], thumbId);
|
var upate = Builders<Media>.Update.Set(m => m.Thumbnails[size], thumbId);
|
||||||
@@ -53,6 +68,13 @@ public class AobaService(IMongoDatabase db, ThumbnailService thumbnailService, I
|
|||||||
await _media.UpdateOneAsync(m => m.MediaId == mediaId, upate, cancellationToken: cancellationToken);
|
await _media.UpdateOneAsync(m => m.MediaId == mediaId, upate, cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RemoveThumbnailAsync(ObjectId mediaId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var upate = Builders<Media>.Update.Unset(m => m.Thumbnails[size]);
|
||||||
|
|
||||||
|
await _media.UpdateOneAsync(m => m.MediaId == mediaId, upate, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<ObjectId> GetThumbnailIdAsync(ObjectId mediaId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public async Task<ObjectId> GetThumbnailIdAsync(ObjectId mediaId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var thumb = await _media.Find(m => m.MediaId == mediaId).Project(m => m.Thumbnails[size]).FirstOrDefaultAsync(cancellationToken);
|
var thumb = await _media.Find(m => m.MediaId == mediaId).Project(m => m.Thumbnails[size]).FirstOrDefaultAsync(cancellationToken);
|
||||||
@@ -79,6 +101,10 @@ public class AobaService(IMongoDatabase db, ThumbnailService thumbnailService, I
|
|||||||
{
|
{
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
data.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MaybeEx<GridFSDownloadStream, GridFSException>> GetFileStreamAsync(ObjectId mediaId, bool seekable = false, CancellationToken cancellationToken = default)
|
public async Task<MaybeEx<GridFSDownloadStream, GridFSException>> GetFileStreamAsync(ObjectId mediaId, bool seekable = false, CancellationToken cancellationToken = default)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
using FFMpegCore;
|
using FFMpegCore;
|
||||||
using FFMpegCore.Pipes;
|
using FFMpegCore.Pipes;
|
||||||
|
|
||||||
|
|
||||||
using MaybeError.Errors;
|
using MaybeError.Errors;
|
||||||
|
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
@@ -10,10 +11,12 @@ using MongoDB.Driver;
|
|||||||
using MongoDB.Driver.GridFS;
|
using MongoDB.Driver.GridFS;
|
||||||
|
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Formats;
|
||||||
using SixLabors.ImageSharp.Processing;
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -25,6 +28,28 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
{
|
{
|
||||||
private readonly GridFSBucket _gridfs = new GridFSBucket(db);
|
private readonly GridFSBucket _gridfs = new GridFSBucket(db);
|
||||||
|
|
||||||
|
public async Task<Error?> DeleteThumbnailAsync(ObjectId mediaId, ThumbnailSize size)
|
||||||
|
{
|
||||||
|
var thumbId = await aobaService.GetThumbnailIdAsync(mediaId, size);
|
||||||
|
if (thumbId == default)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _gridfs.DeleteAsync(thumbId);
|
||||||
|
await aobaService.RemoveThumbnailAsync(mediaId, size);
|
||||||
|
}
|
||||||
|
catch (GridFSFileNotFoundException)
|
||||||
|
{
|
||||||
|
//Ignore if the file was not found (somehow already deleted)
|
||||||
|
await aobaService.RemoveThumbnailAsync(mediaId, size);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ExceptionError(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,11 +59,12 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Maybe<Stream>> GetOrCreateThumbnailAsync(ObjectId mediaId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public async Task<Maybe<Stream>> GetOrCreateThumbnailAsync(ObjectId mediaId, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|
||||||
var existingThumb = await GetThumbnailAsync(mediaId, size, cancellationToken);
|
var existingThumb = await GetThumbnailAsync(mediaId, size, cancellationToken);
|
||||||
if (existingThumb != null)
|
if (existingThumb != null)
|
||||||
return existingThumb;
|
return existingThumb;
|
||||||
|
|
||||||
var media = await aobaService.GetMediaFromFileAsync(mediaId, cancellationToken);
|
var media = await aobaService.GetMediaAsync(mediaId, cancellationToken);
|
||||||
|
|
||||||
if (media == null)
|
if (media == null)
|
||||||
return new Error("Media does not exist");
|
return new Error("Media does not exist");
|
||||||
@@ -91,17 +117,29 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
MediaType.Image => await GenerateImageThumbnailAsync(stream, size, cancellationToken),
|
MediaType.Image => await GenerateImageThumbnailAsync(stream, size, ext, cancellationToken),
|
||||||
MediaType.Video => GenerateVideoThumbnail(stream, size, cancellationToken),
|
MediaType.Video => GenerateVideoThumbnail(stream, size, cancellationToken),
|
||||||
MediaType.Text or MediaType.Code => await GenerateDocumentThumbnailAsync(stream, size, cancellationToken),
|
MediaType.Text or MediaType.Code => await GenerateDocumentThumbnailAsync(stream, size, cancellationToken),
|
||||||
_ => new Error($"No Thumbnail for {type}"),
|
_ => new Error($"No Thumbnail for {type}"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Stream> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, CancellationToken cancellationToken = default)
|
private static Maybe<Image> LoadImage(Stream stream, string ext)
|
||||||
{
|
{
|
||||||
var img = Image.Load(stream);
|
if (ext is ".heif" or ".avif")
|
||||||
img.Mutate(o =>
|
{
|
||||||
|
return new Error("Unsupported image type");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Image.Load(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Maybe<Stream>> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, string ext, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var img = LoadImage(stream, ext);
|
||||||
|
if (img.HasError)
|
||||||
|
return img.Error;
|
||||||
|
img.Value.Mutate(o =>
|
||||||
{
|
{
|
||||||
var size =
|
var size =
|
||||||
o.Resize(new ResizeOptions
|
o.Resize(new ResizeOptions
|
||||||
@@ -112,12 +150,13 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
var result = new MemoryStream();
|
var result = new MemoryStream();
|
||||||
await img.SaveAsWebpAsync(result, cancellationToken);
|
await img.Value.SaveAsWebpAsync(result, cancellationToken);
|
||||||
|
img.Value.Dispose();
|
||||||
result.Position = 0;
|
result.Position = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Maybe<Stream> GenerateVideoThumbnail(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public static Maybe<Stream> GenerateVideoThumbnail(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var w = (int)size;
|
var w = (int)size;
|
||||||
var fn = ObjectId.GenerateNewId().ToString();
|
var fn = ObjectId.GenerateNewId().ToString();
|
||||||
@@ -141,7 +180,7 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
output.Position = 0;
|
output.Position = 0;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
@@ -151,6 +190,47 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Maybe<Stream> GenerateAvifThumbnail(Stream data, ThumbnailSize size, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var w = (int)size;
|
||||||
|
var fn = ObjectId.GenerateNewId().ToString();
|
||||||
|
var inFilePath = $"/tmp/{fn}.avif";
|
||||||
|
var outFilePath = $"/tmp/{fn}.webp";
|
||||||
|
using var source = new FileStream(inFilePath, FileMode.CreateNew);
|
||||||
|
data.CopyTo(source);
|
||||||
|
source.Flush();
|
||||||
|
source.Dispose();
|
||||||
|
data.Dispose();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var process = Process.Start(new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "vips",
|
||||||
|
Arguments = $"smartcrop \"{inFilePath}\" \"{outFilePath}\"[Q=75] {w} {w}",
|
||||||
|
WorkingDirectory = "/tmp"
|
||||||
|
});
|
||||||
|
if (process == null)
|
||||||
|
return new Error("Failed to run vips command");
|
||||||
|
process.WaitForExit();
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
return new Error("Failed to convert");
|
||||||
|
var output = new MemoryStream();
|
||||||
|
using var oFile = File.OpenRead(outFilePath);
|
||||||
|
oFile.CopyTo(output);
|
||||||
|
output.Position = 0;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
File.Delete(inFilePath);
|
||||||
|
File.Delete(outFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Maybe<Stream>> GenerateDocumentThumbnailAsync(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default)
|
public async Task<Maybe<Stream>> GenerateDocumentThumbnailAsync(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return new NotImplementedException();
|
return new NotImplementedException();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UserSecretsId>9ffcc706-7f1b-48e3-bf30-eab69a90fded</UserSecretsId>
|
<UserSecretsId>9ffcc706-7f1b-48e3-bf30-eab69a90fded</UserSecretsId>
|
||||||
@@ -9,22 +9,23 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
|
<PackageReference Include="Fido2" Version="4.0.0" />
|
||||||
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.71.0" />
|
<PackageReference Include="Grpc.AspNetCore" Version="2.76.0" />
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.72.0">
|
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.76.0" />
|
||||||
|
<PackageReference Include="Grpc.Tools" Version="2.78.0">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.6" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.3" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.12.1" />
|
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.16.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||||
<PackageReference Include="MimeTypesMap" Version="1.0.9" />
|
<PackageReference Include="MimeTypesMap" Version="1.0.9" />
|
||||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
|
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
|
||||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
|
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Protobuf Include="Proto\Aoba.proto"></Protobuf>
|
<Protobuf Include="Proto\Aoba.proto"></Protobuf>
|
||||||
|
<Protobuf Include="Proto\Account.proto" />
|
||||||
<Protobuf Include="Proto\Auth.proto"></Protobuf>
|
<Protobuf Include="Proto\Auth.proto"></Protobuf>
|
||||||
<Protobuf Include="Proto\Metrics.proto"></Protobuf>
|
<Protobuf Include="Proto\Metrics.proto"></Protobuf>
|
||||||
<Protobuf Include="Proto\Types.proto"></Protobuf>
|
<Protobuf Include="Proto\Types.proto"></Protobuf>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class MediaApi(AobaService aoba) : ControllerBase
|
|||||||
if (media.HasError)
|
if (media.HasError)
|
||||||
return Problem(detail: media.Error.Message, statusCode: StatusCodes.Status400BadRequest);
|
return Problem(detail: media.Error.Message, statusCode: StatusCodes.Status400BadRequest);
|
||||||
|
|
||||||
|
|
||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
media = media.Value,
|
media = media.Value,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace AobaServer.Controllers;
|
|||||||
public class MediaController(AobaService aobaService, ILogger<MediaController> logger) : Controller
|
public class MediaController(AobaService aobaService, ILogger<MediaController> logger) : Controller
|
||||||
{
|
{
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
|
[HttpGet("{id}/{*fn}")]
|
||||||
[ResponseCache(Duration = int.MaxValue)]
|
[ResponseCache(Duration = int.MaxValue)]
|
||||||
public async Task<IActionResult> MediaAsync(ObjectId id, [FromServices] MongoClient client, CancellationToken cancellationToken)
|
public async Task<IActionResult> MediaAsync(ObjectId id, [FromServices] MongoClient client, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,22 @@ public class MediaController(AobaService aobaService, ILogger<MediaController> l
|
|||||||
return File(file, mime, true);
|
return File(file, mime, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}/dl")]
|
||||||
|
[HttpGet("{id}/dl/{*fn}")]
|
||||||
|
[ResponseCache(Duration = int.MaxValue)]
|
||||||
|
public async Task<IActionResult> DownloadMediaAsync(ObjectId id, [FromServices] MongoClient client, [FromQuery] string? fn = null, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var file = await aobaService.GetFileStreamAsync(id, seekable: true, cancellationToken: cancellationToken);
|
||||||
|
if (file.HasError)
|
||||||
|
{
|
||||||
|
logger.LogError(file.Error.Exception, "Failed to load media stream");
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
var mime = MimeTypesMap.GetMimeType(file.Value.FileInfo.Filename);
|
||||||
|
_ = aobaService.IncrementViewCountAsync(id, cancellationToken);
|
||||||
|
return File(file, mime, fn ?? file.Value.FileInfo.Filename, true);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Redirect legacy media urls to the new url
|
/// Redirect legacy media urls to the new url
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,6 +75,7 @@ public class MediaController(AobaService aobaService, ILogger<MediaController> l
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("/t/{id}")]
|
[HttpGet("/t/{id}")]
|
||||||
|
[ResponseCache(Duration = int.MaxValue)]
|
||||||
public async Task<IActionResult> ThumbAsync(ObjectId id, [FromServices] ThumbnailService thumbnailService, CancellationToken cancellationToken = default)
|
public async Task<IActionResult> ThumbAsync(ObjectId id, [FromServices] ThumbnailService thumbnailService, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var thumb = await thumbnailService.GetThumbnailByFileIdAsync(id, cancellationToken);
|
var thumb = await thumbnailService.GetThumbnailByFileIdAsync(id, cancellationToken);
|
||||||
|
|||||||
+11
-7
@@ -1,5 +1,8 @@
|
|||||||
|
ARG NET_VERSION="10.0"
|
||||||
|
ARG DX_VERSION="0.7.3"
|
||||||
|
|
||||||
# Client Side build - prep deps
|
# Client Side build - prep deps
|
||||||
FROM rust:1 AS chef
|
FROM rust:1-trixie AS chef
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
RUN cargo install cargo-chef
|
RUN cargo install cargo-chef
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -22,28 +25,29 @@ RUN apt install -y protobuf-compiler libprotobuf-dev ffmpeg
|
|||||||
|
|
||||||
# Install `dx`
|
# Install `dx`
|
||||||
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
|
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
|
||||||
RUN cargo binstall dioxus-cli --root /.cargo -y --force
|
ARG DX_VERSION
|
||||||
|
RUN cargo binstall dioxus-cli@${DX_VERSION} --root /.cargo -y --force
|
||||||
ENV PATH="/.cargo/bin:$PATH"
|
ENV PATH="/.cargo/bin:$PATH"
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ENV APP_VERSION=$VERSION
|
ENV APP_VERSION=$VERSION
|
||||||
# Create the final bundle folder. Bundle always executes in release mode with optimizations enabled
|
# Create the final bundle folder. Bundle always executes in release mode with optimizations enabled
|
||||||
RUN dx bundle --platform web
|
RUN dx bundle --release --platform web
|
||||||
|
|
||||||
# Server Build
|
# Server Build
|
||||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:${NET_VERSION} AS base
|
||||||
RUN apt-get update && apt-get install -y ffmpeg
|
RUN apt-get update && apt-get install -y ffmpeg #libvips libvips-tools
|
||||||
USER $APP_UID
|
USER $APP_UID
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
EXPOSE 8081
|
EXPOSE 8081
|
||||||
|
|
||||||
# This stage is used to build the service project
|
# This stage is used to build the service project
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build
|
FROM mcr.microsoft.com/dotnet/sdk:${NET_VERSION}-noble AS build
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["AobaServer/AobaServer.csproj", "AobaServer/"]
|
COPY ["AobaServer/AobaServer.csproj", "AobaServer/"]
|
||||||
RUN dotnet restore "./AobaServer/AobaServer.csproj"
|
RUN dotnet restore "/src/AobaServer/AobaServer.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
# Copy Built bundle from client builder
|
# Copy Built bundle from client builder
|
||||||
COPY --from=client-builder /app/AobaClient/target/dx/aoba-client/release/web/public /src/AobaServer/wwwroot
|
COPY --from=client-builder /app/AobaClient/target/dx/aoba-client/release/web/public /src/AobaServer/wwwroot
|
||||||
|
|||||||
@@ -121,10 +121,13 @@ builder.Services.AddAuthentication(options =>
|
|||||||
|
|
||||||
|
|
||||||
builder.Services.AddAoba();
|
builder.Services.AddAoba();
|
||||||
|
#if DEBUG
|
||||||
|
builder.Services.AddHostedService<DebugService>();
|
||||||
|
#endif
|
||||||
builder.Services.Configure<FormOptions>(opt =>
|
builder.Services.Configure<FormOptions>(opt =>
|
||||||
{
|
{
|
||||||
opt.ValueLengthLimit = int.MaxValue;
|
opt.ValueLengthLimit = int.MaxValue;
|
||||||
opt.MultipartBodyLengthLimit = int.MaxValue;
|
opt.MultipartBodyLengthLimit = long.MaxValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option csharp_namespace = "Aoba.RPC.Account";
|
||||||
|
package aoba;
|
||||||
|
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
import "Proto/Types.proto";
|
||||||
|
|
||||||
|
service AccountRpc {
|
||||||
|
rpc RegisterPasskey(google.protobuf.Empty) returns (PasskeyRegistrationCreds);
|
||||||
|
rpc CompletePasskeyRegistration(PasskeyPublicKey) returns (google.protobuf.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -12,5 +12,6 @@ service AobaRpc {
|
|||||||
rpc ListMedia(PageFilter) returns (ListResponse);
|
rpc ListMedia(PageFilter) returns (ListResponse);
|
||||||
rpc GetUser(Id) returns (UserResponse);
|
rpc GetUser(Id) returns (UserResponse);
|
||||||
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
|
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
|
||||||
|
rpc SetMediaClass(SetMediaClassRequest) returns(google.protobuf.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import "Proto/Types.proto";
|
|||||||
|
|
||||||
service AuthRpc {
|
service AuthRpc {
|
||||||
rpc Login(Credentials) returns (LoginResponse);
|
rpc Login(Credentials) returns (LoginResponse);
|
||||||
rpc LoginPasskey(PassKeyPayload) returns (LoginResponse);
|
rpc LoginPasskey(PasskeyPayload) returns (LoginResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ message Credentials{
|
|||||||
string password = 2;
|
string password = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PassKeyPayload {
|
message SetMediaClassRequest{
|
||||||
|
Id id = 1;
|
||||||
|
MediaClass class = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,10 +41,7 @@ message Id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message MediaResponse {
|
message MediaResponse {
|
||||||
oneof result {
|
optional MediaModel value = 1;
|
||||||
MediaModel value = 1;
|
|
||||||
google.protobuf.Empty empty = 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListResponse {
|
message ListResponse {
|
||||||
@@ -54,8 +52,8 @@ message ListResponse {
|
|||||||
message Pagination {
|
message Pagination {
|
||||||
int32 page = 1;
|
int32 page = 1;
|
||||||
int32 pageSize = 2;
|
int32 pageSize = 2;
|
||||||
int64 totalPages = 3;
|
int32 totalPages = 3;
|
||||||
int64 totalItems = 4;
|
int32 totalItems = 4;
|
||||||
optional string query = 5;
|
optional string query = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +80,8 @@ message MediaModel {
|
|||||||
int32 viewCount = 5;
|
int32 viewCount = 5;
|
||||||
Id owner = 6;
|
Id owner = 6;
|
||||||
string thumbUrl = 7;
|
string thumbUrl = 7;
|
||||||
|
string mediaUrl = 8;
|
||||||
|
MediaClass class = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MediaType {
|
enum MediaType {
|
||||||
@@ -93,9 +93,37 @@ enum MediaType {
|
|||||||
Raw = 5;
|
Raw = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum MediaClass {
|
||||||
|
Standard = 0;
|
||||||
|
NSFW = 1;
|
||||||
|
Secret = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message ShareXResponse {
|
message ShareXResponse {
|
||||||
oneof dstResult {
|
oneof dstResult {
|
||||||
string destination = 1;
|
string destination = 1;
|
||||||
string error = 2;
|
string error = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message SearchQuery {
|
||||||
|
optional string queryText = 1;
|
||||||
|
repeated Filter filters = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Filter {
|
||||||
|
string key = 1;
|
||||||
|
repeated string values = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message PasskeyPayload {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message PasskeyRegistrationCreds{
|
||||||
|
|
||||||
|
}
|
||||||
|
message PasskeyPublicKey{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Aoba.RPC;
|
||||||
|
using Aoba.RPC.Account;
|
||||||
|
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
|
||||||
|
using Grpc.Core;
|
||||||
|
|
||||||
|
namespace AobaServer.Services;
|
||||||
|
|
||||||
|
public class AccountRpcService : AccountRpc.AccountRpcBase
|
||||||
|
{
|
||||||
|
public override Task<PasskeyRegistrationCreds> RegisterPasskey(Empty request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.RegisterPasskey(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<Empty> CompletePasskeyRegistration(PasskeyPublicKey request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return base.CompletePasskeyRegistration(request, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,10 +9,7 @@ using Google.Protobuf.WellKnownTypes;
|
|||||||
|
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
|
|
||||||
using MongoDB.Bson.IO;
|
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AobaServer.Services;
|
namespace AobaServer.Services;
|
||||||
|
|
||||||
@@ -20,7 +17,7 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
{
|
{
|
||||||
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
var media = await aobaService.GetMediaFromLegacyIdAsync(request.ToObjectId());
|
var media = await aobaService.GetMediaAsync(request.ToObjectId(), context.CancellationToken);
|
||||||
return media.ToResponse();
|
return media.ToResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +28,12 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
return result.ToResponse();
|
return result.ToResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<Empty> SetMediaClass(SetMediaClassRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
await aobaService.SetMediaClassAsync(request.Id.ToObjectId(), (AobaCore.Models.MediaClass)request.Class, context.CancellationToken);
|
||||||
|
return new Empty();
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
|
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
var userId = context.GetHttpContext().User.GetId();
|
var userId = context.GetHttpContext().User.GetId();
|
||||||
@@ -50,10 +53,7 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
};
|
};
|
||||||
return new ShareXResponse
|
return new ShareXResponse
|
||||||
{
|
{
|
||||||
Destination = JsonSerializer.Serialize(dest, new JsonSerializerOptions
|
Destination = JsonSerializer.Serialize(dest)
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
using AobaCore.Services;
|
||||||
|
|
||||||
|
namespace AobaServer.Services;
|
||||||
|
|
||||||
|
public class DebugService(AobaService aobaService, ThumbnailService thumbnailService) : BackgroundService
|
||||||
|
{
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
var mediaItems = await aobaService.FindMediaWithExtAsync(".avif", stoppingToken);
|
||||||
|
foreach (var item in mediaItems)
|
||||||
|
{
|
||||||
|
foreach (var size in item.Thumbnails.Keys)
|
||||||
|
{
|
||||||
|
await thumbnailService.DeleteThumbnailAsync(item.MediaId, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ public static class ProtoExtensions
|
|||||||
public static MediaResponse ToResponse(this Media? media)
|
public static MediaResponse ToResponse(this Media? media)
|
||||||
{
|
{
|
||||||
if(media == null)
|
if(media == null)
|
||||||
return new MediaResponse() { Empty = new Empty() };
|
return new MediaResponse() {};
|
||||||
return new MediaResponse()
|
return new MediaResponse()
|
||||||
{
|
{
|
||||||
Value = media.ToMediaModel()
|
Value = media.ToMediaModel()
|
||||||
@@ -56,6 +56,8 @@ public static class ProtoExtensions
|
|||||||
Owner = media.Owner.ToId(),
|
Owner = media.Owner.ToId(),
|
||||||
ViewCount = media.ViewCount,
|
ViewCount = media.ViewCount,
|
||||||
ThumbUrl = thumbUrl,
|
ThumbUrl = thumbUrl,
|
||||||
|
MediaUrl = media.GetMediaUrl(),
|
||||||
|
Class = (Aoba.RPC.MediaClass)media.Class,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user