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,
|
||||
Query(query): Query<TryFetch>,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
let aid = if id.starts_with('+') {
|
||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
||||
} else {
|
||||
ctx.aid(id.clone())
|
||||
};
|
||||
let aid = ctx.uri("activities", id);
|
||||
if auth.is_local() && query.fetch && !ctx.is_local(&aid) {
|
||||
ctx.fetch_activity(&aid).await?;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,8 @@ pub async fn get(
|
|||
Path(id): Path<String>,
|
||||
AuthIdentity(auth): AuthIdentity,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
let context = if id.starts_with('+') {
|
||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
||||
} else {
|
||||
url!(ctx, "/context/{id}")
|
||||
};
|
||||
let local_context_id = url!(ctx, "/context/{id}");
|
||||
let context = ctx.uri("context", id);
|
||||
|
||||
let count = model::addressing::Entity::find_addressed()
|
||||
.filter(auth.filter_condition())
|
||||
|
@ -20,7 +17,7 @@ pub async fn get(
|
|||
.count(ctx.db())
|
||||
.await?;
|
||||
|
||||
crate::server::builders::collection(&url!(ctx, "/context/{id}"), Some(count))
|
||||
crate::server::builders::collection(&local_context_id, Some(count))
|
||||
}
|
||||
|
||||
pub async fn page(
|
||||
|
|
|
@ -8,11 +8,8 @@ pub async fn get(
|
|||
Path(id): Path<String>,
|
||||
AuthIdentity(auth): AuthIdentity,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
let oid = if id.starts_with('+') {
|
||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
||||
} else {
|
||||
ctx.oid(id.clone())
|
||||
};
|
||||
let replies_id = url!(ctx, "/objects/{id}/replies");
|
||||
let oid = ctx.uri("objects", id);
|
||||
|
||||
let count = model::addressing::Entity::find_addressed()
|
||||
.filter(auth.filter_condition())
|
||||
|
@ -20,7 +17,7 @@ pub async fn get(
|
|||
.count(ctx.db())
|
||||
.await?;
|
||||
|
||||
crate::server::builders::collection(&url!(ctx, "/objects/{id}/replies"), Some(count))
|
||||
crate::server::builders::collection(&replies_id, Some(count))
|
||||
}
|
||||
|
||||
pub async fn page(
|
||||
|
@ -29,14 +26,11 @@ pub async fn page(
|
|||
Query(page): Query<Pagination>,
|
||||
AuthIdentity(auth): AuthIdentity,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
let oid = if id.starts_with('+') {
|
||||
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
||||
} else {
|
||||
ctx.oid(id.clone())
|
||||
};
|
||||
let page_id = url!(ctx, "/objects/{id}/replies/page");
|
||||
let oid = ctx.uri("objects", id);
|
||||
|
||||
crate::server::builders::paginate(
|
||||
url!(ctx, "/objects/{id}/replies/page"),
|
||||
page_id,
|
||||
Condition::all()
|
||||
.add(auth.filter_condition())
|
||||
.add(model::object::Column::InReplyTo.eq(oid)),
|
||||
|
|
|
@ -97,7 +97,14 @@ impl Context {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue