Skip to content

Commit

Permalink
Merge pull request #625 from Adamant-im/feat/download_and_upload_files
Browse files Browse the repository at this point in the history
Feat/download and upload files
  • Loading branch information
bludnic committed May 6, 2024
2 parents e4ce4b6 + 6c7f7d2 commit b29ebd2
Show file tree
Hide file tree
Showing 30 changed files with 573 additions and 54 deletions.
24 changes: 23 additions & 1 deletion src/components/AChat/AChatAttachment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
class="a-chat__message-text a-text-regular-enlarged"
v-text="formattedMessage"
/>
<v-btn @click="getFileFromStorage()">CLICK ME</v-btn>
<pre>
{{ JSON.stringify(transaction.id, null, 2) }}
</pre>
Expand All @@ -89,14 +90,15 @@ import { useFormatMessage } from './hooks/useFormatMessage'
import { usePartnerId } from './hooks/usePartnerId'
import { useTransactionTime } from './hooks/useTransactionTime'
import { NormalizedChatMessageTransaction } from '@/lib/chat/helpers'
import { isStringEqualCI } from '@/lib/textHelpers'
import { downloadFile, isStringEqualCI } from '@/lib/textHelpers'
import { tsIcon } from '@/lib/constants'
import QuotedMessage from './QuotedMessage.vue'
import { useSwipeLeft } from '@/hooks/useSwipeLeft'
import formatDate from '@/filters/date'
import { isWelcomeChat } from '@/lib/chat/meta/utils'
export default defineComponent({
methods: { downloadFile },
components: {
QuotedMessage
},
Expand Down Expand Up @@ -140,6 +142,25 @@ export default defineComponent({
const userId = computed(() => store.state.address)
const partnerId = usePartnerId(props.transaction)
const getFileFromStorage = async () => {
//TODO: refactor for each file
const cid = props.transaction.asset.files[0].file_id
const fileName = props.transaction.asset.files[0].file_name
const fileType = props.transaction.asset.files[0].file_type
const nonce = props.transaction.asset.files[0].nonce
const myAddress = store.state.address
const publicKey =
props.transaction.senderId === myAddress
? props.transaction.recipientPublicKey
: props.transaction.senderPublicKey
const data = await store.dispatch('attachment/getAttachment', { cid, publicKey, nonce })
if (!!data && !!fileName && !!fileType) {
// TODO: resolve MIME-type
downloadFile(data, fileName, '')
}
}
const showAvatar = computed(() => !isWelcomeChat(partnerId.value))
const statusIcon = computed(() => tsIcon(props.status.virtualStatus))
Expand All @@ -162,6 +183,7 @@ export default defineComponent({
statusIcon,
isOutgoingMessage,
formattedMessage,
getFileFromStorage,
showAvatar,
onMove,
onSwipeEnd,
Expand Down
15 changes: 11 additions & 4 deletions src/components/nodes/NodesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<v-tabs v-model="tab" bg-color="transparent">
<v-tab value="adm">{{ $t('nodes.tabs.adm_nodes') }}</v-tab>
<v-tab value="coins">{{ $t('nodes.tabs.coin_nodes') }}</v-tab>
<v-tab value="ipfs">{{ $t('nodes.tabs.ipfs_nodes') }}</v-tab>
</v-tabs>

<v-window v-model="tab">
Expand All @@ -13,9 +14,13 @@
<v-window-item value="coins">
<CoinNodesTable />
</v-window-item>

<v-window-item value="ipfs">
<IpfsNodesTable />
</v-window-item>
</v-window>
<div class="ml-6">
<div v-if="tab === 'coins'">
<div v-if="tab === 'coins' || tab === 'ipfs'">
<v-checkbox
v-model="preferFastestCoinNodeOption"
:label="$t('nodes.fastest_title')"
Expand Down Expand Up @@ -69,9 +74,10 @@

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { useStore } from 'vuex'
import { AdmNodesTable } from './adm'
import { CoinNodesTable } from './coins'
import { useStore } from 'vuex'
import { IpfsNodesTable } from './ipfs'
const className = 'nodes-table'
const classes = {
Expand All @@ -80,12 +86,13 @@ const classes = {
checkbox: `${className}__checkbox`
}
type Tab = 'adm' | 'coins'
type Tab = 'adm' | 'coins' | 'ipfs'
export default defineComponent({
components: {
AdmNodesTable,
CoinNodesTable
CoinNodesTable,
IpfsNodesTable
},
setup() {
const store = useStore()
Expand Down
48 changes: 48 additions & 0 deletions src/components/nodes/ipfs/IpfsNodesTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-label hide-socket />

<tbody>
<IpfsNodesTableItem v-for="node in ipfsNodes" :key="node.url" blockchain="adm" :node="node" />
</tbody>
</NodesTableContainer>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from 'vuex'
import NodesTableContainer from '@/components/nodes/components/NodesTableContainer.vue'
import NodesTableHead from '@/components/nodes/components/NodesTableHead.vue'
import IpfsNodesTableItem from './IpfsNodesTableItem.vue'
import { sortNodesFn } from '@/components/nodes/utils/sortNodesFn'
const className = 'adm-nodes-table'
const classes = {
root: className
}
export default defineComponent({
components: {
NodesTableContainer,
NodesTableHead,
IpfsNodesTableItem
},
setup() {
const store = useStore()
const ipfsNodes = computed(() => {
const arr = store.getters['nodes/ipfs']
return [...arr].sort(sortNodesFn)
})
return {
ipfsNodes,
classes
}
}
})
</script>

<style lang="scss">
@import 'vuetify/settings';
</style>
116 changes: 116 additions & 0 deletions src/components/nodes/ipfs/IpfsNodesTableItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<template>
<tr :class="classes.root">
<NodeColumn checkbox>
<NodeStatusCheckbox :value="active" @change="toggleActiveStatus" />
</NodeColumn>

<NodeColumn>
<NodeUrl :node="node" />
<NodeVersion v-if="node.version && active" :node="node" />
</NodeColumn>

<NodeColumn :colspan="!showSocketColumn ? 2 : 1">
<NodeStatus :node="node" />
</NodeColumn>
</tr>
</template>

<script lang="ts">
import { computed, PropType } from 'vue'
import { useStore } from 'vuex'
import type { NodeStatusResult } from '@/lib/nodes/abstract.node'
import NodeUrl from '@/components/nodes/components/NodeUrl.vue'
import NodeColumn from '@/components/nodes/components/NodeColumn.vue'
import NodeStatus from '@/components/nodes/components/NodeStatus.vue'
import NodeVersion from '@/components/nodes/components/NodeVersion.vue'
import NodeStatusCheckbox from '@/components/nodes/components/NodeStatusCheckbox.vue'
const className = 'adm-nodes-table-item'
const classes = {
root: className,
column: `${className}__column`,
columnCheckbox: `${className}__column--checkbox`,
checkbox: `${className}__checkbox`
}
export default {
components: {
NodeStatusCheckbox,
NodeColumn,
NodeStatus,
NodeVersion,
NodeUrl
},
props: {
node: {
type: Object as PropType<NodeStatusResult>,
required: true
}
},
setup(props) {
const store = useStore()
const url = computed(() => props.node.url)
const active = computed(() => props.node.active)
const socketSupport = computed(() => props.node.socketSupport)
const isUnsupported = computed(() => props.node.status === 'unsupported_version')
const type = computed(() => props.node.type)
const showSocketColumn = computed(() => active.value && !isUnsupported.value)
const toggleActiveStatus = () => {
store.dispatch('nodes/toggle', {
type: type.value,
url: url.value,
active: !active.value
})
store.dispatch('nodes/updateStatus')
}
const computedResult = computed(() => {
const baseUrl = new URL(url.value)
const protocol = baseUrl.protocol
const hostname = baseUrl.hostname
const port = baseUrl.port
const result = /^[\d.]+$/.test(hostname)
let nodeName = null
let domain = null
if (!result) {
const regex = /([^.]*)\.(.*)/
const parts = hostname.match(regex)
if (parts !== null) {
nodeName = parts[1]
domain = parts[2]
}
}
return {
protocol,
hostname,
nodeName,
domain,
result,
port
}
})
return {
classes,
url,
active,
socketSupport,
isUnsupported,
showSocketColumn,
toggleActiveStatus,
computedResult
}
}
}
</script>

<style lang="scss">
.ipfs-nodes-table-item {
line-height: 14px;
}
</style>
1 change: 1 addition & 0 deletions src/components/nodes/ipfs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as IpfsNodesTable } from './IpfsNodesTable.vue'
23 changes: 10 additions & 13 deletions src/config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,24 @@
},
"services": {
"list": {
"attachmentService": [
"infoService": [
{
"url": "https://info.adamant.im",
"alt_ip": "http://88.198.156.44:44099"
}
],
"ipfsService": [
{
"url": "https://ipfs1test.adamant.im",
"alt_ip": "http://194.163.154.252:4000",
"multi_address": "/ip4/194.163.154.252/tcp/4001/p2p/12D3KooWDFkrfLKMt46J5uh77SpNkxhxtSURqDnKY7Bnfr9etSQi"
"alt_ip": "http://194.163.154.252:4000"
},
{
"url": "https://ipfs2test.adamant.im",
"alt_ip": "http://154.26.159.245:4000",
"multi_address": "/ip4/154.26.159.245/tcp/4001/p2p/12D3KooWCkyBk2qneNhVJhhNoFat4foTQt877P28Q3VwFHcmYLw1"
"alt_ip": "http://154.26.159.245:4000"
},
{
"url": "https://ipfs3test.adamant.im",
"alt_ip": "http://109.123.240.102:4000",
"multi_address": "/ip4/109.123.240.102/tcp/4001/p2p/12D3KooWGmrZg4iEV8zX3CfiitGakNDKgrDjnphbZSkW2QPW1dbD"
}
],
"infoService": [
{
"url": "https://info.adamant.im",
"alt_ip": "http://88.198.156.44:44099"
"alt_ip": "http://109.123.240.102:4000"
}
]
},
Expand Down
23 changes: 10 additions & 13 deletions src/config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,24 @@
},
"services": {
"list": {
"attachmentService": [
"infoService": [
{
"url": "https://info.adamant.im",
"alt_ip": "http://88.198.156.44:44099"
}
],
"ipfsService": [
{
"url": "https://ipfs1test.adamant.im",
"alt_ip": "http://194.163.154.252:4000",
"multi_address": "/ip4/194.163.154.252/tcp/4001/p2p/12D3KooWDFkrfLKMt46J5uh77SpNkxhxtSURqDnKY7Bnfr9etSQi"
"alt_ip": "http://194.163.154.252:4000"
},
{
"url": "https://ipfs2test.adamant.im",
"alt_ip": "http://154.26.159.245:4000",
"multi_address": "/ip4/154.26.159.245/tcp/4001/p2p/12D3KooWCkyBk2qneNhVJhhNoFat4foTQt877P28Q3VwFHcmYLw1"
"alt_ip": "http://154.26.159.245:4000"
},
{
"url": "https://ipfs3test.adamant.im",
"alt_ip": "http://109.123.240.102:4000",
"multi_address": "/ip4/109.123.240.102/tcp/4001/p2p/12D3KooWGmrZg4iEV8zX3CfiitGakNDKgrDjnphbZSkW2QPW1dbD"
}
],
"infoService": [
{
"url": "https://info.adamant.im",
"alt_ip": "http://88.198.156.44:44099"
"alt_ip": "http://109.123.240.102:4000"
}
]
},
Expand Down
14 changes: 14 additions & 0 deletions src/config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
"url": "https://info.adamant.im",
"alt_ip": "http://88.198.156.44:44099"
}
],
"ipfsService": [
{
"url": "https://ipfs1test.adamant.im",
"alt_ip": "http://194.163.154.252:4000"
},
{
"url": "https://ipfs2test.adamant.im",
"alt_ip": "http://154.26.159.245:4000"
},
{
"url": "https://ipfs3test.adamant.im",
"alt_ip": "http://109.123.240.102:4000"
}
]
},
"healthCheck": {
Expand Down
14 changes: 14 additions & 0 deletions src/config/tor.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
{
"url": "http://czjsawp2crjmnkliw2h2kpk7wwd3a36zvvnvqgvzmi4t4vc2yzm7j2qd.onion"
}
],
"ipfsService": [
{
"url": "https://ipfs1test.adamant.im",
"alt_ip": "http://194.163.154.252:4000"
},
{
"url": "https://ipfs2test.adamant.im",
"alt_ip": "http://154.26.159.245:4000"
},
{
"url": "https://ipfs3test.adamant.im",
"alt_ip": "http://109.123.240.102:4000"
}
]
},
"healthCheck": {
Expand Down
Loading

0 comments on commit b29ebd2

Please sign in to comment.