Skip to content

Commit cd8b543

Browse files
committed
Add correct default error value to not found and file data
1 parent 5a2846a commit cd8b543

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/lib/components/chat/DownloadFile.svelte

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import AudioPlayer from "./AudioPlayer.svelte"
2929
3030
3131
onMount(async () => {
32-
await loadFile(file)
32+
if (!await loadFile(file))
3333
})
3434
3535
$: {
@@ -76,13 +76,24 @@ import AudioPlayer from "./AudioPlayer.svelte"
7676
} else {
7777
load = await window.api.loadFile(file.path, file.size)
7878
}
79-
if (load[0] === OTHER || load[0] === NOT_FOUND) return false
8079
const [arr, type] = load
80+
if (!found(arr)) return
8181
let blob = new Blob( [ arr ]);
8282
data = URL.createObjectURL( blob );
83-
console.log("Load ", data)
8483
checkType(type)
8584
}
85+
86+
const found = (file) => {
87+
switch (file) {
88+
case OTHER:
89+
data = OTHER
90+
return false
91+
case NOT_FOUND:
92+
data = NOT_FOUND
93+
return false
94+
}
95+
return true
96+
}
8697
8798
const downloadFile = (file) => {
8899
clicked = true

src/lib/components/chat/UploadFile.svelte

+14-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,27 @@ import AudioPlayer from "./AudioPlayer.svelte"
5151
5252
async function loadFile(file) {
5353
let [arr, type] = await window.api.loadFile(file.path, file.size)
54-
if (arr === OTHER || arr === NOT_FOUND) return false
54+
if (!found(arr)) return
5555
let blob = new Blob( [ arr ]);
56-
console.log("type", type)
5756
checkType(type)
5857
data = URL.createObjectURL( blob );
5958
if (audio) data = new Audio(data);
6059
return type
6160
}
6261
62+
63+
const found = (file) => {
64+
switch (file) {
65+
case OTHER:
66+
data = OTHER
67+
return false
68+
case NOT_FOUND:
69+
data = NOT_FOUND
70+
return false
71+
}
72+
return true
73+
}
74+
6375
6476
</script>
6577

0 commit comments

Comments
 (0)