forked from alemi/upub
chore: helper to reconstruct ids
This commit is contained in:
parent
f0cdd4bd7a
commit
3df01b5b0a
4 changed files with 18 additions and 24 deletions
|
@ -10,11 +10,7 @@ pub async fn view(
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(query): Query<TryFetch>,
|
Query(query): Query<TryFetch>,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let aid = if id.starts_with('+') {
|
let aid = ctx.uri("activities", id);
|
||||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
|
||||||
} else {
|
|
||||||
ctx.aid(id.clone())
|
|
||||||
};
|
|
||||||
if auth.is_local() && query.fetch && !ctx.is_local(&aid) {
|
if auth.is_local() && query.fetch && !ctx.is_local(&aid) {
|
||||||
ctx.fetch_activity(&aid).await?;
|
ctx.fetch_activity(&aid).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,8 @@ pub async fn get(
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let context = if id.starts_with('+') {
|
let local_context_id = url!(ctx, "/context/{id}");
|
||||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
let context = ctx.uri("context", id);
|
||||||
} else {
|
|
||||||
url!(ctx, "/context/{id}")
|
|
||||||
};
|
|
||||||
|
|
||||||
let count = model::addressing::Entity::find_addressed()
|
let count = model::addressing::Entity::find_addressed()
|
||||||
.filter(auth.filter_condition())
|
.filter(auth.filter_condition())
|
||||||
|
@ -20,7 +17,7 @@ pub async fn get(
|
||||||
.count(ctx.db())
|
.count(ctx.db())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
crate::server::builders::collection(&url!(ctx, "/context/{id}"), Some(count))
|
crate::server::builders::collection(&local_context_id, Some(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn page(
|
pub async fn page(
|
||||||
|
|
|
@ -8,11 +8,8 @@ pub async fn get(
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let oid = if id.starts_with('+') {
|
let replies_id = url!(ctx, "/objects/{id}/replies");
|
||||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
let oid = ctx.uri("objects", id);
|
||||||
} else {
|
|
||||||
ctx.oid(id.clone())
|
|
||||||
};
|
|
||||||
|
|
||||||
let count = model::addressing::Entity::find_addressed()
|
let count = model::addressing::Entity::find_addressed()
|
||||||
.filter(auth.filter_condition())
|
.filter(auth.filter_condition())
|
||||||
|
@ -20,7 +17,7 @@ pub async fn get(
|
||||||
.count(ctx.db())
|
.count(ctx.db())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
crate::server::builders::collection(&url!(ctx, "/objects/{id}/replies"), Some(count))
|
crate::server::builders::collection(&replies_id, Some(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn page(
|
pub async fn page(
|
||||||
|
@ -29,14 +26,11 @@ pub async fn page(
|
||||||
Query(page): Query<Pagination>,
|
Query(page): Query<Pagination>,
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let oid = if id.starts_with('+') {
|
let page_id = url!(ctx, "/objects/{id}/replies/page");
|
||||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
let oid = ctx.uri("objects", id);
|
||||||
} else {
|
|
||||||
ctx.oid(id.clone())
|
|
||||||
};
|
|
||||||
|
|
||||||
crate::server::builders::paginate(
|
crate::server::builders::paginate(
|
||||||
url!(ctx, "/objects/{id}/replies/page"),
|
page_id,
|
||||||
Condition::all()
|
Condition::all()
|
||||||
.add(auth.filter_condition())
|
.add(auth.filter_condition())
|
||||||
.add(model::object::Column::InReplyTo.eq(oid)),
|
.add(model::object::Column::InReplyTo.eq(oid)),
|
||||||
|
|
|
@ -97,7 +97,14 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uri(&self, entity: &str, id: String) -> String {
|
pub fn uri(&self, entity: &str, id: String) -> String {
|
||||||
if id.starts_with("http") { id } else {
|
if id.starts_with("http") { // ready-to-use id
|
||||||
|
id
|
||||||
|
} else if id.starts_with('+') { // compacted id
|
||||||
|
id
|
||||||
|
.replacen('+', "https://", 1)
|
||||||
|
.replace('@', "/")
|
||||||
|
.replace("//", "/@") // oops my method sucks!! TODO
|
||||||
|
} else { // bare local id
|
||||||
format!("{}{}/{}/{}", self.0.protocol, self.0.domain, entity, id)
|
format!("{}{}/{}/{}", self.0.protocol, self.0.domain, entity, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue