MCPcopy Index your code
hub / github.com/SnapDrop/snapdrop / _displayFile

Method _displayFile

client/scripts/ui.js:259–285  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

257 }
258
259 _displayFile(file) {
260 const $a = this.$el.querySelector('#download');
261 const url = URL.createObjectURL(file.blob);
262 $a.href = url;
263 $a.download = file.name;
264
265 if(this._autoDownload()){
266 $a.click()
267 return
268 }
269 if(file.mime.split('/')[0] === 'image'){
270 console.log('the file is image');
271 this.$el.querySelector('.preview').style.visibility = 'inherit';
272 this.$el.querySelector("#img-preview").src = url;
273 }
274
275 this.$el.querySelector('#fileName').textContent = file.name;
276 this.$el.querySelector('#fileSize').textContent = this._formatFileSize(file.size);
277 this.show();
278
279 if (window.isDownloadSupported) return;
280 // fallback for iOS
281 $a.target = '_blank';
282 const reader = new FileReader();
283 reader.onload = e => $a.href = reader.result;
284 reader.readAsDataURL(file.blob);
285 }
286
287 _formatFileSize(bytes) {
288 if (bytes >= 1e9) {

Callers 1

_nextFileMethod · 0.95

Calls 3

_autoDownloadMethod · 0.95
_formatFileSizeMethod · 0.95
showMethod · 0.80

Tested by

no test coverage detected