tango-app-api-trax 3.7.13-qid-halfshutter-3 → 3.7.13-qid-halfshutter-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1255,10 +1255,13 @@ export async function insertTimeDelayFlags( req, res ) {
|
|
|
1255
1255
|
if ( !req.body.date ) {
|
|
1256
1256
|
return res.sendError( 'date is required', 400 );
|
|
1257
1257
|
}
|
|
1258
|
-
|
|
1258
|
+
// Fix for timezone based issue for diff stores
|
|
1259
|
+
const currentDate = new Date( req.body.date );
|
|
1260
|
+
const prevDate = new Date( req.body.date );
|
|
1261
|
+
prevDate.setDate( prevDate.getDate() - 1 );
|
|
1259
1262
|
let query = [ {
|
|
1260
1263
|
$match: {
|
|
1261
|
-
date_iso:
|
|
1264
|
+
date_iso: { $in: [ currentDate, prevDate ] },
|
|
1262
1265
|
checklistStatus: { $ne: 'submit' },
|
|
1263
1266
|
checkListType: { $in: [ 'custom' ] },
|
|
1264
1267
|
timeFlag: 0,
|
|
@@ -19,14 +19,23 @@ import timeZone from 'dayjs/plugin/timezone.js';
|
|
|
19
19
|
import { findOTP, updateOneOTP } from '../services/otp.service.js';
|
|
20
20
|
import * as clientService from '../services/clients.services.js';
|
|
21
21
|
import { create } from '../services/authentication.service.js';
|
|
22
|
-
import
|
|
23
|
-
import { join } from 'path';
|
|
22
|
+
import * as fs from 'fs';
|
|
23
|
+
import { join, dirname } from 'path';
|
|
24
24
|
import handlebars from 'handlebars';
|
|
25
25
|
dayjs.extend( customParseFormat );
|
|
26
26
|
dayjs.extend( timeZone );
|
|
27
27
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
|
|
28
28
|
import * as cameraService from '../services/camera.service.js';
|
|
29
29
|
dayjs.extend( isSameOrBefore );
|
|
30
|
+
import { fileURLToPath } from 'url';
|
|
31
|
+
const fsp = fs.promises;
|
|
32
|
+
|
|
33
|
+
const __filename = fileURLToPath( import.meta.url );
|
|
34
|
+
const __dirname = dirname( __filename );
|
|
35
|
+
const UPLOAD_DIR = join( __dirname, '/uploads' );
|
|
36
|
+
if ( !fs.existsSync( UPLOAD_DIR ) ) {
|
|
37
|
+
fs.mkdirSync( UPLOAD_DIR, { recursive: true } );
|
|
38
|
+
}
|
|
30
39
|
|
|
31
40
|
export async function storeList( req, res ) {
|
|
32
41
|
try {
|
|
@@ -4389,3 +4398,70 @@ export async function questionListV1( req, res ) {
|
|
|
4389
4398
|
}
|
|
4390
4399
|
}
|
|
4391
4400
|
|
|
4401
|
+
|
|
4402
|
+
export async function chunkUpload( req, res ) {
|
|
4403
|
+
try {
|
|
4404
|
+
const { chunkIndex, totalChunks } = req.body;
|
|
4405
|
+
|
|
4406
|
+
if ( !req.files || !req.files.answerImage ) {
|
|
4407
|
+
return res.status( 400 ).json( { error: 'No chunk file uploaded' } );
|
|
4408
|
+
}
|
|
4409
|
+
|
|
4410
|
+
if ( chunkIndex > totalChunks ) {
|
|
4411
|
+
return res.sendError( 'Chunk index is wrong', 400 );
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4414
|
+
const uploadedChunk = req.files.answerImage;
|
|
4415
|
+
const baseName = uploadedChunk.name.split( '.' )[0];
|
|
4416
|
+
const partPath = join( UPLOAD_DIR, `${baseName}.part_${chunkIndex}` );
|
|
4417
|
+
|
|
4418
|
+
fs.rename( uploadedChunk.tempFilePath, partPath, async ( err ) => {
|
|
4419
|
+
if ( err ) {
|
|
4420
|
+
return res.sendError( 'Chunk save failed', 500 );
|
|
4421
|
+
}
|
|
4422
|
+
|
|
4423
|
+
// If not final chunk
|
|
4424
|
+
if ( chunkIndex < totalChunks ) {
|
|
4425
|
+
return res.sendSuccess( { message: 'Chunk received', chunkIndex } );
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
// Final chunk received: Merge now
|
|
4429
|
+
try {
|
|
4430
|
+
const finalPath = join( UPLOAD_DIR, uploadedChunk.name );
|
|
4431
|
+
const writeStream = fs.createWriteStream( finalPath );
|
|
4432
|
+
|
|
4433
|
+
for ( let i = 1; i <= totalChunks; i++ ) {
|
|
4434
|
+
const chunkPath = join( UPLOAD_DIR, `${baseName}.part_${i}` );
|
|
4435
|
+
const data = await fsp.readFile( chunkPath );
|
|
4436
|
+
writeStream.write( data );
|
|
4437
|
+
await fsp.unlink( chunkPath ); // delete part after writing
|
|
4438
|
+
}
|
|
4439
|
+
|
|
4440
|
+
writeStream.end();
|
|
4441
|
+
|
|
4442
|
+
writeStream.on( 'finish', async () => {
|
|
4443
|
+
try {
|
|
4444
|
+
const fileData = await fsp.readFile( finalPath );
|
|
4445
|
+
|
|
4446
|
+
req.files.answerImage = {
|
|
4447
|
+
data: fileData,
|
|
4448
|
+
name: uploadedChunk.name,
|
|
4449
|
+
mimetype: uploadedChunk.mimetype,
|
|
4450
|
+
};
|
|
4451
|
+
|
|
4452
|
+
await fsp.unlink( finalPath );
|
|
4453
|
+
|
|
4454
|
+
uploadAnswerImage( req, res );
|
|
4455
|
+
} catch ( err ) {
|
|
4456
|
+
return res.sendError( 'Final file error', 500 );
|
|
4457
|
+
}
|
|
4458
|
+
} );
|
|
4459
|
+
} catch ( err ) {
|
|
4460
|
+
return res.sendError( 'Chunk merge failed', 500 );
|
|
4461
|
+
}
|
|
4462
|
+
} );
|
|
4463
|
+
} catch ( e ) {
|
|
4464
|
+
logger.error( { functionName: 'chunkUpload', error: e } );
|
|
4465
|
+
return res.sendError( e, 500 );
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
@@ -29,5 +29,6 @@ mobileRouter
|
|
|
29
29
|
.post( '/checkUpdateVersion', mobileController.checkVersion )
|
|
30
30
|
.post( '/checkUpdateVersionv1', mobileController.checkVersionV1 )
|
|
31
31
|
.post( '/checkClientConfig', isAllowedSessionHandler, mobileController.clientConfig )
|
|
32
|
-
.post( '/updatePlanoStatus', isAllowedSessionHandler, mobileController.updatePlanoStatus )
|
|
32
|
+
.post( '/updatePlanoStatus', isAllowedSessionHandler, mobileController.updatePlanoStatus )
|
|
33
|
+
.post( '/chunkUpload', isAllowedSessionHandler, mobileController.chunkUpload );
|
|
33
34
|
|