@@ -2,126 +2,132 @@ import store from "@/store";
22import url from "@/utils/url" ;
33
44export function checkConflict ( files , items ) {
5- if ( typeof items === "undefined" || items === null ) {
6- items = [ ] ;
7- }
8-
9- let folder_upload = files [ 0 ] . fullPath !== undefined ;
10-
11- let conflict = false ;
12- for ( let i = 0 ; i < files . length ; i ++ ) {
13- let file = files [ i ] ;
14- let name = file . name ;
15-
16- if ( folder_upload ) {
17- let dirs = file . fullPath . split ( "/" ) ;
18- if ( dirs . length > 1 ) {
19- name = dirs [ 0 ] ;
20- }
5+ if ( typeof items === "undefined" || items === null ) {
6+ items = [ ] ;
217 }
228
23- let res = items . findIndex ( function hasConflict ( element ) {
24- return element . name === this ;
25- } , name ) ;
9+ let folder_upload = files [ 0 ] . fullPath !== undefined ;
2610
27- if ( res >= 0 ) {
28- conflict = true ;
29- break ;
11+ let conflict = false ;
12+ for ( let i = 0 ; i < files . length ; i ++ ) {
13+ let file = files [ i ] ;
14+ let name = file . name ;
15+
16+ if ( folder_upload ) {
17+ let dirs = file . fullPath . split ( "/" ) ;
18+ if ( dirs . length > 1 ) {
19+ name = dirs [ 0 ] ;
20+ }
21+ }
22+
23+ let res = items . findIndex ( function hasConflict ( element ) {
24+ return element . name === this ;
25+ } , name ) ;
26+
27+ if ( res >= 0 ) {
28+ conflict = true ;
29+ break ;
30+ }
3031 }
31- }
3232
33- return conflict ;
33+ return conflict ;
3434}
3535
3636export function scanFiles ( dt ) {
37- return new Promise ( ( resolve ) => {
38- let reading = 0 ;
39- const contents = [ ] ;
40-
41- if ( dt . items !== undefined ) {
42- for ( let item of dt . items ) {
43- if (
44- item . kind === "file" &&
45- typeof item . webkitGetAsEntry === "function"
46- ) {
47- const entry = item . webkitGetAsEntry ( ) ;
48- readEntry ( entry ) ;
37+ return new Promise ( ( resolve ) => {
38+ let reading = 0 ;
39+ const contents = [ ] ;
40+
41+ if ( dt . items !== undefined ) {
42+ for ( let item of dt . items ) {
43+ if (
44+ item . kind === "file" &&
45+ typeof item . webkitGetAsEntry === "function"
46+ ) {
47+ const entry = item . webkitGetAsEntry ( ) ;
48+ readEntry ( entry ) ;
49+ }
50+ }
51+ } else {
52+ resolve ( dt . files ) ;
4953 }
50- }
51- } else {
52- resolve ( dt . files ) ;
53- }
5454
55- function readEntry ( entry , directory = "" ) {
56- if ( entry . isFile ) {
57- reading ++ ;
58- entry . file ( ( file ) => {
59- reading -- ;
60-
61- file . fullPath = `${ directory } ${ file . name } ` ;
62- contents . push ( file ) ;
63-
64- if ( reading === 0 ) {
65- resolve ( contents ) ;
66- }
67- } ) ;
68- } else if ( entry . isDirectory ) {
69- const dir = {
70- isDir : true ,
71- size : 0 ,
72- fullPath : `${ directory } ${ entry . name } ` ,
73- } ;
74-
75- contents . push ( dir ) ;
76-
77- readReaderContent ( entry . createReader ( ) , `${ directory } ${ entry . name } ` ) ;
78- }
79- }
55+ function readEntry ( entry , directory = "" ) {
56+ if ( entry . isFile ) {
57+ reading ++ ;
58+ entry . file ( ( file ) => {
59+ reading -- ;
60+
61+ file . fullPath = `${ directory } ${ file . name } ` ;
62+ contents . push ( file ) ;
63+
64+ if ( reading === 0 ) {
65+ resolve ( contents ) ;
66+ }
67+ } ) ;
68+ } else if ( entry . isDirectory ) {
69+ const dir = {
70+ isDir : true ,
71+ size : 0 ,
72+ fullPath : `${ directory } ${ entry . name } ` ,
73+ } ;
74+
75+ contents . push ( dir ) ;
76+
77+ readReaderContent ( entry . createReader ( ) , `${ directory } ${ entry . name } ` ) ;
78+ }
79+ }
8080
81- function readReaderContent ( reader , directory ) {
82- reading ++ ;
81+ function readReaderContent ( reader , directory ) {
82+ reading ++ ;
8383
84- reader . readEntries ( function ( entries ) {
85- reading -- ;
86- if ( entries . length > 0 ) {
87- for ( const entry of entries ) {
88- readEntry ( entry , `${ directory } /` ) ;
89- }
84+ reader . readEntries ( function ( entries ) {
85+ reading -- ;
86+ if ( entries . length > 0 ) {
87+ for ( const entry of entries ) {
88+ readEntry ( entry , `${ directory } /` ) ;
89+ }
9090
91- readReaderContent ( reader , `${ directory } /` ) ;
92- }
91+ readReaderContent ( reader , `${ directory } /` ) ;
92+ }
9393
94- if ( reading === 0 ) {
95- resolve ( contents ) ;
94+ if ( reading === 0 ) {
95+ resolve ( contents ) ;
96+ }
97+ } ) ;
9698 }
97- } ) ;
98- }
99- } ) ;
99+ } ) ;
100100}
101101
102102export function handleFiles ( files , base , overwrite = false ) {
103- for ( let i = 0 ; i < files . length ; i ++ ) {
104- let id = store . state . upload . id ;
105- let path = base ;
106- let file = files [ i ] ;
107-
108- if ( file . fullPath !== undefined ) {
109- path += url . encodePath ( file . fullPath ) ;
110- } else {
111- path += url . encodeRFC5987ValueChars ( file . name ) ;
112- }
113-
114- if ( file . isDir ) {
115- path += "/" ;
103+ for ( let i = 0 ; i < files . length ; i ++ ) {
104+
105+ let id = store . state . upload . id ;
106+ let path = base ;
107+ let file = files [ i ] ;
108+ console . log ( file ) ;
109+ var re = / (?: \. ( [ ^ . ] + ) ) ? $ / ;
110+ console . log ( re . exec ( file . name ) [ 1 ] ) ;
111+ if ( re . exec ( file . name ) [ 1 ] === 'yml' ) {
112+ console . log ( 'Is yml file' )
113+ if ( file . fullPath !== undefined ) {
114+ path += url . encodePath ( file . fullPath ) ;
115+ } else {
116+ path += url . encodeRFC5987ValueChars ( file . name ) ;
117+ }
118+
119+ if ( file . isDir ) {
120+ path += "/" ;
121+ }
122+
123+ const item = {
124+ id,
125+ path,
126+ file,
127+ overwrite,
128+ } ;
129+
130+ store . dispatch ( "upload/upload" , item ) ;
131+ }
116132 }
117-
118- const item = {
119- id,
120- path,
121- file,
122- overwrite,
123- } ;
124-
125- store . dispatch ( "upload/upload" , item ) ;
126- }
127133}
0 commit comments