mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first attempt of saving data
This commit is contained in:
parent
1b878089d4
commit
eae42e9b5a
|
@ -43,6 +43,7 @@
|
||||||
"electron-updater": "^6.1.4",
|
"electron-updater": "^6.1.4",
|
||||||
"emoji-picker-element": "^1.18.3",
|
"emoji-picker-element": "^1.18.3",
|
||||||
"emoji-picker-element-data": "^1.4.0",
|
"emoji-picker-element-data": "^1.4.0",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"mime": "^3.0.0",
|
"mime": "^3.0.0",
|
||||||
"pinia": "^2.1.6",
|
"pinia": "^2.1.6",
|
||||||
"pouchdb": "^8.0.1",
|
"pouchdb": "^8.0.1",
|
||||||
|
|
|
@ -33,6 +33,13 @@
|
||||||
<i class="bi bi-info-circle"></i>
|
<i class="bi bi-info-circle"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="getFileContent['filesize'] !== 0"
|
||||||
|
class="btn btn-outline-secondary border-0 me-1"
|
||||||
|
@click="downloadAttachment"
|
||||||
|
>
|
||||||
|
<i class="bi bi-download"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
|
@ -42,11 +49,42 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { deleteMessageFromDB, requestMessageInfo } from "../js/chatHandler";
|
import { deleteMessageFromDB, requestMessageInfo, getMessageAttachment } from "../js/chatHandler";
|
||||||
|
import {atob_FD} from "../js/freedata.js"
|
||||||
|
|
||||||
|
// pinia store setup
|
||||||
|
import { setActivePinia } from "pinia";
|
||||||
|
import pinia from "../store/index";
|
||||||
|
setActivePinia(pinia);
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
|
import { useChatStore } from "../store/chatStore.js";
|
||||||
|
const chat = useChatStore(pinia);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
message: Object,
|
message: Object,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
async downloadAttachment() {
|
||||||
|
try {
|
||||||
|
// reset file store
|
||||||
|
chat.downloadFileFromDB = [];
|
||||||
|
|
||||||
|
const attachment = await getMessageAttachment(this.message._id);
|
||||||
|
const blob = new Blob([atob_FD(attachment[2])], { type: `${attachment[1]};charset=utf-8` });
|
||||||
|
window.focus();
|
||||||
|
saveAs(blob, attachment[0]);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to download attachment:", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getFileContent() {
|
getFileContent() {
|
||||||
|
|
|
@ -2,6 +2,17 @@
|
||||||
<div class="row justify-content-end mb-2">
|
<div class="row justify-content-end mb-2">
|
||||||
<!-- control area -->
|
<!-- control area -->
|
||||||
<div class="col-auto p-0 m-0">
|
<div class="col-auto p-0 m-0">
|
||||||
|
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="getFileContent['filesize'] !== 0"
|
||||||
|
class="btn btn-outline-secondary border-0 me-1"
|
||||||
|
@click="downloadAttachment"
|
||||||
|
>
|
||||||
|
<i class="bi bi-download"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="btn btn-outline-secondary border-0 me-1"
|
class="btn btn-outline-secondary border-0 me-1"
|
||||||
@click="repeatMessage"
|
@click="repeatMessage"
|
||||||
|
@ -75,20 +86,50 @@
|
||||||
|
|
||||||
import { Modal } from "bootstrap";
|
import { Modal } from "bootstrap";
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
|
import {atob_FD} from "../js/freedata.js"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
repeatMessageTransmission,
|
repeatMessageTransmission,
|
||||||
deleteMessageFromDB,
|
deleteMessageFromDB,
|
||||||
requestMessageInfo,
|
requestMessageInfo,
|
||||||
|
getMessageAttachment,
|
||||||
} from "../js/chatHandler";
|
} from "../js/chatHandler";
|
||||||
|
|
||||||
|
|
||||||
|
// pinia store setup
|
||||||
|
import { setActivePinia } from "pinia";
|
||||||
|
import pinia from "../store/index";
|
||||||
|
setActivePinia(pinia);
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
|
import { useChatStore } from "../store/chatStore.js";
|
||||||
|
const chat = useChatStore(pinia);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
message: Object,
|
message: Object,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
async downloadAttachment() {
|
||||||
|
try {
|
||||||
|
// reset file store
|
||||||
|
chat.downloadFileFromDB = [];
|
||||||
|
|
||||||
|
const attachment = await getMessageAttachment(this.message._id);
|
||||||
|
const blob = new Blob([atob_FD(attachment[2])], { type: `${attachment[1]};charset=utf-8` });
|
||||||
|
saveAs(blob, attachment[0]);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to download attachment:", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getFileContent() {
|
getFileContent() {
|
||||||
var filename = Object.keys(this.message._attachments)[0];
|
var filename = Object.keys(this.message._attachments)[0];
|
||||||
|
@ -120,6 +161,10 @@ export default {
|
||||||
repeatMessage() {
|
repeatMessage() {
|
||||||
repeatMessageTransmission(this.message._id);
|
repeatMessageTransmission(this.message._id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deleteMessage() {
|
deleteMessage() {
|
||||||
deleteMessageFromDB(this.message._id);
|
deleteMessageFromDB(this.message._id);
|
||||||
},
|
},
|
||||||
|
|
|
@ -238,6 +238,35 @@ function sortChatList() {
|
||||||
return reorderedData;
|
return reorderedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function getMessageAttachment(id) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const findResult = await db.find({
|
||||||
|
selector: {
|
||||||
|
_id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const getResult = await db.get(findResult.docs[0]._id, {
|
||||||
|
attachments: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
let obj = getResult;
|
||||||
|
let filename = Object.keys(obj._attachments)[0];
|
||||||
|
let filetype = obj._attachments[filename].content_type;
|
||||||
|
let file = obj._attachments[filename].data;
|
||||||
|
resolve([filename, filetype, file]);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
reject(false); // Reject the Promise if there's an error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//repeat a message
|
//repeat a message
|
||||||
export function repeatMessageTransmission(id) {
|
export function repeatMessageTransmission(id) {
|
||||||
// 1. get message object by ID
|
// 1. get message object by ID
|
||||||
|
|
|
@ -62,6 +62,8 @@ export const useChatStore = defineStore("chatStore", () => {
|
||||||
var beaconDataArray = ref([]);
|
var beaconDataArray = ref([]);
|
||||||
var beaconLabelArray = ref([]);
|
var beaconLabelArray = ref([]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedCallsign,
|
selectedCallsign,
|
||||||
selectedMessageObject,
|
selectedMessageObject,
|
||||||
|
@ -81,6 +83,5 @@ export const useChatStore = defineStore("chatStore", () => {
|
||||||
beaconLabelArray,
|
beaconLabelArray,
|
||||||
unsorted_beacon_list,
|
unsorted_beacon_list,
|
||||||
sorted_beacon_list,
|
sorted_beacon_list,
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue