Skip to content

Commit a3cc702

Browse files
committed
fix: improve file transfer performance
1 parent 4fb409b commit a3cc702

11 files changed

Lines changed: 239 additions & 69 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173
"$updater_asset" \
174174
"$updater_asset.sig" \
175175
"release-assets/${{ matrix.latest_name }}" \
176-
"主要解决移动端问题"
176+
"解决下载速度问题"
177177
178178
- name: Prepare Windows updater metadata
179179
if: runner.os == 'Windows'
@@ -188,7 +188,7 @@ jobs:
188188
"$updater_asset" \
189189
"$updater_asset.sig" \
190190
"release-assets/${{ matrix.latest_name }}" \
191-
"主要解决移动端问题"
191+
"解决下载速度问题"
192192
193193
- name: Upload workflow artifact
194194
uses: actions/upload-artifact@v4
@@ -203,5 +203,5 @@ jobs:
203203
with:
204204
files: ${{ matrix.release_artifact_path || matrix.artifact_path }}
205205
body: |
206-
主要解决移动端问题
206+
解决下载速度问题
207207
prerelease: ${{ contains(github.ref_name, 'rc') }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ src-tauri/data/items.json
99
.updater/
1010

1111
.claude/
12+
.playwright-mcp/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fileshare",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"private": true,
55
"type": "module",
66
"scripts": {

public/app.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
function getDownloadUrl(item) {
4242
const path = `/api/items/${item.id}/download`;
43-
if (state.role === 'admin' && state.shareInfo?.url) {
44-
return state.shareInfo.url.replace(/\/client\.html$/, path);
43+
if (state.shareInfo?.url) {
44+
return new URL(path, new URL(state.shareInfo.url).origin).toString();
4545
}
4646
return new URL(path, window.location.origin).toString();
4747
}
@@ -563,38 +563,54 @@
563563
const pickAdminFilesButton = $('pickAdminFilesButton');
564564
const adminDropZones = Array.from(document.querySelectorAll('.admin-file-drop'));
565565
if (fileForm && fileInput) {
566-
const updateFileHint = () => {
566+
let uploadingFiles = false;
567+
568+
const updateFileHint = (message) => {
569+
if (!fileHint) return;
570+
if (message) {
571+
fileHint.textContent = message;
572+
return;
573+
}
567574
const count = fileInput.files.length;
568-
fileHint.textContent = count ? `已选择 ${count} 个文件,上传中会自动开始` : '支持多文件上传';
575+
fileHint.textContent = count ? `已选择 ${count} 个文件,正在准备上传` : '选择后自动上传';
569576
};
570577

571578
const uploadSelectedFiles = async () => {
572-
if (!fileInput.files.length) return;
573-
updateFileHint();
579+
if (!fileInput.files.length || uploadingFiles) return;
580+
const files = Array.from(fileInput.files);
581+
uploadingFiles = true;
582+
updateFileHint(`正在上传 ${files.length} 个文件,请保持页面打开`);
574583
if (dropZone) {
575584
dropZone.classList.add('uploading');
576585
}
577-
const data = new FormData();
578-
data.append('source', state.role);
579-
for (const file of Array.from(fileInput.files)) {
580-
data.append('file', file, file.name);
581-
}
582-
await request('/api/upload', { method: 'POST', body: data });
583-
fileForm.reset();
584-
updateFileHint();
585-
if (dropZone) {
586-
dropZone.classList.remove('uploading');
586+
try {
587+
const data = new FormData();
588+
data.append('source', state.role);
589+
for (const file of files) {
590+
data.append('file', file, file.name);
591+
}
592+
await request('/api/upload', { method: 'POST', body: data });
593+
fileForm.reset();
594+
updateFileHint('上传完成');
595+
window.setTimeout(() => updateFileHint(), 900);
596+
fileForm.closest('dialog')?.close();
597+
} finally {
598+
uploadingFiles = false;
599+
if (dropZone) {
600+
dropZone.classList.remove('uploading');
601+
}
587602
}
588-
fileForm.closest('dialog')?.close();
589603
};
590604

591605
fileInput.addEventListener('change', () => {
592606
if (!fileInput.files.length) return;
593607
updateFileHint();
594608
uploadSelectedFiles().catch((error) => {
609+
uploadingFiles = false;
595610
if (dropZone) {
596611
dropZone.classList.remove('uploading');
597612
}
613+
updateFileHint('上传失败,请重新选择');
598614
alert(error.message);
599615
});
600616
});

public/client.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2>上传文件</h2>
6666
<input id="fileInput" name="file" type="file" multiple>
6767
<span class="upload-icon"></span>
6868
<strong>点击选择文件,选完自动上传</strong>
69-
<small id="fileHint">支持多文件上传</small>
69+
<small id="fileHint">选择后自动上传</small>
7070
</label>
7171
</form>
7272
</div>

public/styles.css

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ body {
9999
margin: 0;
100100
min-height: 100vh;
101101
overflow-x: hidden;
102+
overflow-y: auto;
102103
color: var(--text);
103104
background: var(--bg);
104105
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
@@ -250,9 +251,11 @@ h2 {
250251

251252
.client-share {
252253
display: grid;
253-
grid-template-columns: 76px minmax(180px, 280px);
254+
grid-template-columns: 76px minmax(0, 280px);
254255
gap: 10px;
255256
align-items: center;
257+
max-width: 100%;
258+
min-width: 0;
256259
}
257260

258261
.client-qr-button {
@@ -298,6 +301,7 @@ h2 {
298301
.client-link-box {
299302
display: grid;
300303
gap: 8px;
304+
min-width: 0;
301305
}
302306

303307
.client-link-box span {
@@ -319,9 +323,11 @@ h2 {
319323
gap: 18px;
320324
width: min(980px, calc(100% - 32px));
321325
margin: 22px auto;
326+
min-width: 0;
322327
}
323328

324329
.panel {
330+
min-width: 0;
325331
background: var(--panel);
326332
border: 1px solid var(--line);
327333
border-radius: 8px;
@@ -893,6 +899,7 @@ pre {
893899
}
894900

895901
.upload-drop {
902+
position: relative;
896903
display: grid;
897904
place-items: center;
898905
gap: 8px;
@@ -902,6 +909,9 @@ pre {
902909
background: var(--surface-soft);
903910
color: var(--text-soft);
904911
cursor: pointer;
912+
overflow: hidden;
913+
touch-action: manipulation;
914+
-webkit-tap-highlight-color: transparent;
905915
transition: border-color .16s ease, background .16s ease;
906916
text-align: center;
907917
}
@@ -944,7 +954,13 @@ pre {
944954
}
945955

946956
.upload-drop input {
947-
display: none;
957+
position: absolute;
958+
inset: 0;
959+
z-index: 2;
960+
width: 100%;
961+
height: 100%;
962+
cursor: pointer;
963+
opacity: 0;
948964
}
949965

950966
.upload-icon {
@@ -966,8 +982,11 @@ pre {
966982

967983
@media (max-width: 760px) {
968984
body {
985+
width: 100%;
986+
overflow-x: hidden;
969987
overflow-y: auto;
970988
-webkit-overflow-scrolling: touch;
989+
overscroll-behavior-x: none;
971990
}
972991

973992
.layout {
@@ -980,11 +999,13 @@ pre {
980999
align-items: flex-start;
9811000
flex-direction: column;
9821001
padding: 14px 16px;
1002+
gap: 12px;
9831003
}
9841004

9851005
.top-actions {
9861006
width: 100%;
9871007
justify-content: flex-start;
1008+
min-width: 0;
9881009
}
9891010

9901011
.client-share {
@@ -1017,11 +1038,13 @@ pre {
10171038
.modal,
10181039
.qr-modal {
10191040
width: calc(100% - 20px);
1041+
max-width: calc(100% - 20px);
10201042
}
10211043

10221044
.list-actions {
1023-
width: auto;
1045+
width: 100%;
10241046
justify-content: flex-start;
1047+
flex-wrap: wrap;
10251048
}
10261049

10271050
.item {
@@ -1030,6 +1053,7 @@ pre {
10301053

10311054
.actions {
10321055
justify-content: flex-start;
1056+
flex-wrap: wrap;
10331057
}
10341058

10351059
.items {

src-tauri/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fileshare"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
description = "LAN file sharing desktop app"
55
authors = ["FileShare"]
66
edition = "2021"
@@ -23,6 +23,7 @@ serde_json = "1"
2323
tauri = { version = "2", features = ["image-png", "tray-icon"] }
2424
tauri-plugin-updater = "2"
2525
tokio = { version = "1", features = ["fs", "macros", "net", "rt-multi-thread", "sync"] }
26+
tokio-util = { version = "0.7", features = ["io"] }
2627
tower-http = { version = "0.5", features = ["cors"] }
2728
urlencoding = "2"
2829
uuid = { version = "1", features = ["v4"] }

0 commit comments

Comments
 (0)