Skip to content

Commit

Permalink
postgres and auth bug fixes
Browse files Browse the repository at this point in the history
silly billy
  • Loading branch information
billyb2 committed Apr 17, 2024
1 parent 9c9c696 commit bfb18cf
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 63 deletions.
66 changes: 33 additions & 33 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ humantime = "2"
sqlx = { version = "0.7", features = ["runtime-tokio", "postgres"] }
rand = "0.8"
wtransport = { version = "0.1" }
#bfsp = { path = "./bfsp" }
#bfsp = { path = "../bfsp" }
bfsp = { git = "https://github.com/Billy-s-E2EE-File-Server/bfsp.git" }
async-trait = { version = "0.1" }
futures = { version = "0.3", features = ["executor"] }
Expand Down
8 changes: 4 additions & 4 deletions migrations/20231018041636_chunks.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE chunks (
hash text primary key unique not null,
id text unique not null,
indice int not null,
chunk_size int not null,
id text primary key unique not null,
hash text not null,
indice bigint not null,
chunk_size bigint not null,
nonce bytea not null,
user_id bigint not null
)
8 changes: 5 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl ChunkDatabase for PostgresDB {
user_id: i64,
) -> std::result::Result<(), InsertChunkError> {
let indice: i64 = chunk_meta.indice.try_into().unwrap();
let chunk_id: ChunkID = ChunkID::from_bytes(chunk_meta.id.try_into().unwrap());
let chunk_id: ChunkID = ChunkID::try_from(chunk_meta.id.as_str()).unwrap();
let chunk_hash: ChunkHash = ChunkHash::from_bytes(chunk_meta.hash.try_into().unwrap());
let chunk_size: i64 = chunk_meta.size.into();

Expand Down Expand Up @@ -135,7 +135,7 @@ impl ChunkDatabase for PostgresDB {
.map(|chunk_info| {
let chunk_hash: ChunkHash = chunk_info.get::<String, _>("hash").try_into().unwrap();
ChunkMetadata {
id: chunk_id.to_bytes().to_vec(),
id: chunk_id.to_string(),
hash: chunk_hash.to_bytes().to_vec(),
size: chunk_info.get::<i64, _>("chunk_size").try_into().unwrap(),
indice: chunk_info.get::<i64, _>("indice").try_into().unwrap(),
Expand Down Expand Up @@ -183,7 +183,7 @@ impl ChunkDatabase for PostgresDB {
user_id: i64,
) -> Result<Option<EncryptedFileMetadata>> {
let row = sqlx::query(
"select encrypted_metadata, nonce from file_meta where id = $1 and user_id = $2",
"select encrypted_metadata, nonce from file_metadata where id = $1 and user_id = $2",
)
.bind(meta_id)
.bind(user_id)
Expand Down Expand Up @@ -211,6 +211,7 @@ impl ChunkDatabase for PostgresDB {
let mut query = QueryBuilder::new(
"select id, encrypted_metadata, nonce from file_metadata where user_id = $1",
);
debug!("id len: {}", ids.len());
if !ids.is_empty() {
query.push(" and id in (");
{
Expand All @@ -230,6 +231,7 @@ impl ChunkDatabase for PostgresDB {
.into_iter()
.map(|row| {
let meta_id: i64 = row.get("id");

let enc_meta: Vec<u8> = row.get("encrypted_metadata");
let nonce: Vec<u8> = row.get("nonce");
(
Expand Down
Loading

0 comments on commit bfb18cf

Please sign in to comment.