4242 >
4343 consolidate
4444 </b-button >
45-
46- <div v-if =" didConsolidate" class =" block mt-6" >
47- {{ didCopy ? 'Copied' : 'Moved' }} {{ numConsolidated }} /
48- {{ numTracks }} tracks to
49- <a @click =" openTargetFolder()" class =" has-text-link" >
50- {{ targetFolder }}
51- </a >
52- </div >
53-
54- <p v-if =" numMissing" >
55- <span class =" has-text-warning" >
56- {{ numMissing }} tracks were not found
57- </span >
58- <br />
59- Use
60- <a @click =" $router.push('relocate')" class =" link-text" >relocate</a >
61- to fix this
62- </p >
6345 </div >
6446
6547 <error-message :message =" error" ></error-message >
48+
49+ <b-modal v-model =" didConsolidate" has-modal-card >
50+ <div class =" modal-card card is-align-items-center py-6" >
51+ <div class =" block" >
52+ {{ didCopy ? 'Copied' : 'Moved' }} {{ numConsolidated }} /
53+ {{ numTracks }} tracks to
54+ <a @click =" openTargetFolder()" class =" link-text" >
55+ {{ targetFolder }}
56+ </a >
57+ </div >
58+
59+ <div v-if =" numAlreadyConsolidated" class =" block" >
60+ <span class =" has-text-info" >
61+ {{ numAlreadyConsolidated }} tracks were already in the target
62+ folder
63+ </span >
64+ </div >
65+
66+ <div v-if =" numMissing" >
67+ <span class =" has-text-warning" >
68+ {{ numMissing }} tracks were not found
69+ </span >
70+ <br />
71+ Use
72+ <a @click =" $router.push('relocate')" class =" link-text" >relocate</a >
73+ to fix this
74+ </div >
75+
76+ <b-button
77+ @click =" didConsolidate = false"
78+ type =" is-primary"
79+ class =" mt-6"
80+ >
81+ ok
82+ </b-button >
83+ </div >
84+ </b-modal >
6685 </div >
6786</template >
6887
@@ -89,6 +108,7 @@ interface ConsolidatableTrack {
89108 track: engine .Track ;
90109 wasConsolidated: boolean ;
91110 oldPath: string ;
111+ newPath: string ;
92112}
93113
94114@Component ({
@@ -103,8 +123,10 @@ export default class ConsolidateCommand extends BaseCommand {
103123
104124 targetFolder = ' ' ;
105125
106- allTracks: engine .Track [] | null = null ;
107- foundTracks: ConsolidatableTrack [] | null = null ;
126+ allTracks: engine .Track [] = [];
127+ foundTracks: ConsolidatableTrack [] = [];
128+ alreadyConsolidatedTracks: engine .Track [] = [];
129+ missingTracks: engine .Track [] = [];
108130
109131 error = ' ' ;
110132
@@ -116,23 +138,24 @@ export default class ConsolidateCommand extends BaseCommand {
116138 return this .isConsolidating ;
117139 }
118140
119- get numTracks(): number | undefined {
120- return this .allTracks ? .length ;
141+ get numTracks(): number {
142+ return this .allTracks .length ;
121143 }
122144
123- get consolidatedTracks(): ConsolidatableTrack [] | undefined {
124- return this .foundTracks ? .filter (x => x .wasConsolidated );
145+ get consolidatedTracks(): ConsolidatableTrack [] {
146+ return this .foundTracks .filter (x => x .wasConsolidated );
125147 }
126148
127- get numConsolidated(): number | undefined {
128- return this .consolidatedTracks ? .length ;
149+ get numConsolidated(): number {
150+ return this .consolidatedTracks .length ;
129151 }
130152
131- get numMissing(): number | undefined {
132- if (! this .didConsolidate ) {
133- return 0 ;
134- }
135- return this .allTracks ! .length - this .foundTracks ! .length ;
153+ get numAlreadyConsolidated(): number {
154+ return this .alreadyConsolidatedTracks .length ;
155+ }
156+
157+ get numMissing(): number {
158+ return this .missingTracks .length ;
136159 }
137160
138161 async consolidateLibrary() {
@@ -169,55 +192,51 @@ export default class ConsolidateCommand extends BaseCommand {
169192
170193 private async consolidateLibraryInternal() {
171194 const findTracks = async () => {
172- const tracks = await this .engineDb ! .getTracks ();
173- const found: ConsolidatableTrack [] = [];
195+ this .allTracks = await this .engineDb ! .getTracks ();
196+ this .foundTracks = [];
197+ this .alreadyConsolidatedTracks = [];
198+ this .missingTracks = [];
174199
175- for (const track of tracks ) {
200+ for (const track of this . allTracks ) {
176201 const resolvedPath = path .resolve (this .libraryFolder , track .path );
177- if (await checkPathExists (resolvedPath )) {
178- found .push ({
202+ const newPath = path .resolve (this .targetFolder , track .filename );
203+
204+ if (resolvedPath === newPath ) {
205+ this .alreadyConsolidatedTracks .push (track );
206+ } else if (! (await checkPathExists (resolvedPath ))) {
207+ this .missingTracks .push (track );
208+ } else {
209+ this .foundTracks .push ({
179210 track ,
180211 wasConsolidated: false ,
181212 oldPath: resolvedPath ,
213+ newPath ,
182214 });
183215 }
184216 }
185-
186- return { tracks , found };
187217 };
188218
189- async function processFile(from : string , to : string , copy ? : boolean ) {
219+ const processFile = async (from : string , to : string , copy ? : boolean ) => {
190220 if (copy ) {
191221 await fse .copyFile (from , to );
192222 } else {
193223 await fse .move (from , to );
194224 }
195- }
225+ };
226+
227+ await findTracks ();
196228
197- const { tracks, found } = await findTracks ();
198- this .allTracks = tracks ;
199- this .foundTracks = found ;
200-
201- for (const item of found ) {
202- const targetPath = path .resolve (this .targetFolder , item .track .filename );
203- item .track .path = makePathUnix (
204- path .relative (this .libraryFolder , targetPath ),
205- );
206- // no overwrite
207- // if (path.normalize(item.oldPath) === path.normalize(item.track.path)) {
208- // continue;
209- // }
210-
211- await processFile (item .oldPath , targetPath , this .shouldCopy );
229+ for (const item of this .foundTracks ) {
230+ await processFile (item .oldPath , item .newPath , this .shouldCopy );
212231 item .wasConsolidated = true ;
213232 }
214233
215234 await this .engineDb ! .updateTracks (
216- found
235+ this . foundTracks
217236 .filter (x => x .wasConsolidated )
218- .map (({ track }) => ({
237+ .map (({ track , newPath }) => ({
219238 id: track .id ,
220- path: track . path ,
239+ path: makePathUnix ( path . relative ( this . libraryFolder , newPath )) ,
221240 })),
222241 );
223242 }
0 commit comments