1function __rvxMediaUploadComponent__(){ 2 return { 3 isDragging: false, 4 multiple: true, 5 isPhotoReviewsAllowed: false, 6 isVideoReviewsAllowed: false, 7 // accept: 'image/*,video/*', 8 accept: 'image/*', 9 disabled: false, 10 files: { 11 urls: [], 12 blobFiles: [], 13 }, 14 maxFileCountError: null, 15 16 maxFileSizeError: null, 17 maxFileCount: 5, // Set max file count (adjust as needed) 18 maxFileSize: 10, // Set max file size in MB (adjust as needed) 19 20 init() { 21 this.isPhotoReviewsAllowed = this.reviewSettingsData?.data?.setting?.review_settings?.reviews?.photo_reviews_allowed ?? false; 22 this.isVideoReviewsAllowed = this.reviewSettingsData?.data?.setting?.review_settings?.reviews?.video_reviews_allowed ?? false; 23 // console.log('isPhotoReviewsAllowed:', this.isPhotoReviewsAllowed); 24 // console.log('isVideoReviewsAllowed:', this.isVideoReviewsAllowed); 25 26 if(this.isPhotoReviewsAllowed && !this.isVideoReviewsAllowed){ 27 this.accept = 'image/*' 28 } 29 if(this.isVideoReviewsAllowed && !this.isPhotoReviewsAllowed){ 30 this.accept = 'video/*' 31 } 32 if(this.isVideoReviewsAllowed && this.isPhotoReviewsAllowed){ 33 this.accept = 'image/*,video/*' 34 } 35 this.ready = true; 36 37 this.clearAll(); // Clear files on init 38 this.$nextTick(() => { 39 this.notifyFiles(); // Notify parent components about the state of files 40 }); 41 }, 42 43 // formatAcceptHandler(){}, 44 45 // Drag-and-drop handlers 46 dragEnterHandler() { 47 this.isDragging = true; 48 }, 49 dragLeaveHandler() { 50 this.isDragging = false; 51 }, 52 dropHandler(e) { 53 const fileList = e.dataTransfer?.files; 54 if (fileList?.length) { 55 this.handleFiles(fileList); 56 this.dragLeaveHandler(); 57 } 58 }, 59 notifyFiles() { 60 this.$dispatch('notify-attachment',{ reviewAttachFiles: this.files }); 61 }, 62 // File upload (input and drop) handling 63 onUpload(event) { 64 const target = event.target; 65 // console.log('target.files', target?.files) 66 if (target.files) { 67 this.handleFiles(target.files); 68 this.notifyFiles() 69 } 70 }, 71 72 handleFiles(fileList) { 73 const newFiles = Array.from(fileList); 74 75 // Reset error states 76 this.maxFileCountError = null; 77 this.maxFileSizeError = null; 78 79 // Check file count constraint 80 if (this.maxFileCount && this.files.blobFiles.length + newFiles.length > this.maxFileCount) { 81 this.maxFileCountError = `Cannot upload more than ${this.maxFileCount} files.`; 82 return; 83 } 84 85 // Check file size constraint 86 const maxFileSizeBytes = this.maxFileSize ? this.maxFileSize * 1024 * 1024 : null; 87 const overSizedFiles = newFiles.filter( 88 (file) => maxFileSizeBytes && file.size > maxFileSizeBytes 89 ); 90 if (overSizedFiles.length > 0) { 91 this.maxFileSizeError = `Some files exceed the maximum size of ${this.maxFileSize} MB.`; 92 return; 93 } 94 95 this.files.blobFiles.push(...newFiles); 96 this.files.urls.push(...this.createObjectURLs(newFiles)); 97 }, 98 createObjectURLs(files) { 99 return files.map((file) => ({ 100 path: URL.createObjectURL(file), 101 type: file.type.startsWith('image') ? 'image' : 'video', 102 })); 103 }, 104 remove(index) { 105 URL.revokeObjectURL(this.files.urls[index].path); 106 this.files.blobFiles.splice(index, 1); 107 this.files.urls.splice(index, 1); 108 this.notifyFiles() 109 }, 110 111 clearAll() {
112 this.files.urls.forEach((file) => URL.revokeObjectURL(file.path)); 113 this.files.blobFiles = []; 114 this.files.urls = []; 115 this.notifyFiles() 116 } 117 } 118}
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.