@@ -23,6 +23,48 @@ let fileManager = function (dataService) {
2323 dataService . upload ( url , data , callBack , fail ) ;
2424 }
2525
26+ function clipBoardUpload ( ClipboardEvent )
27+ {
28+ let file = getPasteFile ( ClipboardEvent ) ;
29+
30+ if ( file === null )
31+ return
32+
33+ uplType = "PostImage" ;
34+ let url = `api/storage/upload/${ uplType } ` ;
35+ let data = new FormData ( ) ;
36+ data . append ( 'file' , file , `${ Date . now ( ) } .png` ) ;
37+ dataService . upload ( url , data , ( arg ) => { insertImgCallback ( arg ) } , fail ) ;
38+ }
39+
40+ function getPasteFile ( ClipboardEvent )
41+ {
42+ const data = ClipboardEvent . clipboardData ;
43+ if ( data == null )
44+ {
45+ return null ;
46+ }
47+
48+ if ( data . items . length === 0 )
49+ {
50+ return null ;
51+ }
52+
53+ const item = data . items [ 0 ] ;
54+
55+ if ( item . kind === 'string' )
56+ {
57+ return null ;
58+ }
59+
60+ const file = item . getAsFile ( ) ;
61+
62+ if ( file . type . indexOf ( "image" ) === - 1 )
63+ return null
64+
65+ return file ;
66+ }
67+
2668 function appCoverCallback ( data ) {
2769 let defaultCover = document . getElementById ( 'defaultCover' ) ;
2870 defaultCover . value = data ;
@@ -73,6 +115,7 @@ let fileManager = function (dataService) {
73115
74116 return {
75117 uploadClick : uploadClick ,
76- uploadSubmit : uploadSubmit
118+ uploadSubmit : uploadSubmit ,
119+ clipBoardUpload :clipBoardUpload ,
77120 } ;
78121} ( DataService ) ;
0 commit comments