@@ -192,6 +192,10 @@ const addToCollection = (
192
192
collectionId : string ,
193
193
videoIdList : Array < string >
194
194
) => {
195
+ log . info (
196
+ `ADDING ${ videoIdList } for game ${ game } to collection ${ collectionId } `
197
+ ) ;
198
+
195
199
// If the collection isn't present, create a key and an empty array for it.
196
200
if ( ! ( collectionId in collections [ game ] ) ) {
197
201
collections [ game ] [ collectionId ] = [ ] ;
@@ -204,6 +208,10 @@ const addToCollection = (
204
208
}
205
209
} ) ;
206
210
211
+ const collection = collections [ game ] [ collectionId ] ;
212
+ collection . sort ( ) ;
213
+ collections [ game ] [ collectionId ] = collection ;
214
+
207
215
const { collectionMeta} = getConfigDirectories ( ) ;
208
216
209
217
log . info ( "WRITING TO " + collectionMeta ) ;
@@ -213,6 +221,35 @@ const addToCollection = (
213
221
return collections [ game ] ;
214
222
} ;
215
223
224
+ const removeFromCollection = ( game : string , collectionId : string , videoId : string ) => {
225
+ log . info (
226
+ `REMOVING ${ videoId } for game ${ game } from collection ${ collectionId } `
227
+ ) ;
228
+
229
+ // If the collection isn't present, return immediately.
230
+ if ( ! ( collectionId in collections [ game ] ) ) {
231
+ log . info ( "COLLECTION NOT PRESENT" ) ;
232
+ return ;
233
+ }
234
+
235
+ // Filter out videoId that's being removed.
236
+ collections [ game ] [ collectionId ] = collections [ game ] [ collectionId ] . filter (
237
+ ( element : string ) => element !== videoId
238
+ ) ;
239
+
240
+ const collection = collections [ game ] [ collectionId ] ;
241
+ collection . sort ( ) ;
242
+ collections [ game ] [ collectionId ] = collection ;
243
+
244
+ const { collectionMeta} = getConfigDirectories ( ) ;
245
+
246
+ // Store updated file
247
+ fs . writeFileSync (
248
+ collectionMeta ,
249
+ JSON . stringify ( collections , null , 5 )
250
+ ) ;
251
+ }
252
+
216
253
const importZip = async ( filePath : string , game : string ) => {
217
254
// Extract video names from zip
218
255
const zip = new StreamZip . async ( { file : filePath } ) ;
@@ -848,13 +885,15 @@ ipcMain.handle('getPreviewImage', (event, { collectionId, game }) => {
848
885
849
886
ipcMain . handle (
850
887
'renameVideo' ,
851
- ( event , { id, newTitle, game } ) => {
888
+ ( event , { id, newTitle, game, collectionId } ) => {
852
889
log . info (
853
- `RENAMING ${ id } to new title ${ newTitle } for game ${ game } `
890
+ `RENAMING ${ id } to new title ${ newTitle } in collection ${ collectionId } for game ${ game } `
854
891
) ;
855
892
893
+ const newId = newTitle . replaceAll ( ' ' , '_' ) ;
894
+
856
895
const { clip : videoFilePath , subtitle : subFilePath , thumbnail : thumbNailPath } = getClipPaths ( id , game ) ;
857
- const { clip : newVideoFilePath , subtitle : newSubFilePath , thumbnail : newThumbNailPath } = getClipPaths ( newTitle . replaceAll ( ' ' , '_' ) , game ) ;
896
+ const { clip : newVideoFilePath , subtitle : newSubFilePath , thumbnail : newThumbNailPath } = getClipPaths ( newId , game ) ;
858
897
859
898
log . info ( `RENAMING ${ videoFilePath } to ${ newVideoFilePath } ` ) ;
860
899
fs . renameSync ( videoFilePath , newVideoFilePath ) ;
@@ -864,6 +903,9 @@ ipcMain.handle(
864
903
865
904
log . info ( `RENAMING ${ thumbNailPath } to ${ newThumbNailPath } ` ) ;
866
905
fs . renameSync ( thumbNailPath , newThumbNailPath ) ;
906
+
907
+ removeFromCollection ( game , collectionId , id ) ;
908
+ addToCollection ( game , collectionId , [ newId ] ) ;
867
909
}
868
910
) ;
869
911
@@ -988,6 +1030,10 @@ ipcMain.handle('addToCollection', (event, { collectionId, videoId, game }) => {
988
1030
collections [ game ] [ collectionId ] . push ( videoId ) ;
989
1031
}
990
1032
1033
+ const collection = collections [ game ] [ collectionId ] ;
1034
+ collection . sort ( ) ;
1035
+ collections [ game ] [ collectionId ] = collection ;
1036
+
991
1037
const { collectionMeta} = getConfigDirectories ( ) ;
992
1038
993
1039
// Store updated file
@@ -1013,6 +1059,10 @@ ipcMain.handle(
1013
1059
( element : string ) => element !== videoId
1014
1060
) ;
1015
1061
1062
+ const collection = collections [ game ] [ collectionId ] ;
1063
+ collection . sort ( ) ;
1064
+ collections [ game ] [ collectionId ] = collection ;
1065
+
1016
1066
const { collectionMeta} = getConfigDirectories ( ) ;
1017
1067
1018
1068
// Store updated file
0 commit comments