git ssb

16+

Dominic / patchbay



Commit 9c5fb9afa9248c901294db9eac5e350da9bc055d

Merge pull request #326 from ssbc/dat-files

Support sharing files using dat
mix irving authored on 4/27/2019, 5:57:24 AM
GitHub committed on 4/27/2019, 5:57:24 AM
Parent: 8282b94576564e5f039401a879bfad5112d372e8
Parent: c2c3592f96ca4dddb067997ed7f1a2b45ab7b5bb

Files changed

app/async/catch-link-click.jschanged
app/sync/initialise/dat.jsadded
message/html/compose.jschanged
message/html/compose.mcsschanged
package-lock.jsonchanged
package.jsonchanged
app/async/catch-link-click.jsView
@@ -33,9 +33,9 @@
@@ -44,9 +44,9 @@
app/sync/initialise/dat.jsView
@@ -1,0 +1,14 @@
1 +const nest = require('depnest')
2 +const datSharedFiles = require('dat-shared-files/lib')
3 +
4 +exports.gives = nest('app.sync.initialise')
5 +
6 +exports.create = function (api) {
7 + return nest('app.sync.initialise', datShare)
8 +
9 + function datShare () {
10 + datSharedFiles.shareFiles(links => {
11 + links.forEach(link => console.log('Sharing: ' + link))
12 + })
13 + }
14 +}
message/html/compose.jsView
@@ -4,8 +4,9 @@
44 const extend = require('xtend')
55 const addSuggest = require('suggest-box')
66 const blobFiles = require('ssb-blob-files')
77 const get = require('lodash/get')
8 +const datSharedFiles = require('dat-shared-files/lib')
89
910 exports.gives = nest('message.html.compose')
1011
1112 exports.needs = nest({
@@ -121,12 +122,12 @@
121122 ])
122123 }))
123124 })
124125
125- var fileInput = h('input', {
126 + var ssbBlobInput = h('input -ssb', {
126127 type: 'file',
127128 // accept,
128- attributes: { multiple: true },
129 + attributes: { multiple: true, title: 'Add files as blobs' },
129130 'ev-click': () => hasContent.set(true),
130131 'ev-change': (ev) => {
131132 warningMessages.set([])
132133
@@ -157,13 +158,44 @@
157158
158159 console.log('added:', result)
159160 }
160161
162 + var datBlobInput = h('input -dat', {
163 + type: 'file',
164 + attributes: { title: 'Add file as dat link' },
165 + 'ev-click': () => hasContent.set(true),
166 + 'ev-change': (ev) => {
167 + const file = ev.target.files[0]
168 + datSharedFiles.shareFile(file.path, (datLink) => {
169 + const pos = textArea.selectionStart
170 + const insertLink = '[' + file.name + ']' + '(' + datLink + '/' + file.name + ')'
171 +
172 + textArea.value = textArea.value.slice(0, pos) + insertLink + textArea.value.slice(pos)
173 + })
174 + }
175 + })
176 +
161177 var isPublishing = Value(false)
162178 var publishBtn = h('button', { 'ev-click': publish, disabled: isPublishing }, isPrivate ? 'Reply' : 'Publish')
163179
164180 var actions = h('section.actions', [
165- fileInput,
181 + h('div.attach', [
182 + h('i.fa.fa-paperclip'),
183 + h('div.attachers', [
184 + h('div.attacher', { 'ev-click': () => ssbBlobInput.click() }, [
185 + h('i.fa.fa-file-o'),
186 + h('div.label', 'small file(s)'),
187 + h('div.subtext', '< 5MB')
188 + ]),
189 + h('div.attacher', { 'ev-click': () => datBlobInput.click() }, [
190 + h('i.fa.fa-file-archive-o'),
191 + h('div.label', 'large file'),
192 + h('div.subtext', 'DAT archive, (BETA)')
193 + ]),
194 + ssbBlobInput,
195 + datBlobInput
196 + ])
197 + ]),
166198 publishBtn
167199 ])
168200
169201 var composer = h('Compose', {
message/html/compose.mcssView
@@ -56,40 +56,72 @@
5656 justify-content: space-between
5757
5858 margin-top: .4rem
5959
60- input[type="file"] {
61- width: 1.8rem
62- height: 1.8rem
63- cursor: pointer
64- color: transparent
65- font-family: FontAwesome
66- border: 1px rgba(0,0,0,0) solid
60 + div.attach {
61 + position: relative
62 + transition: opacity ease-in 1s
6763
68- ::-webkit-file-upload-button {
69- visibility: hidden
64 + :hover {
65 + background-color: black
66 + i.fa { color: white }
67 +
68 + div.attachers { display: grid }
7069 }
7170
72- ::before {
73- padding-top: .3rem
71 + i.fa {
72 + color: black
7473
75- content: '\f0c6'
76- font-size: 1rem
77- color: #666;
78- background-color: #fff
74 + width: 30px
75 + height: 30px
7976
80- outline: none
81- white-space: nowrap
82- -webkit-user-select: none
83-
84- display: flex
77 + display: grid
8578 justify-content: center
79 + align-content: center
8680 }
8781
88- :hover, :focus {
89- border: 1px gainsboro solid
90- outline: none
91- box-shadow: none
82 + div.attachers {
83 + position: absolute
84 + top: 0
85 + left: 30px
86 +
87 + width: 250px
88 +
89 + color: black
90 + background: white
91 + border: 1px solid black
92 +
93 + display: none
94 + justify-items: stretch
95 + align-items: center
96 + grid-gap: 2px
97 + padding: 8px
98 +
99 + div.attacher {
100 + i.fa {}
101 + div.label {}
102 + div.subtext {
103 + color: grey
104 + font-size: 12px
105 + }
106 +
107 + display: grid
108 + grid-template-columns: auto 1fr auto
109 + grid-gap: 10px
110 +
111 + padding: 3px 5px
112 + cursor: pointer
113 + :hover {
114 + color: white
115 + background: black
116 +
117 + div.subtext { color: gainsboro }
118 + }
119 + }
120 +
121 + input[type="file"] {
122 + display: none
123 + }
92124 }
93125 }
94126
95127 }
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 658774 bytes
New file size: 710176 bytes
package.jsonView
@@ -45,8 +45,9 @@
4545 "dependencies": {
4646 "bulk-require": "^1.0.1",
4747 "chart.js": "^2.7.3",
4848 "cross-script": "^1.0.5",
49 + "dat-shared-files": "^0.0.2",
4950 "dataurl-": "^0.1.0",
5051 "depject": "^4.1.1",
5152 "depnest": "^1.3.0",
5253 "electron-default-menu": "^1.0.1",

Built with git-ssb-web