Compare commits

..

No commits in common. "83631251089c580eae4d3a80cdf24c99711e1bb3" and "d4a3a71e2fefea88ac4465937d64e0ae11f8e79d" have entirely different histories.

12 changed files with 62 additions and 911 deletions

View file

@ -0,0 +1,14 @@
{
"lexicon": 1,
"id": "me.woach.content.anilist",
"defs": {
"main": {
"type": "object",
"required": ["id"],
"key": "nsid",
"properties": {
"id": { "type": "integer" }
}
}
}
}

View file

@ -1,6 +1,6 @@
{ {
"lexicon": 1, "lexicon": 1,
"id": "my.spoor.content.media", "id": "me.woach.content.media",
"defs": { "defs": {
"main": { "main": {
"type": "object", "type": "object",
@ -12,14 +12,14 @@
"minLength": 1, "minLength": 1,
"items": { "items": {
"type": "ref", "type": "ref",
"ref": "my.spoor.content.title" "ref": "me.woach.content.title"
} }
}, },
"durationData": { "durationData": {
"type": "union", "type": "union",
"refs": [ "refs": [
"my.spoor.content.media#television", "me.woach.content.media#television",
"my.spoor.content.media#book" "me.woach.content.media#book"
] ]
}, },
"posterImage": { "posterImage": {

View file

@ -1,17 +1,16 @@
{ {
"lexicon": 1, "lexicon": 1,
"id": "my.spoor.content.title", "id": "me.woach.content.title",
"defs": { "defs": {
"main": { "main": {
"type": "object", "type": "object",
"properties": { "properties": {
"language": { "language": {
"type": "string", "type": "string",
"format": "nsid",
"knownValues": [ "knownValues": [
"my.spoor.content.title#romanization", "me.woach.content.title#romanization",
"my.spoor.content.title#english", "me.woach.content.title#english",
"my.spoor.content.title#native" "me.woach.content.title#native"
] ]
}, },
"value": { "type": "string", "minLength": 1 } "value": { "type": "string", "minLength": 1 }

View file

@ -1,10 +1,10 @@
{ {
"lexicon": 1, "lexicon": 1,
"id": "my.spoor.log.activity", "id": "me.woach.feed.activity",
"defs": { "defs": {
"main": { "main": {
"type": "record", "type": "record",
"description": "A single activity (spoor) for a specific session", "description": "A single activity log for a specific show",
"key": "tid", "key": "tid",
"record": { "record": {
"type": "object", "type": "object",
@ -13,15 +13,13 @@
"properties": { "properties": {
"session": { "type": "ref", "ref": "com.atproto.repo.strongRef" }, "session": { "type": "ref", "ref": "com.atproto.repo.strongRef" },
"progress": { "progress": {
"type": "union", "type": "integer",
"refs": [ "description": "The episode/chapter number for the content consumed."
"my.spoor.log.activity#indexProgress"
]
}, },
"performedAt": { "performedAt": {
"type": "string", "type": "string",
"format": "datetime", "format": "datetime",
"description": "User-declared timestamp for when they performed the activity. Null implies unknown time." "description": "User-declared timestamp for when they performed the activity."
}, },
"createdAt": { "createdAt": {
"type": "string", "type": "string",
@ -30,10 +28,6 @@
} }
} }
} }
},
"indexProgress": {
"type": "integer",
"description": "The index of the content consumed. Content must be indexable"
} }
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"lexicon": 1, "lexicon": 1,
"id": "my.spoor.log.session", "id": "me.woach.feed.session",
"defs": { "defs": {
"main": { "main": {
"type": "record", "type": "record",
@ -16,9 +16,9 @@
"maxGraphemes": 64, "maxGraphemes": 64,
"maxLength": 640 "maxLength": 640
}, },
"otherParticipants": { "participants": {
"type": "array", "type": "array",
"items": { "type": "string", "format": "did" } "items": { "type": "ref", "ref": "com.atproto.repo.strongRef" }
}, },
"createdAt": { "createdAt": {
"type": "string", "type": "string",

View file

@ -1,30 +0,0 @@
{
"lexicon": 1,
"id": "my.spoor.content.external",
"defs": {
"main": {
"type": "object",
"required": [ "source", "queryable" ],
"key": "nsid",
"properties": {
"source": {
"type": "string",
"description": "An nsid for a specific data source. The domain authority governs how to process the queryable",
"format": "nsid",
"knownValues": [
"my.spoor.content.external#tvdb"
]
},
"queryable": {
"type": "union",
"description": "All the data needed to query the content from the source"
},
"overrides": {
"type": "object",
"description": "User defined overrides for the returned content",
"properties": {}
}
}
}
}
}

830
rust/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,11 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
atrium-api = { version = "0.25.2", default-features = false }
axum = { version = "0.8.3", features = ["json"] } axum = { version = "0.8.3", features = ["json"] }
axum-macros = "0.5.0" axum-macros = "0.5.0"
http = "1.3.1"
serde = "1.0.219" serde = "1.0.219"
serde_json = "1.0.140" serde_json = "1.0.140"
sqlx = { version = "0.8.5", features = ["postgres", "runtime-tokio"] } sqlx = { version = "0.8.5", features = ["runtime-tokio"] }
tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] }

View file

@ -1 +0,0 @@
pub use atrium_api::types::string::Nsid;

View file

@ -1,6 +1,4 @@
use crate::{ use crate::router::{
atproto::Nsid,
router::{
Router, Router,
Endpoint, Endpoint,
xrpc::{ xrpc::{
@ -9,21 +7,18 @@ use crate::{
Response, Response,
error, error,
}, },
},
}; };
use http::status::StatusCode; use axum::http::StatusCode;
mod atproto;
mod router; mod router;
mod db; mod db;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let mut router = Router::new(); let mut router = Router::new();
let get_nsid = Nsid::new(String::from("me.woach.get")).expect("me.woach.get is a valid nsid"); router = router.add_endpoint(Endpoint::new_xrpc_query(String::from("me.woach.get"), test));
let post_nsid = Nsid::new(String::from("me.woach.post")).expect("me.woach.post is a valid nsid"); router = router.add_endpoint(Endpoint::new_xrpc_procedure(String::from("me.woach.post"), test2));
router = router.add_endpoint(Endpoint::new_xrpc_query(get_nsid, test));
router = router.add_endpoint(Endpoint::new_xrpc_procedure(post_nsid, test2));
router.serve().await; router.serve().await;
} }

View file

@ -1,11 +1,8 @@
use crate::{ use crate::router::xrpc::{
atproto::Nsid, XrpcEndpoint,
router::xrpc::{ XrpcHandler,
XrpcEndpoint, QueryInput,
XrpcHandler, ProcedureInput,
QueryInput,
ProcedureInput,
}
}; };
use axum::Router as AxumRouter; use axum::Router as AxumRouter;
use core::net::SocketAddr; use core::net::SocketAddr;
@ -22,13 +19,13 @@ pub enum Endpoint {
Xrpc(XrpcEndpoint), Xrpc(XrpcEndpoint),
} }
impl Endpoint { impl Endpoint {
pub fn new_xrpc_query<Q>(nsid: Nsid, query: Q) -> Self pub fn new_xrpc_query<Q>(nsid: String, query: Q) -> Self
where where
Q: XrpcHandler<QueryInput> + Clone Q: XrpcHandler<QueryInput> + Clone
{ {
Endpoint::Xrpc(XrpcEndpoint::new_query(nsid,query)) Endpoint::Xrpc(XrpcEndpoint::new_query(nsid,query))
} }
pub fn new_xrpc_procedure<P>(nsid: Nsid, procedure: P) -> Self pub fn new_xrpc_procedure<P>(nsid: String, procedure: P) -> Self
where where
P: XrpcHandler<ProcedureInput> + Clone P: XrpcHandler<ProcedureInput> + Clone
{ {

View file

@ -1,4 +1,3 @@
use crate::atproto::Nsid;
use std::{ use std::{
collections::HashMap, collections::HashMap,
pin::Pin, pin::Pin,
@ -27,13 +26,13 @@ use axum::{
}; };
use serde_json::{Value, json}; use serde_json::{Value, json};
enum Path { enum Nsid {
Nsid(Nsid), Nsid(String),
NotImplemented, NotImplemented,
} }
pub struct XrpcEndpoint { pub struct XrpcEndpoint {
path: Path, nsid: Nsid,
resolver: MethodRouter, resolver: MethodRouter,
} }
@ -124,12 +123,12 @@ where
} }
impl XrpcEndpoint { impl XrpcEndpoint {
pub fn new_query<Q>(nsid: Nsid, query: Q) -> Self pub fn new_query<Q>(nsid: String, query: Q) -> Self
where where
Q: XrpcHandler<QueryInput> + Clone Q: XrpcHandler<QueryInput> + Clone
{ {
XrpcEndpoint { XrpcEndpoint {
path: Path::Nsid(nsid), nsid: Nsid::Nsid(nsid),
resolver: get(async move | mut parts: Parts | -> Response { resolver: get(async move | mut parts: Parts | -> Response {
match QueryInput::from_request_parts(&mut parts, &()).await { match QueryInput::from_request_parts(&mut parts, &()).await {
Ok(qi) => query.call(qi).await, Ok(qi) => query.call(qi).await,
@ -139,12 +138,12 @@ impl XrpcEndpoint {
} }
} }
pub fn new_procedure<P>(nsid: Nsid, procedure: P) -> Self pub fn new_procedure<P>(nsid: String, procedure: P) -> Self
where where
P: XrpcHandler<ProcedureInput> + Clone P: XrpcHandler<ProcedureInput> + Clone
{ {
XrpcEndpoint { XrpcEndpoint {
path: Path::Nsid(nsid), nsid: Nsid::Nsid(nsid),
resolver: post(async move | req: Request | -> Response { resolver: post(async move | req: Request | -> Response {
match ProcedureInput::from_request(req, &()).await { match ProcedureInput::from_request(req, &()).await {
Ok(pi) => procedure.call(pi).await, Ok(pi) => procedure.call(pi).await,
@ -155,9 +154,9 @@ impl XrpcEndpoint {
} }
pub fn add_to_router(self, router: axumRouter) -> axumRouter { pub fn add_to_router(self, router: axumRouter) -> axumRouter {
let path = match self.path { let path = match self.nsid {
Path::Nsid(nsid) => &("/xrpc/".to_owned() + nsid.as_str()), Nsid::Nsid(s) => &("/xrpc/".to_owned() + &s),
Path::NotImplemented => "/xrpc/{*nsid}", Nsid::NotImplemented => "/xrpc/{*nsid}",
}; };
router.route(path, self.resolver) router.route(path, self.resolver)
@ -173,7 +172,7 @@ impl XrpcEndpoint {
); );
XrpcEndpoint { XrpcEndpoint {
path: Path::NotImplemented, nsid: Nsid::NotImplemented,
resolver: get(resolver.clone()).post(resolver), resolver: get(resolver.clone()).post(resolver),
} }
} }