Skip to content

Commit

Permalink
return storage caps when getting usage
Browse files Browse the repository at this point in the history
  • Loading branch information
billyb2 committed Oct 3, 2024
1 parent cc2b6a4 commit 73e2c11
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
17 changes: 4 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ COPY --from=builder /tmp/build/result /app

COPY --from=builder-sqlx /build/bin/sqlx /usr/bin/sqlx
COPY migrations /app/migrations
COPY fly-airship-client ./fly-airship-client

CMD ["/app/bin/file_server"]
CMD ["./fly-airship-client", "--", "/app/bin/file_server"]
2 changes: 2 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ primary_region = 'ord'
[env]
RUST_BACKTRACE = '1'
TOKEN_PUBLIC_KEY = 'd27fb9c11d7608f86aa9e90a00133d58688b2fe4e7903a35199a25f7e905f658'
AIRSHIP_SERVER_URL = "http://fly-airship-server.flycast"
INTERFACE_NAME = "eth0"

[http_service]
internal_port = 80
Expand Down
23 changes: 18 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,12 @@ pub async fn handle_message<M: MetaDB + 'static, C: ChunkDB + 'static>(
}
}
GetUsageQuery(_query) => match handle_get_usage(meta_db.as_ref(), &token).await {
Ok(usage) => bfsp::GetUsageResp {
Ok((total_usage, storage_cap)) => bfsp::GetUsageResp {
response: Some(bfsp::get_usage_resp::Response::Usage(
bfsp::get_usage_resp::Usage { total_usage: usage },
bfsp::get_usage_resp::Usage {
total_usage,
storage_cap,
},
)),
}
.encode_to_vec(),
Expand Down Expand Up @@ -740,14 +743,24 @@ pub async fn handle_delete_file_metadata<D: MetaDB>(
}

#[tracing::instrument(err, skip(token, meta_db))]
pub async fn handle_get_usage<D: MetaDB>(meta_db: &D, token: &Biscuit) -> anyhow::Result<u64> {
pub async fn handle_get_usage<D: MetaDB>(
meta_db: &D,
token: &Biscuit,
) -> anyhow::Result<(u64, u64)> {
let user_id = authorize(Right::Usage, token, Vec::new(), meta_db)
.await
.unwrap();

Ok(*meta_db
let usage = *meta_db
.total_usages(&[user_id])
.await?
.get(&user_id)
.unwrap())
.unwrap();
let cap = *meta_db
.storage_caps(&[user_id])
.await?
.get(&user_id)
.unwrap();

Ok((usage, cap))
}

0 comments on commit 73e2c11

Please sign in to comment.