Skip to content

Commit

Permalink
private/group chat with file
Browse files Browse the repository at this point in the history
  • Loading branch information
oxogenesis authored Mar 2, 2020
1 parent a548607 commit a011926
Show file tree
Hide file tree
Showing 8 changed files with 1,302 additions and 408 deletions.
9 changes: 5 additions & 4 deletions src/components/section/Bulletin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
SHA1:{{bulletin.file.SHA1}}<br>
<h5 v-show="bulletin.file_saved" class="bulletin-quote-link" @click="openFile(bulletin.file.SHA1)">[打开]</h5>
<h5 v-show="bulletin.file_saved" class="bulletin-quote-link" @click="openDir(bulletin.file.SHA1)">[打开文件夹]</h5>
<h5 v-show="!bulletin.file_saved" class="bulletin-quote-link" @click="fetchFile(bulletin.file, bulletin.relay1_address)">[获取]</h5>
<h5 v-show="!bulletin.file_saved" class="bulletin-quote-link">{{bulletin.file_percent}}</h5>
<h5 v-show="!bulletin.file_saved" class="bulletin-quote-link" @click="fetchFile(bulletin.file, bulletin.relay_address)">[获取]</h5>
</div>
<div v-else class="bulletin-text" v-html="bulletin.content"></div>
</li>
Expand Down Expand Up @@ -77,11 +78,11 @@ export default {
}
});
},
fetchFile(file, relay1_address) {
fetchFile(file, relay_address) {
this.$store.commit({
type: 'FetchFile',
type: 'FetchBulletinFile',
file: file,
relay1_address: relay1_address
relay_address: relay_address
})
},
...mapActions({
Expand Down
23 changes: 10 additions & 13 deletions src/components/section/BulletinSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<el-input type="textarea" class="bulletin-composer" v-model="content"></el-input>
</el-form-item>
<el-form-item align="right">
<el-button size="mini" type="primary" @click="publishBulletin()">发布</el-button>
<el-button size="mini" type="primary" @click="publishBulletinFile()">发布文件</el-button>
<el-button size="mini" type="primary" @click="publishTextBulletin()">发布</el-button>
<el-button size="mini" type="primary" @click="publishFileBulletin()">发布文件</el-button>
</el-form-item>
</el-form>
</div>
Expand Down Expand Up @@ -68,7 +68,7 @@ export default {
},
created() {},
methods: {
publishBulletin() {
publishTextBulletin() {
if (this.content.trim() == "") {
this.$message({
showClose: true,
Expand All @@ -80,7 +80,7 @@ export default {
this.content = this.content.replace(/\r/ig, "").replace(/\n/ig, "<br>");
this.$store.dispatch({
type: 'PublishBulletin',
type: 'PublishTextBulletin',
content: this.content
})
this.content = ''
Expand All @@ -104,30 +104,30 @@ export default {
changeShowEdit: function(onoff) {
this.showEdit = onoff;
},
publishBulletinFile() {
publishFileBulletin() {
let self = this
dialog.showOpenDialog({
title: "浏览文件"
}, filename => {
try {
let stats = fs.statSync(filename[0])
console.log(stats)
//console.log(stats)
if (stats.isFile() && stats.size > 0) {
let fileToPublish = filename[0]
console.log(fileToPublish)
//console.log(fileToPublish)
let stats = fs.statSync(fileToPublish)
if (stats.isFile() && stats.size > 0) {
let pathJson = path.parse(fileToPublish)
if (pathJson["ext"] == '.exe') {
self.$message({
showClose: true,
message: '不是发布可执行文件',
message: '不能发布可执行文件',
type: 'warning'
})
} else {
self.$store.dispatch({
type: 'PublishBulletinFile',
type: 'PublishFileBulletin',
fileToPublish: fileToPublish,
pathJson: pathJson,
size: stats.size
Expand All @@ -145,10 +145,7 @@ export default {
console.log(e)
}
})
},
...mapActions({
switchBBSession: 'SwitchBBSession'
})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/section/FooterSection.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="inner-footer">
<footer>
<p>版本 0.0.7</p>
<p>版本 0.0.8</p>
<p>@copyright 2019-2020</p>
</footer>
</div>
Expand Down
76 changes: 56 additions & 20 deletions src/components/section/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,32 @@
</div>
</div>
<div class="message-textWrapper">
<div :class="[{'message-confirm':message.confirmed}, 'message-text']">{{message.content}}</div>
<div v-if="message.is_file" class="[{'message-confirm':message.confirmed}, 'message-text']">
Name:{{message.file.Name}}{{message.file.Ext}}<br>
Size:{{message.file.Size}}<br>
Chunk:{{message.file.Chunk}}<br>
SHA1:{{message.file.SHA1}}<br>
<h5 v-show="message.file_saved" class="message-quote-link" @click="openFile(message.file.SHA1)">[打开]</h5>
<h5 v-show="message.file_saved" class="message-quote-link" @click="openDir(message.file.SHA1)">[打开文件夹]</h5>
<h5 v-show="!message.file_saved" class="message-quote-link">{{message.file_percent}}</h5>
<h5 v-show="!message.file_saved" class="message-quote-link" @click="fetchFile(message.is_private, message.address, message.file)">[获取]</h5>
</div>
<div v-else class="[{'message-confirm':message.confirmed}, 'message-text']" v-html="message.content"></div>
</div>
</li>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
const shell = window.require('electron').shell
const fs = window.require("fs")
const path = window.require("path")
export default {
name: 'Message',
data: function() {
return {
myAddress: this.$store.state.OXO.Address
address: this.$store.state.OXO.Address
}
},
props: {
Expand All @@ -39,27 +49,53 @@ export default {
getNameByAddress: 'getNameByAddress'
}),
myline: function() {
return this.myAddress == this.message.address ? 'myline' : '';
return this.address == this.message.address ? 'myline' : '';
},
toolTipDir: function() {
return this.myAddress == this.message.address ? 'left' : 'right';
return this.address == this.message.address ? 'left' : 'right';
}
},
mounted() {
/*
//what the fuck!
console.log(`mounted#${this.message.sequence}#${this.message.content}`)
let content = this.message.content
if (content.length > 22 && content.substring(0, 22) == 'data:image/png;base64,') {
let newImg = document.createElement("img")
newImg.src = content
newImg.width = 447
this.$refs.content.appendChild(newImg)
} else {
content = content.replace(/\r/ig, "").replace(/\n/ig, "<br>");
this.$refs.content.innerHTML = content;
},
methods: {
openFile() {
let sha1 = this.message.file.SHA1
let tmpFile = `./data/tmp/${sha1}${this.message.file.Ext}`
fs.copyFile(`./data/${this.address}/${sha1.substr(0,3)}/${sha1.substr(3,3)}/${sha1}`, tmpFile, (err) => {
if (err) {
throw err
} else {
shell.openItem(path.resolve(tmpFile))
}
})
},
openDir() {
let sha1 = this.message.file.SHA1
let tmpFile = `./data/tmp/${sha1}${this.message.file.Ext}`
fs.copyFile(`./data/${this.address}/${sha1.substr(0,3)}/${sha1.substr(3,3)}/${sha1}`, tmpFile, (err) => {
if (err) {
throw err
} else {
shell.showItemInFolder(path.resolve(tmpFile))
}
})
},
fetchFile(is_private, address, file) {
if (is_private) {
this.$store.commit({
type: 'FetchPrivateFile',
file: file,
address: address
})
} else {
this.$store.commit({
type: 'FetchGroupFile',
file: file,
address: address
})
}
}
*/
}
}
Expand Down
Loading

0 comments on commit a011926

Please sign in to comment.