Skip to content

Commit cb17501

Browse files
committed
Addressing review comments
1 parent 110d8af commit cb17501

File tree

5 files changed

+31
-62
lines changed

5 files changed

+31
-62
lines changed
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ A Flask-based REST API for providing storage capabilities (key-value pairs and f
2323
- `DELETE /storage/<path>` - Delete file or directory
2424
- `POST /storage/rename` - Rename file or directory
2525

26-
## Running the Application
27-
28-
1. Install dependencies:
29-
```bash
30-
pip install flask flask-restful flask-sqlalchemy
31-
```
26+
## Setup
27+
1. cd <your repo>/backend
28+
2. python3.12 -m venv ./venv
29+
3. source ./venv/bin/activate
30+
4. python3.12 -m pip install -r requirements.txt
31+
5. deactivate
3232

33-
2. Run the application:
34-
```bash
35-
python main.py
36-
```
37-
38-
3. The API will be available at `http://localhost:5001`
33+
## Running the Application
34+
1. source ./venv/bin/activate
35+
2. python main.py
36+
3. The API will be available at `http://localhost:5001`
3937

4038
## Example Usage
4139

backend/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def handle_preflight():
2626

2727
# Configure SQLite database
2828
basedir = os.path.abspath(os.path.dirname(__file__))
29-
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(basedir, "storage.db")}'
29+
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(basedir, "projects.db")}'
3030
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
3131

3232
db = SQLAlchemy(app)

backend/requirements.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
aniso8601==10.0.1
2+
blinker==1.9.0
3+
click==8.2.1
4+
Flask==3.1.1
5+
Flask-RESTful==0.3.10
6+
Flask-SQLAlchemy==3.1.1
7+
itsdangerous==2.2.0
8+
Jinja2==3.1.6
9+
MarkupSafe==3.0.2
10+
pytz==2025.2
11+
six==1.17.0
12+
SQLAlchemy==2.0.42
13+
typing_extensions==4.14.1
14+
Werkzeug==3.1.3

backend/storage.db

-20 KB
Binary file not shown.

src/storage/server_side_storage.ts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import * as commonStorage from './common_storage';
2424

2525
const API_BASE_URL = 'http://localhost:5001';
2626

27-
async function isServerAvailable(): Promise<boolean> {
27+
export async function isServerAvailable(): Promise<boolean> {
2828
try {
2929
// Create a timeout promise
3030
const timeoutPromise = new Promise<never>((_, reject) => {
@@ -33,7 +33,7 @@ async function isServerAvailable(): Promise<boolean> {
3333

3434
// Race between the fetch and timeout
3535
const response = await Promise.race([
36-
fetch(`${API_BASE_URL}/`, { method: 'GET' }),
36+
fetch(`${API_BASE_URL}/`),
3737
timeoutPromise
3838
]);
3939

@@ -44,7 +44,7 @@ async function isServerAvailable(): Promise<boolean> {
4444
}
4545
}
4646

47-
class ServerSideStorage implements commonStorage.Storage {
47+
export class ServerSideStorage implements commonStorage.Storage {
4848

4949
async saveEntry(entryKey: string, entryValue: string): Promise<void> {
5050
const response = await fetch(`${API_BASE_URL}/entries/${encodeURIComponent(entryKey)}`, {
@@ -86,27 +86,6 @@ class ServerSideStorage implements commonStorage.Storage {
8686
}
8787

8888
async rename(oldPath: string, newPath: string): Promise<void> {
89-
if (oldPath.endsWith('/')) {
90-
return this.renameDirectory(oldPath, newPath);
91-
}
92-
return this.renameFile(oldPath, newPath);
93-
}
94-
95-
private async renameDirectory(oldPath: string, newPath: string): Promise<void> {
96-
const response = await fetch(`${API_BASE_URL}/storage/rename`, {
97-
method: 'POST',
98-
headers: {
99-
'Content-Type': 'application/json',
100-
},
101-
body: JSON.stringify({ old_path: oldPath, new_path: newPath }),
102-
});
103-
104-
if (!response.ok) {
105-
throw new Error(`Failed to rename directory: ${response.statusText}`);
106-
}
107-
}
108-
109-
private async renameFile(oldPath: string, newPath: string): Promise<void> {
11089
const response = await fetch(`${API_BASE_URL}/storage/rename`, {
11190
method: 'POST',
11291
headers: {
@@ -116,7 +95,7 @@ class ServerSideStorage implements commonStorage.Storage {
11695
});
11796

11897
if (!response.ok) {
119-
throw new Error(`Failed to rename file: ${response.statusText}`);
98+
throw new Error(`Failed to rename: ${response.statusText}`);
12099
}
121100
}
122101

@@ -149,34 +128,12 @@ class ServerSideStorage implements commonStorage.Storage {
149128
}
150129

151130
async delete(path: string): Promise<void> {
152-
if (path.endsWith('/')) {
153-
return this.deleteDirectory(path);
154-
}
155-
return this.deleteFile(path);
156-
}
157-
158-
private async deleteDirectory(path: string): Promise<void> {
159131
const response = await fetch(`${API_BASE_URL}/storage/${encodeURIComponent(path)}`, {
160132
method: 'DELETE',
161133
});
162134

163135
if (!response.ok) {
164-
throw new Error(`Failed to delete directory: ${response.statusText}`);
136+
throw new Error(`Failed to delete: ${response.statusText}`);
165137
}
166138
}
167-
168-
private async deleteFile(filePath: string): Promise<void> {
169-
const response = await fetch(`${API_BASE_URL}/storage/${encodeURIComponent(filePath)}`, {
170-
method: 'DELETE',
171-
});
172-
173-
if (!response.ok) {
174-
if (response.status === 404) {
175-
throw new Error(`File not found: ${filePath}`);
176-
}
177-
throw new Error(`Failed to delete file: ${response.statusText}`);
178-
}
179-
}
180-
}
181-
182-
export { ServerSideStorage, isServerAvailable };
139+
}

0 commit comments

Comments
 (0)