Compare commits
No commits in common. "88bdfdfc876a842261328e5b956b554c9a2502b3" and "2ff0d37313b4cee8cd6966e193496d9f19ae6ce9" have entirely different histories.
88bdfdfc87
...
2ff0d37313
9 changed files with 3 additions and 37 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,5 +3,3 @@
|
|||
/.cache
|
||||
/node_modules
|
||||
testing.db
|
||||
testing.db-shm
|
||||
testing.db-wal
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
[sqlfluff]
|
||||
dialect = sqlite
|
||||
|
||||
[sqlfluff:rules:capitalisation.keywords]
|
||||
# Keywords
|
||||
capitalisation_policy = upper
|
||||
|
||||
[sqlfluff:layout:type:column_constraint_segment]
|
||||
spacing_before = align
|
||||
align_within = create_table_statement
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
-- Add up migration script here
|
||||
CREATE TABLE IF NOT EXISTS records (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
uploaded TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
id INTEGER PRIMARY KEY,
|
||||
uploaded TEXT NOT NULL,
|
||||
file_path TEXT NOT NULL,
|
||||
downloads INTEGER NOT NULL DEFAULT 0,
|
||||
max_downloads INTEGER NOT NULL
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
SELECT COUNT(*) FROM records;
|
|
@ -1,3 +0,0 @@
|
|||
UPDATE record
|
||||
SET downloads = downloads + 1
|
||||
WHERE id = ?
|
|
@ -1,2 +0,0 @@
|
|||
INSERT INTO records (file_path, max_downloads)
|
||||
VALUES (?, ?);
|
|
@ -12,9 +12,7 @@ mkShell rec {
|
|||
# Additional darwin specific inputs can be set here
|
||||
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
|
||||
];
|
||||
buildInputs = [
|
||||
sqlite
|
||||
] ++ additionalBuildInputs;
|
||||
buildInputs = additionalBuildInputs;
|
||||
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
|
||||
DATABASE_URL = "sqlite:testing.db";
|
||||
}
|
||||
|
|
|
@ -75,19 +75,6 @@ async fn upload_to_zip(
|
|||
|
||||
let record = UploadRecord::new(archive_path);
|
||||
let mut records = state.records.lock().await;
|
||||
|
||||
if let Some(mut conn) = state.pool.try_acquire() {
|
||||
let path = record.file.clone().into_os_string().into_string().unwrap();
|
||||
|
||||
let id = sqlx::query_file!("queries/records/new.sql", path, 5)
|
||||
.execute(&mut *conn)
|
||||
.await
|
||||
.unwrap()
|
||||
.last_insert_rowid();
|
||||
|
||||
// TODO: Looks like I actually gotta store cache_name lmfao
|
||||
};
|
||||
|
||||
records.insert(cache_name.clone(), record.clone());
|
||||
|
||||
let records_cache = records.clone();
|
||||
|
|
|
@ -2,14 +2,12 @@ use std::{
|
|||
collections::{hash_map::Entry, HashMap},
|
||||
io::ErrorKind,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::cache;
|
||||
|
@ -56,17 +54,12 @@ impl Default for UploadRecord {
|
|||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub records: Arc<Mutex<HashMap<String, UploadRecord>>>,
|
||||
pub pool: SqlitePool,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(records: HashMap<String, UploadRecord>) -> Self {
|
||||
Self {
|
||||
records: Arc::new(Mutex::new(records)),
|
||||
pool: SqlitePool::connect_lazy_with(
|
||||
SqliteConnectOptions::from_str("sqlite:testing.db")
|
||||
.expect("Invalid Database String"),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue