forked from alemi/upub
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();
|
||||
model::session::Entity::insert(
|
||||
model::session::ActiveModel {
|
||||
id: sea_orm::ActiveValue::NotSet,
|
||||
id: sea_orm::ActiveValue::Set(token.clone()),
|
||||
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)),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -102,6 +102,7 @@ pub async fn post(
|
|||
.map(|actor|
|
||||
addressing::ActiveModel{
|
||||
id: sea_orm::ActiveValue::NotSet,
|
||||
server: sea_orm::Set(Context::server(&actor)),
|
||||
actor: sea_orm::Set(actor),
|
||||
activity: sea_orm::Set(activity_id.clone()),
|
||||
object: sea_orm::Set(Some(object_id.clone())),
|
||||
|
|
|
@ -18,6 +18,7 @@ impl MigrationTrait for Migration {
|
|||
.primary_key()
|
||||
)
|
||||
.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::Object).string().null())
|
||||
.col(ColumnDef::new(Addressing::Published).date_time().not_null())
|
||||
|
@ -39,6 +40,16 @@ impl MigrationTrait for Migration {
|
|||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-server-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Server)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
|
@ -71,6 +82,10 @@ impl MigrationTrait for Migration {
|
|||
.drop_index(Index::drop().name("addressing-actor-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-server-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-activity-index").to_owned())
|
||||
.await?;
|
||||
|
@ -88,6 +103,7 @@ enum Addressing {
|
|||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Server,
|
||||
Activity,
|
||||
Object,
|
||||
Published,
|
||||
|
|
|
@ -6,6 +6,7 @@ pub struct Model {
|
|||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
pub actor: String,
|
||||
pub server: String,
|
||||
pub activity: String,
|
||||
pub object: Option<String>,
|
||||
pub published: ChronoDateTimeUtc,
|
||||
|
|
|
@ -41,8 +41,6 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO maybe redo these with enums? idk
|
||||
|
||||
/// get full user id uri
|
||||
pub fn uid(&self, id: String) -> String {
|
||||
self.uri("users", id)
|
||||
|
@ -58,7 +56,7 @@ impl Context {
|
|||
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 {
|
||||
if id.starts_with(&self.0.domain) {
|
||||
id.split('/').last().unwrap_or("").to_string()
|
||||
|
@ -66,4 +64,14 @@ impl Context {
|
|||
id
|
||||
}
|
||||
}
|
||||
|
||||
pub fn server(id: &str) -> String {
|
||||
id
|
||||
.replace("https://", "")
|
||||
.replace("http://", "")
|
||||
.split('/')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue