Spaces:
Runtime error
Runtime error
add: migrate to models module
Browse files- src/models/dtos/keyframes/mod.rs +38 -0
- src/models/dtos/mod.rs +3 -0
- src/models/dtos/videos/mod.rs +17 -0
- src/models/entities/keyframes/mod.rs +22 -0
- src/models/entities/mod.rs +2 -0
- src/models/entities/videos/mod.rs +22 -0
- src/models/mod.rs +3 -0
- src/models/states/mod.rs +48 -0
src/models/dtos/keyframes/mod.rs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use crate::entities::{keyframes::KeyframeEntity, videos::VideoEntity};
|
| 2 |
+
|
| 3 |
+
#[derive(Debug, Clone, serde::Serialize, utoipa::ToSchema)]
|
| 4 |
+
pub struct KeyframeDto {
|
| 5 |
+
id: i64,
|
| 6 |
+
path: String,
|
| 7 |
+
timestamp: f64,
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
impl From<(KeyframeEntity, VideoEntity)> for KeyframeDto {
|
| 11 |
+
fn from((keyframe, video): (KeyframeEntity, VideoEntity)) -> Self {
|
| 12 |
+
let id = keyframe.id();
|
| 13 |
+
let timestamp = keyframe.video_related_frame_timestamp();
|
| 14 |
+
let path = format!(
|
| 15 |
+
"/static/keyframes/L{}_V{:0>3}/{:0>3}.jpg",
|
| 16 |
+
video.l(),
|
| 17 |
+
video.v(),
|
| 18 |
+
keyframe.video_related_frame_id()
|
| 19 |
+
);
|
| 20 |
+
Self {
|
| 21 |
+
id,
|
| 22 |
+
path,
|
| 23 |
+
timestamp,
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
impl From<(VideoEntity, KeyframeEntity)> for KeyframeDto {
|
| 29 |
+
fn from((video, keyframe): (VideoEntity, KeyframeEntity)) -> Self {
|
| 30 |
+
Self::from((keyframe, video))
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#[derive(Debug, Clone, Copy, serde::Deserialize)]
|
| 35 |
+
pub struct VectoredKeyframeDto {
|
| 36 |
+
id: i64,
|
| 37 |
+
score: f64,
|
| 38 |
+
}
|
src/models/dtos/mod.rs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pub mod keyframes;
|
| 2 |
+
pub mod vectors;
|
| 3 |
+
pub mod videos;
|
src/models/dtos/videos/mod.rs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use crate::entities::videos::VideoEntity;
|
| 2 |
+
|
| 3 |
+
#[derive(Debug, Clone, serde::Serialize, utoipa::ToSchema)]
|
| 4 |
+
pub struct VideoDto {
|
| 5 |
+
id: i64,
|
| 6 |
+
path: String,
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
impl From<VideoEntity> for VideoDto {
|
| 10 |
+
fn from(value: VideoEntity) -> Self {
|
| 11 |
+
let path = format!("/static/videos/L{}_V{:0>3}.mp4", value.l(), value.v());
|
| 12 |
+
Self {
|
| 13 |
+
id: value.id(),
|
| 14 |
+
path,
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
src/models/entities/keyframes/mod.rs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#[derive(Debug, Clone, diesel::Queryable, diesel::Selectable)]
|
| 2 |
+
#[diesel(table_name = crate::schema::keyframes)]
|
| 3 |
+
#[diesel(check_for_backend(diesel::pg::Pg))]
|
| 4 |
+
pub struct KeyframeEntity {
|
| 5 |
+
id: i64,
|
| 6 |
+
video_related_frame_id: i16,
|
| 7 |
+
video_related_frame_timestamp: f64,
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
impl KeyframeEntity {
|
| 11 |
+
pub fn id(&self) -> i64 {
|
| 12 |
+
self.id
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
pub fn video_related_frame_id(&self) -> i16 {
|
| 16 |
+
self.video_related_frame_id
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
pub fn video_related_frame_timestamp(&self) -> f64 {
|
| 20 |
+
self.video_related_frame_timestamp
|
| 21 |
+
}
|
| 22 |
+
}
|
src/models/entities/mod.rs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pub mod keyframes;
|
| 2 |
+
pub mod videos;
|
src/models/entities/videos/mod.rs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#[derive(Debug, Clone, diesel::Queryable, diesel::Selectable)]
|
| 2 |
+
#[diesel(table_name = crate::schema::videos)]
|
| 3 |
+
#[diesel(check_for_backend(diesel::pg::Pg))]
|
| 4 |
+
pub struct VideoEntity {
|
| 5 |
+
id: i64,
|
| 6 |
+
l: i16,
|
| 7 |
+
v: i16,
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
impl VideoEntity {
|
| 11 |
+
pub fn id(&self) -> i64 {
|
| 12 |
+
self.id
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
pub fn l(&self) -> i16 {
|
| 16 |
+
self.l
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
pub fn v(&self) -> i16 {
|
| 20 |
+
self.v
|
| 21 |
+
}
|
| 22 |
+
}
|
src/models/mod.rs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pub mod dtos;
|
| 2 |
+
pub mod entities;
|
| 3 |
+
pub mod states;
|
src/models/states/mod.rs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use std::sync::Arc;
|
| 2 |
+
|
| 3 |
+
use deadpool_diesel::{
|
| 4 |
+
Runtime,
|
| 5 |
+
postgres::{Manager, Pool},
|
| 6 |
+
};
|
| 7 |
+
use qdrant_client::Qdrant;
|
| 8 |
+
|
| 9 |
+
#[derive(Clone)]
|
| 10 |
+
pub struct AppState {
|
| 11 |
+
diesel_pool: Pool,
|
| 12 |
+
qdrant_client: Arc<Qdrant>,
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
impl AppState {
|
| 16 |
+
pub fn new() -> anyhow::Result<Self> {
|
| 17 |
+
Ok(Self {
|
| 18 |
+
diesel_pool: Self::diesel_pool_helper()?,
|
| 19 |
+
qdrant_client: Self::qdrant_client_helper()?,
|
| 20 |
+
})
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
fn diesel_pool_helper() -> anyhow::Result<Pool> {
|
| 24 |
+
Pool::builder(Manager::new(
|
| 25 |
+
std::env::var("DATABASE_URL")?,
|
| 26 |
+
Runtime::Tokio1,
|
| 27 |
+
))
|
| 28 |
+
.build()
|
| 29 |
+
.map_err(Into::into)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
fn qdrant_client_helper() -> anyhow::Result<Arc<Qdrant>> {
|
| 33 |
+
Qdrant::from_url(&std::env::var("QDRANT_URL")?)
|
| 34 |
+
.build()
|
| 35 |
+
.map(Arc::new)
|
| 36 |
+
.map_err(Into::into)
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
impl AppState {
|
| 41 |
+
pub fn pool(&self) -> &Pool {
|
| 42 |
+
&self.diesel_pool
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
pub fn qdrant_client(&self) -> &Qdrant {
|
| 46 |
+
&self.qdrant_client
|
| 47 |
+
}
|
| 48 |
+
}
|