core/bild.db
core/bild.db
This is a binary file and will not be displayed.
+28
-6
core/src/routes.rs
+28
-6
core/src/routes.rs
···
1
1
pub mod login {
2
+
use crate::AppState;
2
3
use atrium_api::{
3
4
agent::{AtpAgent, store::MemorySessionStore},
4
5
types::string::AtIdentifier,
5
6
};
6
7
use atrium_xrpc_client::isahc::IsahcClient;
7
-
use axum::{extract::Form, http::StatusCode, response::IntoResponse};
8
+
use axum::{
9
+
extract::{Form, State},
10
+
http::StatusCode,
11
+
response::IntoResponse,
12
+
};
8
13
use serde::Deserialize;
9
14
10
15
pub async fn get() -> String {
···
17
22
app_password: String,
18
23
}
19
24
20
-
pub async fn post(session: tower_sessions::Session, Form(req): Form<Req>) -> impl IntoResponse {
25
+
pub async fn post(
26
+
State(state): State<AppState>,
27
+
session: tower_sessions::Session,
28
+
Form(req): Form<Req>,
29
+
) -> impl IntoResponse {
30
+
let did_doc = state.resolve_did_document(&req.handle).await.unwrap();
21
31
let agent = AtpAgent::new(
22
-
IsahcClient::new("https://dummy.example"),
32
+
IsahcClient::new(did_doc.get_pds_endpoint().unwrap()),
23
33
MemorySessionStore::default(),
24
34
);
25
35
let res = agent.login(req.handle, req.app_password).await.unwrap();
···
31
41
}
32
42
33
43
pub mod index {
44
+
use crate::AppState;
34
45
use atrium_api::agent::{AtpAgent, store::MemorySessionStore};
46
+
use atrium_api::types::string::AtIdentifier;
35
47
use atrium_xrpc_client::isahc::IsahcClient;
48
+
use axum::extract::State;
36
49
37
-
pub async fn get(session: tower_sessions::Session) -> &'static str {
50
+
pub async fn get(
51
+
session: tower_sessions::Session,
52
+
State(state): State<AppState>,
53
+
) -> &'static str {
38
54
match session
39
55
.get::<atrium_api::agent::Session>("bild_session")
40
56
.await
···
42
58
{
43
59
None => "no session",
44
60
Some(s) => {
61
+
let did_doc = state
62
+
.resolve_did_document(&AtIdentifier::Did(s.did.clone()))
63
+
.await
64
+
.unwrap();
45
65
let agent = AtpAgent::new(
46
-
IsahcClient::new("https://dummy.example"),
66
+
IsahcClient::new(did_doc.get_pds_endpoint().unwrap()),
47
67
MemorySessionStore::default(),
48
68
);
49
69
println!("resuming session of {:?} ({:?})", s.handle, s.did);
···
123
143
let did = sess.did.clone().into();
124
144
db.conn
125
145
.call(|c| {
126
-
c.execute("INSERT INTO keys VALUES (?1, ?2)", [did, req.key])?;
146
+
c.execute("INSERT INTO keys (did, key) VALUES (?1, ?2)", [
147
+
did, req.key,
148
+
])?;
127
149
Ok(())
128
150
})
129
151
.await