Commit 9c5fb9afa9248c901294db9eac5e350da9bc055d
Merge pull request #326 from ssbc/dat-files
Support sharing files using datmix 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.js | changed |
app/sync/initialise/dat.js | added |
message/html/compose.js | changed |
message/html/compose.mcss | changed |
package-lock.json | changed |
package.json | changed |
app/async/catch-link-click.js | ||
---|---|---|
@@ -33,9 +33,9 @@ | ||
33 | 33 … | |
34 | 34 … | var url |
35 | 35 … | |
36 | 36 … | try { |
37 | - var url = new URL(href) | |
37 … | + url = new URL(href) | |
38 | 38 … | } catch (e) { |
39 | 39 … | // In case we pass an invalid URL |
40 | 40 … | url = {} |
41 | 41 … | } |
@@ -44,9 +44,9 @@ | ||
44 | 44 … | altKey: ev.altKey, |
45 | 45 … | ctrlKey: ev.ctrlKey, |
46 | 46 … | metaKey: ev.metaKey, |
47 | 47 … | shiftKey: ev.shiftKey, |
48 | - isExternal: !!url.host || url.protocol === 'magnet:' | |
48 … | + isExternal: !!url.host || url.protocol === 'magnet:' || url.protocol === 'dat:' | |
49 | 49 … | } |
50 | 50 … | |
51 | 51 … | cb(href, opts) |
52 | 52 … | }) |
app/sync/initialise/dat.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -4,8 +4,9 @@ | ||
4 | 4 … | const extend = require('xtend') |
5 | 5 … | const addSuggest = require('suggest-box') |
6 | 6 … | const blobFiles = require('ssb-blob-files') |
7 | 7 … | const get = require('lodash/get') |
8 … | +const datSharedFiles = require('dat-shared-files/lib') | |
8 | 9 … | |
9 | 10 … | exports.gives = nest('message.html.compose') |
10 | 11 … | |
11 | 12 … | exports.needs = nest({ |
@@ -121,12 +122,12 @@ | ||
121 | 122 … | ]) |
122 | 123 … | })) |
123 | 124 … | }) |
124 | 125 … | |
125 | - var fileInput = h('input', { | |
126 … | + var ssbBlobInput = h('input -ssb', { | |
126 | 127 … | type: 'file', |
127 | 128 … | // accept, |
128 | - attributes: { multiple: true }, | |
129 … | + attributes: { multiple: true, title: 'Add files as blobs' }, | |
129 | 130 … | 'ev-click': () => hasContent.set(true), |
130 | 131 … | 'ev-change': (ev) => { |
131 | 132 … | warningMessages.set([]) |
132 | 133 … | |
@@ -157,13 +158,44 @@ | ||
157 | 158 … | |
158 | 159 … | console.log('added:', result) |
159 | 160 … | } |
160 | 161 … | |
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 … | + | |
161 | 177 … | var isPublishing = Value(false) |
162 | 178 … | var publishBtn = h('button', { 'ev-click': publish, disabled: isPublishing }, isPrivate ? 'Reply' : 'Publish') |
163 | 179 … | |
164 | 180 … | 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 … | + ]), | |
166 | 198 … | publishBtn |
167 | 199 … | ]) |
168 | 200 … | |
169 | 201 … | var composer = h('Compose', { |
message/html/compose.mcss | ||
---|---|---|
@@ -56,40 +56,72 @@ | ||
56 | 56 … | justify-content: space-between |
57 | 57 … | |
58 | 58 … | margin-top: .4rem |
59 | 59 … | |
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 | |
67 | 63 … | |
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 } | |
70 | 69 … | } |
71 | 70 … | |
72 | - ::before { | |
73 | - padding-top: .3rem | |
71 … | + i.fa { | |
72 … | + color: black | |
74 | 73 … | |
75 | - content: '\f0c6' | |
76 | - font-size: 1rem | |
77 | - color: #666; | |
78 | - background-color: #fff | |
74 … | + width: 30px | |
75 … | + height: 30px | |
79 | 76 … | |
80 | - outline: none | |
81 | - white-space: nowrap | |
82 | - -webkit-user-select: none | |
83 | - | |
84 | - display: flex | |
77 … | + display: grid | |
85 | 78 … | justify-content: center |
79 … | + align-content: center | |
86 | 80 … | } |
87 | 81 … | |
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 … | + } | |
92 | 124 … | } |
93 | 125 … | } |
94 | 126 … | |
95 | 127 … | } |
package-lock.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -45,8 +45,9 @@ | ||
45 | 45 … | "dependencies": { |
46 | 46 … | "bulk-require": "^1.0.1", |
47 | 47 … | "chart.js": "^2.7.3", |
48 | 48 … | "cross-script": "^1.0.5", |
49 … | + "dat-shared-files": "^0.0.2", | |
49 | 50 … | "dataurl-": "^0.1.0", |
50 | 51 … | "depject": "^4.1.1", |
51 | 52 … | "depnest": "^1.3.0", |
52 | 53 … | "electron-default-menu": "^1.0.1", |
Built with git-ssb-web