1import Dropzone from 'dropzone' 2 3export default class Uploader { 4 constructor (dropzone, element) { 5 this.element = $(element) 6 this.dropzone = dropzone 7 } 8 9 addedFile(file) { 10 const folderLayout = this.element.attr('data-folder-layout') 11 const objectId = this.element.attr('data-object-id') 12 const [ok, msg] = this.admitFile(file) 13 14 if (ok) { 15 $.post( 16 '/admin/s3_uploads', 17 { object_id: objectId, 18 original_filename: file.name, 19 folder_layout: folderLayout }, 20 response => { 21 this.dropzone.options.url = response.url 22 file.s3_path = response.s3_path 23 this.dropzone.processFile(file) 24 } 25 ) 26 } 27 } 28 29 sending (_file, xhr, _formData) { 30 xhr.timeout = 99999999 31 } 32 33 success (file) { 34 const successUrl = this.element.attr('data-success-url') 35 const objectId = this.element.attr('data-object-id') 36 37 $.post(successUrl, { object_id: objectId, s3_path: file.s3_path }) 38 } 39 40 progress(percent) { 41 const progressBar = this.element.find('.c-progress-bar') 42 if (percent < 100) { 43 progressBar.css('display', 'block') 44 progressBar.css('width', `${percent}%`) 45 } else { 46 progressBar.css('display', 'none') 47 } 48 } 49 50 admitFile(file) { 51 const filenameRegexp = this.element.attr('data-filename-regexp') 52 const acceptedFiles = this.element.attr('data-accepted-files') 53 54 if (!Dropzone.isValidFile(file, acceptedFiles)) { 55 return [false, 'Invalid file type'] 56 } 57 58 if (filenameRegexp != null && !file.name.match(filenameRegexp)) { 59 return [false, 'Invalid file name'] 60 } 61 62 return [true, ''] 63 } 64};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.