fix: add also server column for server addressing
This commit is contained in:
parent
acd4fa0bd4
commit
6be486ca3d
5 changed files with 30 additions and 5 deletions
|
@ -83,9 +83,8 @@ pub async fn auth(State(ctx): State<Context>, Json(login): Json<LoginForm>) -> R
|
||||||
.collect();
|
.collect();
|
||||||
model::session::Entity::insert(
|
model::session::Entity::insert(
|
||||||
model::session::ActiveModel {
|
model::session::ActiveModel {
|
||||||
id: sea_orm::ActiveValue::NotSet,
|
id: sea_orm::ActiveValue::Set(token.clone()),
|
||||||
actor: sea_orm::ActiveValue::Set(x.id),
|
actor: sea_orm::ActiveValue::Set(x.id),
|
||||||
session: sea_orm::ActiveValue::Set(token.clone()),
|
|
||||||
expires: sea_orm::ActiveValue::Set(chrono::Utc::now() + std::time::Duration::from_secs(3600 * 6)),
|
expires: sea_orm::ActiveValue::Set(chrono::Utc::now() + std::time::Duration::from_secs(3600 * 6)),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -102,6 +102,7 @@ pub async fn post(
|
||||||
.map(|actor|
|
.map(|actor|
|
||||||
addressing::ActiveModel{
|
addressing::ActiveModel{
|
||||||
id: sea_orm::ActiveValue::NotSet,
|
id: sea_orm::ActiveValue::NotSet,
|
||||||
|
server: sea_orm::Set(Context::server(&actor)),
|
||||||
actor: sea_orm::Set(actor),
|
actor: sea_orm::Set(actor),
|
||||||
activity: sea_orm::Set(activity_id.clone()),
|
activity: sea_orm::Set(activity_id.clone()),
|
||||||
object: sea_orm::Set(Some(object_id.clone())),
|
object: sea_orm::Set(Some(object_id.clone())),
|
||||||
|
|
|
@ -18,6 +18,7 @@ impl MigrationTrait for Migration {
|
||||||
.primary_key()
|
.primary_key()
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Addressing::Actor).string().not_null())
|
.col(ColumnDef::new(Addressing::Actor).string().not_null())
|
||||||
|
.col(ColumnDef::new(Addressing::Server).string().not_null())
|
||||||
.col(ColumnDef::new(Addressing::Activity).string().not_null())
|
.col(ColumnDef::new(Addressing::Activity).string().not_null())
|
||||||
.col(ColumnDef::new(Addressing::Object).string().null())
|
.col(ColumnDef::new(Addressing::Object).string().null())
|
||||||
.col(ColumnDef::new(Addressing::Published).date_time().not_null())
|
.col(ColumnDef::new(Addressing::Published).date_time().not_null())
|
||||||
|
@ -39,6 +40,16 @@ impl MigrationTrait for Migration {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
manager
|
||||||
|
.create_index(
|
||||||
|
Index::create()
|
||||||
|
.name("addressing-server-index")
|
||||||
|
.table(Addressing::Table)
|
||||||
|
.col(Addressing::Server)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
manager
|
manager
|
||||||
.create_index(
|
.create_index(
|
||||||
Index::create()
|
Index::create()
|
||||||
|
@ -71,6 +82,10 @@ impl MigrationTrait for Migration {
|
||||||
.drop_index(Index::drop().name("addressing-actor-index").to_owned())
|
.drop_index(Index::drop().name("addressing-actor-index").to_owned())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
manager
|
||||||
|
.drop_index(Index::drop().name("addressing-server-index").to_owned())
|
||||||
|
.await?;
|
||||||
|
|
||||||
manager
|
manager
|
||||||
.drop_index(Index::drop().name("addressing-activity-index").to_owned())
|
.drop_index(Index::drop().name("addressing-activity-index").to_owned())
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -88,6 +103,7 @@ enum Addressing {
|
||||||
Table,
|
Table,
|
||||||
Id,
|
Id,
|
||||||
Actor,
|
Actor,
|
||||||
|
Server,
|
||||||
Activity,
|
Activity,
|
||||||
Object,
|
Object,
|
||||||
Published,
|
Published,
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub actor: String,
|
pub actor: String,
|
||||||
|
pub server: String,
|
||||||
pub activity: String,
|
pub activity: String,
|
||||||
pub object: Option<String>,
|
pub object: Option<String>,
|
||||||
pub published: ChronoDateTimeUtc,
|
pub published: ChronoDateTimeUtc,
|
||||||
|
|
|
@ -41,8 +41,6 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO maybe redo these with enums? idk
|
|
||||||
|
|
||||||
/// get full user id uri
|
/// get full user id uri
|
||||||
pub fn uid(&self, id: String) -> String {
|
pub fn uid(&self, id: String) -> String {
|
||||||
self.uri("users", id)
|
self.uri("users", id)
|
||||||
|
@ -58,7 +56,7 @@ impl Context {
|
||||||
self.uri("activities", id)
|
self.uri("activities", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get bare uri, usually an uuid but unspecified
|
/// get bare id, usually an uuid but unspecified
|
||||||
pub fn id(&self, id: String) -> String {
|
pub fn id(&self, id: String) -> String {
|
||||||
if id.starts_with(&self.0.domain) {
|
if id.starts_with(&self.0.domain) {
|
||||||
id.split('/').last().unwrap_or("").to_string()
|
id.split('/').last().unwrap_or("").to_string()
|
||||||
|
@ -66,4 +64,14 @@ impl Context {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn server(id: &str) -> String {
|
||||||
|
id
|
||||||
|
.replace("https://", "")
|
||||||
|
.replace("http://", "")
|
||||||
|
.split('/')
|
||||||
|
.next()
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue