Skip to content

Commit fce51de

Browse files
committed
fix: change vue to MPA mode and primarily add upload logic in web page
1 parent b09d6c9 commit fce51de

File tree

18 files changed

+805
-33
lines changed

18 files changed

+805
-33
lines changed

server/src/db.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{sync::Arc, u32};
1+
use std::{sync::Arc};
22
use crate::utils::memdb::MemDB;
33

44
use axum::body::Bytes;
@@ -27,7 +27,6 @@ impl AccessCode {
2727
#[derive(Clone)]
2828
pub struct FileBlock {
2929
pub data: Bytes,
30-
pub size: u64,
3130
pub is_final: bool,
3231
pub filename: String,
3332
pub start: u64,
@@ -40,10 +39,9 @@ impl FileBlock {
4039
FILE_BLOCK_DB.clone()
4140
}
4241

43-
pub fn new(data: &Bytes, size: u64, is_final: bool, filename: String, start: u64, end: u64, total: u64) -> Self {
42+
pub fn new(data: &Bytes, is_final: bool, filename: String, start: u64, end: u64, total: u64) -> Self {
4443
FileBlock {
4544
data: data.clone(),
46-
size,
4745
is_final,
4846
filename,
4947
start,

server/src/router.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ use axum::{routing::{get, post}, serve, Router};
22
use tokio::net::{TcpListener};
33
use tracing::{event, instrument};
44

5-
use crate::service::handler::{get_file, get_id, get_status, root, upload_file};
5+
use crate::service::handler::{download, get_file, get_id, get_status, upload, upload_file};
66

77
fn api_router() -> Router {
88
Router::new()
9+
.route("/hello", get(|| async { "Hi!" }))
910
.route("/get_id", get(get_id))
1011
.route("/{id}/status", get(get_status))
1112
.route("/{id}/upload", post(upload_file))
13+
.route("/{id}/file", get(get_file))
1214
}
1315

1416
fn view_router() -> Router {
1517
Router::new()
16-
.route("/", get(root))
17-
.route("/{id}/file", get(get_file))
18+
.route("/", get(upload))
19+
.route("/{id}/file", get(download))
1820
}
1921

2022
#[instrument(skip_all)]

server/src/service/handler.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ struct FileInfo {
2929
}
3030

3131
#[instrument]
32-
pub async fn root() -> impl IntoResponse {
33-
match StaticFiles::get("index.html") {
32+
pub async fn upload() -> impl IntoResponse {
33+
match StaticFiles::get("./src/pages/upload/index.html") {
34+
Some(content) => {
35+
let html = String::from_utf8(content.data.to_vec()).unwrap();
36+
Html(html).into_response()
37+
}
38+
None => (StatusCode::NOT_FOUND, "Page not found").into_response(),
39+
}
40+
}
41+
42+
pub async fn download() -> impl IntoResponse {
43+
match StaticFiles::get("./src/pages/download/index.html") {
3444
Some(content) => {
3545
let html = String::from_utf8(content.data.to_vec()).unwrap();
3646
Html(html).into_response()
@@ -144,8 +154,8 @@ pub async fn get_file(
144154

145155
// Get file size and filename
146156
let file_block_db = FileBlock::get_db();
147-
let mut total_size = 0u64;
148-
let mut filename = String::new();
157+
let total_size: u64 ;
158+
let filename: String;
149159

150160
// Calculate file size and get filename
151161
let mut retry = 0;
@@ -470,7 +480,6 @@ pub async fn upload_file(Path(id): Path<String>, multipart: Multipart) -> impl I
470480
}
471481
let file_block = FileBlock::new(
472482
&data,
473-
data.len() as u64,
474483
is_final > 0,
475484
filename,
476485
start,

web/components.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable */
2+
// @ts-nocheck
3+
// Generated by unplugin-vue-components
4+
// Read more: https://github.com/vuejs/core/pull/3399
5+
// biome-ignore lint: disable
6+
export {}
7+
8+
/* prettier-ignore */
9+
declare module 'vue' {
10+
export interface GlobalComponents {
11+
AButton: typeof import('ant-design-vue/es')['Button']
12+
AProgress: typeof import('ant-design-vue/es')['Progress']
13+
AUpload: typeof import('ant-design-vue/es')['Upload']
14+
}
15+
}

web/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"format": "prettier --write src/"
1717
},
1818
"dependencies": {
19+
"@ant-design/icons-vue": "^7.0.1",
20+
"ant-design-vue": "~4.2.6",
21+
"lucide-vue-next": "^0.544.0",
1922
"vue": "^3.5.18"
2023
},
2124
"devDependencies": {
@@ -31,6 +34,7 @@
3134
"npm-run-all2": "^8.0.4",
3235
"prettier": "3.6.2",
3336
"typescript": "~5.8.0",
37+
"unplugin-vue-components": "^29.0.0",
3438
"vite": "^7.0.6",
3539
"vite-plugin-vue-devtools": "^8.0.0",
3640
"vue-tsc": "^3.0.4"

0 commit comments

Comments
 (0)