@@ -119,22 +119,10 @@ const { user } = storeToRefs(webStores.collection());
119119
120120const showWidget = ref (true );
121121
122- watch (
123- () => uploadPageNumber ,
124- (value ) => {
125- if (value !== undefined ) {
126- modal .value = true ;
127- showWidget .value = true ;
128- }
129- },
130- { immediate: true },
131- );
132-
133122const uploadFileType = ref <" PDF_ignore" | " PDF_replace" | " Images" >(
134123 " PDF_ignore" ,
135124);
136125
137- const currentPageIndex = ref (0 );
138126const isUploading = ref (false );
139127const processLog = ref (" " );
140128
@@ -147,6 +135,17 @@ declare var cloudinary: {
147135 createUploadWidget: CloudinaryCreateUploadWidget ;
148136};
149137
138+ watch (
139+ () => uploadPageNumber ,
140+ (value ) => {
141+ if (value !== undefined ) {
142+ modal .value = true ;
143+ showWidget .value = true ;
144+ }
145+ },
146+ { immediate: true },
147+ );
148+
150149const pages = computed (() =>
151150 uploadFileType .value === " PDF_ignore"
152151 ? pagesWithoutOverwrite .value
@@ -160,6 +159,7 @@ const processPage = async (pageIndex: number, url: string) => {
160159};
161160
162161onMounted (() => {
162+ const fileIds: string [] = [];
163163 const folderName = indexation .value ! .id ;
164164 const uploadWidget = cloudinary .createUploadWidget (
165165 {
@@ -182,6 +182,9 @@ onMounted(() => {
182182 console .error (error );
183183 } else {
184184 switch (result ?.event ) {
185+ case " upload-added" :
186+ fileIds .push ((result .info as CloudinaryUploadWidgetInfo ).id );
187+ break ;
185188 case " queues-start" :
186189 isUploading .value = true ;
187190 break ;
@@ -190,23 +193,28 @@ onMounted(() => {
190193 const info = result .info as CloudinaryUploadWidgetInfo ;
191194 console .log (" Done! Here is the image info: " , info );
192195
196+ const firstUploadPageIndex = pages .value .findIndex (
197+ (page ) => page .pageNumber === uploadPageNumber ,
198+ );
193199 if (info .pages ) {
194200 for (
195201 let page = 1 ;
196202 page <= Math .min (info .pages , pages .value .length );
197203 page ++
198204 ) {
199205 await processPage (
200- currentPageIndex . value ++ ,
206+ firstUploadPageIndex + page - 1 ,
201207 info .secure_url
202208 .replace (" /upload/" , ` /upload/pg_${page }/ ` )
203209 .replace (/ . pdf$ / g , " .png" ),
204210 );
205211 }
206212 } else {
207- await processPage (currentPageIndex .value ++ , info .secure_url );
213+ await processPage (
214+ firstUploadPageIndex + fileIds .indexOf (info .id ),
215+ info .secure_url ,
216+ );
208217 }
209- currentPageIndex .value = 0 ;
210218 modal .value = false ;
211219 emit (" done" );
212220 break ;
0 commit comments