Upgrade dependencies
- For new axum, use the new way to start the server. No other changes seem necessary. - For new atrium, update the way agent is initialized. Also now we cannot get the session out of the agent, so resolve our own handle to the did with an extra request. This is a shame, but eh. That's what you get when using unstable libraries
This commit is contained in:
parent
77d2d90522
commit
2bb88d69b3
File diff suppressed because it is too large
Load Diff
23
Cargo.toml
23
Cargo.toml
|
@ -9,25 +9,26 @@ default-run = "nederlandskie"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.75"
|
anyhow = "1.0.75"
|
||||||
async-trait = "0.1.74"
|
async-trait = "0.1.74"
|
||||||
atrium-api = "0.11.0"
|
atrium-api = "0.14.0"
|
||||||
atrium-xrpc = "0.4.1"
|
atrium-xrpc = "0.8.0"
|
||||||
axum = "0.6.20"
|
atrium-xrpc-client = "0.2.0"
|
||||||
chat-gpt-lib-rs = "0.2.1"
|
axum = "0.7.1"
|
||||||
|
chat-gpt-lib-rs = "0.3.2"
|
||||||
chrono = "0.4.31"
|
chrono = "0.4.31"
|
||||||
clap = { version = "4.4.7", features = ["derive"] }
|
clap = { version = "4.4.10", features = ["derive"] }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.1"
|
||||||
futures = "0.3.29"
|
futures = "0.3.29"
|
||||||
http = "0.2.9"
|
http = "1.0.0"
|
||||||
libipld-core = { version = "0.16.0", features = ["serde-codec"] }
|
libipld-core = { version = "0.16.0", features = ["serde-codec"] }
|
||||||
lingua = "1.5.0"
|
lingua = "1.6.1"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
rs-car = "0.4.1"
|
rs-car = "0.4.1"
|
||||||
scooby = "0.5.0"
|
scooby = "0.5.0"
|
||||||
serde = "1.0.190"
|
serde = "1.0.193"
|
||||||
serde_ipld_dagcbor = "0.4.2"
|
serde_ipld_dagcbor = "0.4.2"
|
||||||
sk-cbor = "0.1.2"
|
sk-cbor = "0.1.2"
|
||||||
sqlx = { version = "0.7.2", default-features = false, features = ["postgres", "runtime-tokio-native-tls", "chrono"] }
|
sqlx = { version = "0.7.3", default-features = false, features = ["postgres", "runtime-tokio-native-tls", "chrono"] }
|
||||||
tokio = { version = "1.33.0", features = ["full"] }
|
tokio = { version = "1.34.0", features = ["full"] }
|
||||||
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
|
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
|
||||||
|
|
|
@ -45,6 +45,11 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let bluesky = Bluesky::login(&handle, &password).await?;
|
let bluesky = Bluesky::login(&handle, &password).await?;
|
||||||
|
|
||||||
|
let publisher_did = bluesky
|
||||||
|
.resolve_handle(&handle)
|
||||||
|
.await?
|
||||||
|
.expect("couldn't resolve our own handle, huh?");
|
||||||
|
|
||||||
let mut avatar = None;
|
let mut avatar = None;
|
||||||
if let Some(path) = args.avatar_filename {
|
if let Some(path) = args.avatar_filename {
|
||||||
let bytes = std::fs::read(path)?;
|
let bytes = std::fs::read(path)?;
|
||||||
|
@ -54,7 +59,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
bluesky
|
bluesky
|
||||||
.publish_feed(
|
.publish_feed(
|
||||||
&bluesky.session().unwrap().did,
|
&publisher_did,
|
||||||
&feed_generator_did,
|
&feed_generator_did,
|
||||||
&args.name,
|
&args.name,
|
||||||
&args.display_name,
|
&args.display_name,
|
||||||
|
|
|
@ -2,7 +2,7 @@ extern crate nederlandskie;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
|
||||||
use nederlandskie::services::Bluesky;
|
use nederlandskie::services::Bluesky;
|
||||||
|
@ -18,11 +18,13 @@ async fn main() -> Result<()> {
|
||||||
.context("PUBLISHER_BLUESKY_PASSWORD environment variable must be set")?;
|
.context("PUBLISHER_BLUESKY_PASSWORD environment variable must be set")?;
|
||||||
|
|
||||||
let bluesky = Bluesky::login(&handle, &password).await?;
|
let bluesky = Bluesky::login(&handle, &password).await?;
|
||||||
let session = bluesky
|
|
||||||
.session()
|
|
||||||
.ok_or_else(|| anyhow!("Could not log in"))?;
|
|
||||||
|
|
||||||
println!("{}", session.did);
|
let did = bluesky
|
||||||
|
.resolve_handle(&handle)
|
||||||
|
.await?
|
||||||
|
.expect("couldn't resolve our own handle, huh?");
|
||||||
|
|
||||||
|
println!("{}", did);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use std::net::SocketAddr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Router, Server};
|
use axum::Router;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
use crate::algos::Algos;
|
use crate::algos::Algos;
|
||||||
|
@ -46,11 +45,11 @@ impl FeedServer {
|
||||||
algos: self.algos,
|
algos: self.algos,
|
||||||
});
|
});
|
||||||
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3030));
|
let addr = "0.0.0.0:3030";
|
||||||
|
|
||||||
info!("Serving feed on {}", addr);
|
info!("Serving feed on {}", addr);
|
||||||
|
|
||||||
Server::bind(&addr).serve(app.into_make_service()).await?;
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||||
|
axum::serve(listener, app).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::matches;
|
use std::matches;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use atrium_api::agent::{AtpAgent, Session};
|
use atrium_api::agent::{store::MemorySessionStore, AtpAgent};
|
||||||
use atrium_api::blob::BlobRef;
|
use atrium_api::blob::BlobRef;
|
||||||
use atrium_api::records::Record;
|
use atrium_api::records::Record;
|
||||||
use atrium_xrpc::client::reqwest::ReqwestClient;
|
use atrium_xrpc_client::reqwest::ReqwestClient;
|
||||||
use axum::http::StatusCode;
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use http::StatusCode;
|
||||||
use log::error;
|
use log::error;
|
||||||
use tokio_tungstenite::{connect_async, tungstenite};
|
use tokio_tungstenite::{connect_async, tungstenite};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ use super::entities::ProfileDetails;
|
||||||
use super::streaming::{handle_message, CommitProcessor};
|
use super::streaming::{handle_message, CommitProcessor};
|
||||||
|
|
||||||
pub struct Bluesky {
|
pub struct Bluesky {
|
||||||
agent: AtpAgent<ReqwestClient>,
|
agent: AtpAgent<MemorySessionStore, ReqwestClient>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bluesky {
|
impl Bluesky {
|
||||||
|
@ -24,21 +24,23 @@ impl Bluesky {
|
||||||
|
|
||||||
pub fn unauthenticated() -> Self {
|
pub fn unauthenticated() -> Self {
|
||||||
Self {
|
Self {
|
||||||
agent: AtpAgent::new(ReqwestClient::new(Self::XRPC_HOST.to_owned())),
|
agent: AtpAgent::new(
|
||||||
|
ReqwestClient::new(Self::XRPC_HOST.to_owned()),
|
||||||
|
MemorySessionStore::default(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn login(handle: &str, password: &str) -> Result<Self> {
|
pub async fn login(handle: &str, password: &str) -> Result<Self> {
|
||||||
let agent = AtpAgent::new(ReqwestClient::new(Self::XRPC_HOST.to_owned()));
|
let agent = AtpAgent::new(
|
||||||
|
ReqwestClient::new(Self::XRPC_HOST.to_owned()),
|
||||||
|
MemorySessionStore::default(),
|
||||||
|
);
|
||||||
agent.login(handle, password).await?;
|
agent.login(handle, password).await?;
|
||||||
|
|
||||||
Ok(Self { agent })
|
Ok(Self { agent })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn session(&self) -> Option<Session> {
|
|
||||||
self.agent.get_session()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn upload_blob(&self, blob: Vec<u8>) -> Result<BlobRef> {
|
pub async fn upload_blob(&self, blob: Vec<u8>) -> Result<BlobRef> {
|
||||||
let result = self.agent.api.com.atproto.repo.upload_blob(blob).await?;
|
let result = self.agent.api.com.atproto.repo.upload_blob(blob).await?;
|
||||||
|
|
||||||
|
@ -167,13 +169,18 @@ fn is_missing_record_error<T>(error: &atrium_xrpc::error::Error<T>) -> bool {
|
||||||
|
|
||||||
matches!(error,
|
matches!(error,
|
||||||
Error::XrpcResponse(XrpcError {
|
Error::XrpcResponse(XrpcError {
|
||||||
status: StatusCode::BAD_REQUEST,
|
status,
|
||||||
error:
|
error:
|
||||||
Some(XrpcErrorKind::Undefined(ErrorResponseBody {
|
Some(XrpcErrorKind::Undefined(ErrorResponseBody {
|
||||||
error: Some(error_code),
|
error: Some(error_code),
|
||||||
message: Some(error_message),
|
message: Some(error_message),
|
||||||
})),
|
})),
|
||||||
}) if error_code == "InvalidRequest"
|
}) if
|
||||||
|
// FIXME: This is this way instead of pattern matching because atrium's
|
||||||
|
// version of http is pegged at like 0.2.x and it does not
|
||||||
|
// re-export it so we have no way of referencing the real type
|
||||||
|
status.as_u16() == StatusCode::BAD_REQUEST.as_u16()
|
||||||
|
&& error_code == "InvalidRequest"
|
||||||
&& error_message.starts_with("Could not locate record")
|
&& error_message.starts_with("Could not locate record")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -183,13 +190,18 @@ fn is_unable_to_resolve_handle_error<T>(error: &atrium_xrpc::error::Error<T>) ->
|
||||||
|
|
||||||
matches!(error,
|
matches!(error,
|
||||||
Error::XrpcResponse(XrpcError {
|
Error::XrpcResponse(XrpcError {
|
||||||
status: StatusCode::BAD_REQUEST,
|
status,
|
||||||
error:
|
error:
|
||||||
Some(XrpcErrorKind::Undefined(ErrorResponseBody {
|
Some(XrpcErrorKind::Undefined(ErrorResponseBody {
|
||||||
error: Some(error_code),
|
error: Some(error_code),
|
||||||
message: Some(error_message),
|
message: Some(error_message),
|
||||||
})),
|
})),
|
||||||
}) if error_code == "InvalidRequest"
|
}) if
|
||||||
|
// FIXME: This is this way instead of pattern matching because atrium's
|
||||||
|
// version of http is pegged at like 0.2.x and it does not
|
||||||
|
// re-export it so we have no way of referencing the real type
|
||||||
|
status.as_u16() == StatusCode::BAD_REQUEST.as_u16()
|
||||||
|
&& error_code == "InvalidRequest"
|
||||||
&& error_message.starts_with("Unable to resolve handle")
|
&& error_message.starts_with("Unable to resolve handle")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue