@@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
44import {
55 FindOptionsWhere ,
66 In ,
7+ IsNull ,
78 LessThan ,
89 Like ,
910 MoreThan ,
@@ -164,6 +165,41 @@ export class QueueService implements OnModuleInit {
164165 return { } ;
165166 }
166167
168+ /**
169+ * re-calculates the hashes for all files without a valid hash
170+ */
171+ async recalculateHashes ( ) : Promise < {
172+ success : boolean ;
173+ fileCount : number ;
174+ } > {
175+ // search for files with no hash (empty or null) and state OK
176+ const files = await this . fileRepository . find ( {
177+ where : [
178+ { hash : IsNull ( ) , state : FileState . OK } ,
179+ { hash : '' , state : FileState . OK } ,
180+ ] ,
181+ relations : [ 'mission' , 'mission.project' ] ,
182+ } ) ;
183+
184+ logger . debug ( `Add ${ files . length } files to queue for hash calculation` ) ;
185+ logger . debug ( JSON . stringify ( files . map ( ( file ) => file . uuid ) ) ) ;
186+
187+ for ( const file of files ) {
188+ try {
189+ await this . fileQueue . add ( 'extractHashFromMinio' , {
190+ file_uuid : file . uuid ,
191+ } ) ;
192+ } catch ( error : any ) {
193+ logger . error ( error ) ;
194+ }
195+ }
196+
197+ return {
198+ success : true ,
199+ fileCount : files . length ,
200+ } ;
201+ }
202+
167203 async confirmUpload ( uuid : string , md5 : string ) : Promise < void > {
168204 const queue = await this . queueRepository . findOneOrFail ( {
169205 where : { identifier : uuid } ,
@@ -191,12 +227,6 @@ export class QueueService implements OnModuleInit {
191227 file . size = fileInfo . size ;
192228 await this . fileRepository . save ( file ) ;
193229
194- // abort if autoConvert is disabled
195- if ( ! file . mission ?. project ?. autoConvert ) {
196- logger . debug ( `Skip auto convert to mcap` ) ;
197- return ;
198- }
199-
200230 queue . state = QueueState . AWAITING_PROCESSING ;
201231 await this . queueRepository . save ( queue ) ;
202232
0 commit comments