Compare commits
2 commits
d4a3a71e2f
...
8363125108
| Author | SHA1 | Date | |
|---|---|---|---|
| 8363125108 | |||
| db33099405 |
12 changed files with 911 additions and 62 deletions
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"lexicon": 1,
|
|
||||||
"id": "me.woach.content.anilist",
|
|
||||||
"defs": {
|
|
||||||
"main": {
|
|
||||||
"type": "object",
|
|
||||||
"required": ["id"],
|
|
||||||
"key": "nsid",
|
|
||||||
"properties": {
|
|
||||||
"id": { "type": "integer" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
30
lexicons/my/spoor/content/external.json
Normal file
30
lexicons/my/spoor/content/external.json
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"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": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"lexicon": 1,
|
"lexicon": 1,
|
||||||
"id": "me.woach.content.media",
|
"id": "my.spoor.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": "me.woach.content.title"
|
"ref": "my.spoor.content.title"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"durationData": {
|
"durationData": {
|
||||||
"type": "union",
|
"type": "union",
|
||||||
"refs": [
|
"refs": [
|
||||||
"me.woach.content.media#television",
|
"my.spoor.content.media#television",
|
||||||
"me.woach.content.media#book"
|
"my.spoor.content.media#book"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"posterImage": {
|
"posterImage": {
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
{
|
{
|
||||||
"lexicon": 1,
|
"lexicon": 1,
|
||||||
"id": "me.woach.content.title",
|
"id": "my.spoor.content.title",
|
||||||
"defs": {
|
"defs": {
|
||||||
"main": {
|
"main": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"language": {
|
"language": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
"format": "nsid",
|
||||||
"knownValues": [
|
"knownValues": [
|
||||||
"me.woach.content.title#romanization",
|
"my.spoor.content.title#romanization",
|
||||||
"me.woach.content.title#english",
|
"my.spoor.content.title#english",
|
||||||
"me.woach.content.title#native"
|
"my.spoor.content.title#native"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"value": { "type": "string", "minLength": 1 }
|
"value": { "type": "string", "minLength": 1 }
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"lexicon": 1,
|
"lexicon": 1,
|
||||||
"id": "me.woach.feed.activity",
|
"id": "my.spoor.log.activity",
|
||||||
"defs": {
|
"defs": {
|
||||||
"main": {
|
"main": {
|
||||||
"type": "record",
|
"type": "record",
|
||||||
"description": "A single activity log for a specific show",
|
"description": "A single activity (spoor) for a specific session",
|
||||||
"key": "tid",
|
"key": "tid",
|
||||||
"record": {
|
"record": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
@ -13,13 +13,15 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"session": { "type": "ref", "ref": "com.atproto.repo.strongRef" },
|
"session": { "type": "ref", "ref": "com.atproto.repo.strongRef" },
|
||||||
"progress": {
|
"progress": {
|
||||||
"type": "integer",
|
"type": "union",
|
||||||
"description": "The episode/chapter number for the content consumed."
|
"refs": [
|
||||||
|
"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."
|
"description": "User-declared timestamp for when they performed the activity. Null implies unknown time."
|
||||||
},
|
},
|
||||||
"createdAt": {
|
"createdAt": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
@ -28,6 +30,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"indexProgress": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "The index of the content consumed. Content must be indexable"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"lexicon": 1,
|
"lexicon": 1,
|
||||||
"id": "me.woach.feed.session",
|
"id": "my.spoor.log.session",
|
||||||
"defs": {
|
"defs": {
|
||||||
"main": {
|
"main": {
|
||||||
"type": "record",
|
"type": "record",
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
"maxGraphemes": 64,
|
"maxGraphemes": 64,
|
||||||
"maxLength": 640
|
"maxLength": 640
|
||||||
},
|
},
|
||||||
"participants": {
|
"otherParticipants": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "type": "ref", "ref": "com.atproto.repo.strongRef" }
|
"items": { "type": "string", "format": "did" }
|
||||||
},
|
},
|
||||||
"createdAt": {
|
"createdAt": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
830
rust/Cargo.lock
generated
830
rust/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,9 +6,11 @@ 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 = ["runtime-tokio"] }
|
sqlx = { version = "0.8.5", features = ["postgres", "runtime-tokio"] }
|
||||||
tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
|
||||||
1
rust/src/atproto.rs
Normal file
1
rust/src/atproto.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub use atrium_api::types::string::Nsid;
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use crate::router::{
|
use crate::{
|
||||||
|
atproto::Nsid,
|
||||||
|
router::{
|
||||||
Router,
|
Router,
|
||||||
Endpoint,
|
Endpoint,
|
||||||
xrpc::{
|
xrpc::{
|
||||||
|
|
@ -7,18 +9,21 @@ use crate::router::{
|
||||||
Response,
|
Response,
|
||||||
error,
|
error,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use axum::http::StatusCode;
|
use http::status::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();
|
||||||
router = router.add_endpoint(Endpoint::new_xrpc_query(String::from("me.woach.get"), test));
|
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_procedure(String::from("me.woach.post"), test2));
|
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_query(get_nsid, test));
|
||||||
|
router = router.add_endpoint(Endpoint::new_xrpc_procedure(post_nsid, test2));
|
||||||
router.serve().await;
|
router.serve().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
use crate::router::xrpc::{
|
use crate::{
|
||||||
XrpcEndpoint,
|
atproto::Nsid,
|
||||||
XrpcHandler,
|
router::xrpc::{
|
||||||
QueryInput,
|
XrpcEndpoint,
|
||||||
ProcedureInput,
|
XrpcHandler,
|
||||||
|
QueryInput,
|
||||||
|
ProcedureInput,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
use axum::Router as AxumRouter;
|
use axum::Router as AxumRouter;
|
||||||
use core::net::SocketAddr;
|
use core::net::SocketAddr;
|
||||||
|
|
@ -19,13 +22,13 @@ pub enum Endpoint {
|
||||||
Xrpc(XrpcEndpoint),
|
Xrpc(XrpcEndpoint),
|
||||||
}
|
}
|
||||||
impl Endpoint {
|
impl Endpoint {
|
||||||
pub fn new_xrpc_query<Q>(nsid: String, query: Q) -> Self
|
pub fn new_xrpc_query<Q>(nsid: Nsid, 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: String, procedure: P) -> Self
|
pub fn new_xrpc_procedure<P>(nsid: Nsid, procedure: P) -> Self
|
||||||
where
|
where
|
||||||
P: XrpcHandler<ProcedureInput> + Clone
|
P: XrpcHandler<ProcedureInput> + Clone
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::atproto::Nsid;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
|
@ -26,13 +27,13 @@ use axum::{
|
||||||
};
|
};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
enum Nsid {
|
enum Path {
|
||||||
Nsid(String),
|
Nsid(Nsid),
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct XrpcEndpoint {
|
pub struct XrpcEndpoint {
|
||||||
nsid: Nsid,
|
path: Path,
|
||||||
resolver: MethodRouter,
|
resolver: MethodRouter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,12 +124,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XrpcEndpoint {
|
impl XrpcEndpoint {
|
||||||
pub fn new_query<Q>(nsid: String, query: Q) -> Self
|
pub fn new_query<Q>(nsid: Nsid, query: Q) -> Self
|
||||||
where
|
where
|
||||||
Q: XrpcHandler<QueryInput> + Clone
|
Q: XrpcHandler<QueryInput> + Clone
|
||||||
{
|
{
|
||||||
XrpcEndpoint {
|
XrpcEndpoint {
|
||||||
nsid: Nsid::Nsid(nsid),
|
path: Path::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,
|
||||||
|
|
@ -138,12 +139,12 @@ impl XrpcEndpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_procedure<P>(nsid: String, procedure: P) -> Self
|
pub fn new_procedure<P>(nsid: Nsid, procedure: P) -> Self
|
||||||
where
|
where
|
||||||
P: XrpcHandler<ProcedureInput> + Clone
|
P: XrpcHandler<ProcedureInput> + Clone
|
||||||
{
|
{
|
||||||
XrpcEndpoint {
|
XrpcEndpoint {
|
||||||
nsid: Nsid::Nsid(nsid),
|
path: Path::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,
|
||||||
|
|
@ -154,9 +155,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.nsid {
|
let path = match self.path {
|
||||||
Nsid::Nsid(s) => &("/xrpc/".to_owned() + &s),
|
Path::Nsid(nsid) => &("/xrpc/".to_owned() + nsid.as_str()),
|
||||||
Nsid::NotImplemented => "/xrpc/{*nsid}",
|
Path::NotImplemented => "/xrpc/{*nsid}",
|
||||||
};
|
};
|
||||||
|
|
||||||
router.route(path, self.resolver)
|
router.route(path, self.resolver)
|
||||||
|
|
@ -172,7 +173,7 @@ impl XrpcEndpoint {
|
||||||
);
|
);
|
||||||
|
|
||||||
XrpcEndpoint {
|
XrpcEndpoint {
|
||||||
nsid: Nsid::NotImplemented,
|
path: Path::NotImplemented,
|
||||||
resolver: get(resolver.clone()).post(resolver),
|
resolver: get(resolver.clone()).post(resolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue