@@ -148,30 +148,33 @@ export default {
148148 }
149149 } ,
150150
151- insertGraphic ( insertFile ) {
151+ /**
152+ * @private
153+ */
154+ insertFile_impl ( mimeTypeFilter , insertFileProc , insertHandler ) {
152155 if ( isPublicShare ( ) ) {
153- console . error ( '[FilesAppIntegration] insertGraphic is not supported' )
156+ console . error ( '[FilesAppIntegration] insertFile is not supported' )
154157 }
155158
156159 const insertFileFromPath = async ( path ) => {
157160 const filename = path . substring ( path . lastIndexOf ( '/' ) + 1 )
158161 const { data } = await axios . post ( generateUrl ( 'apps/richdocuments/assets' ) , { path } )
159- insertFile ( filename , data . url )
162+ insertFileProc ( filename , data . url )
160163 }
161164
162- if ( this . handlers . insertGraphic && this . handlers . insertGraphic ( this , { insertFileFromPath } ) ) {
165+ if ( insertHandler && insertHandler ( this , mimeTypeFilter , { insertFileFromPath } ) ) {
163166 return
164167 }
165168
166- getFilePickerBuilder ( t ( 'richdocuments' , 'Insert image from {name}' , { name : OC . theme . name } ) )
167- . setMimeTypeFilter ( [ 'image/png' , 'image/gif' , 'image/jpeg' , 'image/svg' ] )
169+ getFilePickerBuilder ( t ( 'richdocuments' , 'Insert file from {name}' , { name : OC . theme . name } ) )
170+ . setMimeTypeFilter ( mimeTypeFilter )
168171 . setFilter ( ( node ) => {
169172 const downloadShareAttribute = JSON . parse ( node . attributes [ 'share-attributes' ] ) . find ( ( shareAttribute ) => shareAttribute . key === 'download' )
170173 const downloadPermissions = downloadShareAttribute !== undefined ? ( downloadShareAttribute . enabled || downloadShareAttribute . value ) : true
171174 return ( node . permissions & OC . PERMISSION_READ ) && downloadPermissions
172175 } )
173176 . addButton ( {
174- label : t ( 'richdocuments' , 'Insert image ' ) ,
177+ label : t ( 'richdocuments' , 'Insert file ' ) ,
175178 callback : ( files ) => {
176179 if ( files && files . length ) {
177180 insertFileFromPath ( files [ 0 ] . path )
@@ -182,6 +185,16 @@ export default {
182185 . pick ( )
183186 } ,
184187
188+ insertGraphic ( insertFileProc ) {
189+ this . insertFile_impl ( [ 'image/png' , 'image/gif' , 'image/jpeg' , 'image/svg' ] ,
190+ insertFileProc ,
191+ ( filesAppIntegration , mimeTypeFilter , { insertFileFromPath } ) => { return this . handlers . insertGraphic && this . handlers . insertGraphic ( filesAppIntegration , { insertFileFromPath } ) } )
192+ } ,
193+
194+ insertFile ( mimeTypeFilter , insertFileProc ) {
195+ this . insertFile_impl ( mimeTypeFilter , insertFileProc , this . handlers . insertFile )
196+ } ,
197+
185198 getFileList ( ) {
186199 if ( this . fileList ) {
187200 return this . fileList
0 commit comments