Skip to content

Commit

Permalink
fix: Fix file type judgement problems
Browse files Browse the repository at this point in the history
  • Loading branch information
WCY-dt committed Jun 23, 2024
1 parent 5a8f7b2 commit c46e75e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions client/components/Download.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export default {
watch: {
isConnectSuccess(newValue) {
if (newValue) {
this.receiveFileUtil.receiveFiles(this.connectCore, this.addDownloadFileItem, this.updateFileProgress, this.updateFileUrl, this.updateFileSuccess)
this.receiveUtil.receiveFiles(this.connectCore, this.addDownloadFileItem, this.updateFileProgress, this.updateFileUrl, this.updateFileSuccess)
}
}
},

setup() {
const dataStore = useDataStore()

const { connectCore, receiveFileUtil, isConnectSuccess } = storeToRefs(dataStore)
const { connectCore, receiveUtil, isConnectSuccess } = storeToRefs(dataStore)

return {
dataStore,
connectCore,
receiveFileUtil,
receiveUtil,
isConnectSuccess,
}
},
Expand Down
9 changes: 4 additions & 5 deletions client/components/DownloadItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
},
type: {
type: String,
default: "file"
default: "TRANSFER_TYPE_FILE"
},
success: {
type: Boolean,
Expand All @@ -43,19 +43,18 @@ export default {
},

template: /*html*/`
<a v-if="type==='file' || type==='photo'" ref="downloadLink" :href="url" class="downloadFileItem file" :download="name" :class="{ success: success, loading: !success }">
<a v-if="type==='TRANSFER_TYPE_FILE' || type==='TRANSFER_TYPE_PHOTO'" ref="downloadLink" :href="url" class="downloadFileItem file" :download="name" :class="{ success: success, loading: !success }">
<div id="downloadDisplay">
<p id="downloadName">{{ name }}</p>
<progress id="downloadProgress" :value="progress" :max="size"></progress>
<img v-if="type==='photo'"
<img v-if="type==='TRANSFER_TYPE_PHOTO' && success"
id="downloadContent"
:src="url"
alt="Photo"
v-if="success"
/>
</div>
</a>
<div v-if="type==='text'" class="downloadFileItem text" :class="{ success: success, loading: !success }" @click="onTextClick">
<div v-if="type==='TRANSFER_TYPE_TEXT'" class="downloadFileItem text" :class="{ success: success, loading: !success }" @click="onTextClick">
<div id="downloadDisplay">
<p id="downloadContent">{{ name }}</p>
<div class="cover">
Expand Down
4 changes: 2 additions & 2 deletions client/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {

methods: {
async sendFiles() { // Send the file meta and content
this.sendFileUtil.sendFiles(this.$refs.fileInput.files, 'file', this.sendCore)
this.sendFileUtil.sendFiles(this.$refs.fileInput.files, 'TRANSFER_TYPE_FILE', this.sendCore)
},

onFileDrop(event) { // Handle file drop event
Expand Down Expand Up @@ -77,7 +77,7 @@ export default {
);
console.log(file);

await this.sendFileUtil.sendFiles([file], 'photo', this.sendCore);
await this.sendFileUtil.sendFiles([file], 'TRANSFER_TYPE_PHOTO', this.sendCore);
}.bind(this), 'image/png');
},

Expand Down
6 changes: 3 additions & 3 deletions client/dataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import ConnectCore from './e2e/connectCore.js'
import SendCore from './e2e/sendCore.js'
import SendFileUtil from './e2e/sendFileUtil.js'
import SendTextUtil from './e2e/sendTextUtil.js'
import ReceiveFileUtil from './e2e/receiveFileUtil.js'
import ReceiveUtil from './e2e/receiveUtil.js'

export const useDataStore = defineStore('data', {
state: () => ({
connectCore: ref(null),
sendCore: ref(null),
sendFileUtil: ref(null),
sendTextUtil: ref(null),
receiveFileUtil: ref(null),
receiveUtil: ref(null),

clientId: ref('LOADING'),

Expand All @@ -32,7 +32,7 @@ export const useDataStore = defineStore('data', {
)
this.sendFileUtil = new SendFileUtil()
this.sendTextUtil = new SendTextUtil()
this.receiveFileUtil = new ReceiveFileUtil()
this.receiveUtil = new ReceiveUtil()
},

setClientId(id) { // Set the client ID
Expand Down
12 changes: 6 additions & 6 deletions client/e2e/receiveFileUtil.js → client/e2e/receiveUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ReceiveFileUtil {
class ReceiveUtil {
constructor() {
this.addDownloadFileItem = null;
this.updateFileProgress = null;
Expand Down Expand Up @@ -67,9 +67,9 @@ class ReceiveFileUtil {
console.log(`[INFO] Received size: ${data}`)
this.fileSizeQueue.push(parseInt(data))
} else {
if (data === 'file'
|| data === 'text'
|| data === 'photo'
if (data === 'TRANSFER_TYPE_FILE'
|| data === 'TRANSFER_TYPE_TEXT'
|| data === 'TRANSFER_TYPE_PHOTO'
) {
console.log(`[INFO] Received type: ${data}`)
this.fileTypeQueue.push(data)
Expand All @@ -92,7 +92,7 @@ class ReceiveFileUtil {
this.fileTypeQueue[this.fileTypeQueue.length - 1]
)

if (this.fileTypeQueue[this.fileTypeQueue.length - 1] === 'text') {
if (this.fileTypeQueue[this.fileTypeQueue.length - 1] === 'TRANSFER_TYPE_TEXT') {
this.fileTypeQueue.shift()
this.fileNameQueue.shift()
this.fileSizeQueue.shift()
Expand Down Expand Up @@ -141,4 +141,4 @@ class ReceiveFileUtil {
}
}

export default ReceiveFileUtil;
export default ReceiveUtil;
4 changes: 2 additions & 2 deletions client/e2e/sendTextUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class SendTextUtil {
async sendTextContent(text) { // Send the type, name, and size of the file
if (!this.checkSendAvailability(text)) return

await this.sendCore.sendData('text')
await this.sendCore.sendData('TRANSFER_TYPE_TEXT')
await this.sendCore.sendData(text)
await this.sendCore.sendData(text.length)

console.log(`[INFO] Sent content: ${'text'} | ${text} | ${text.length}`)
console.log(`[INFO] Sent content: ${'TRANSFER_TYPE_FILE'} | ${text} | ${text.length}`)
}

checkSendAvailability(text) { // Check if the text is empty or the data channel is open
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "file-transfer-server",
"version": "1.4.1",
"version": "1.4.2",
"description": "Server for file transfer",
"main": "server/server.js",
"scripts": {
Expand Down

0 comments on commit c46e75e

Please sign in to comment.