From a70a58ff2003ea4f5aca96b4f0e6dcfd3f3a5611 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 6 Feb 2021 16:22:56 -0600 Subject: [PATCH] Save scans --- helpers/app-files-scanner.js | 75 +++++++++++++++++++++++++++++++++++- nuxt.config.js | 3 +- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/helpers/app-files-scanner.js b/helpers/app-files-scanner.js index b5540cd..affe93b 100644 --- a/helpers/app-files-scanner.js +++ b/helpers/app-files-scanner.js @@ -1,4 +1,5 @@ import plist from 'plist' +import axios from 'axios' import parseMacho from './macho/index.js' @@ -58,10 +59,15 @@ let zip export default class AppFilesScanner { - constructor( { observableFilesArray } ) { + constructor( { + observableFilesArray, + testResultStore + } ) { // Files to process this.files = observableFilesArray + this.testResultStore = testResultStore + // https://gildas-lormeau.github.io/zip.js/ zip = require('@zip.js/zip.js') @@ -277,8 +283,26 @@ export default class AppFilesScanner { } - submitScanInfo () { + async submitScanInfo ({ + filename, + appVersion, + result, + machoMeta, + infoPlist + }) { // Each file scanned: Filename, Type(Drop or URL), File URL, Datetime, Architectures, Mach-o Meta + + console.log( 'this.testResultStore', this.testResultStore ) + + await axios.post( this.testResultStore , { + filename, + appVersion, + result, + machoMeta: JSON.stringify( machoMeta ), + infoPlist: JSON.stringify( infoPlist ) + }).catch(function (error) { + console.error(error) + }) } async scanFile ( file, scanIndex ) { @@ -308,6 +332,14 @@ export default class AppFilesScanner { } catch ( Error ) { // console.warn( Error ) + this.submitScanInfo ({ + filename: file.name, + appVersion: null, + result: 'error_decompression_error', + machoMeta: null, + infoPlist: null + }) + // Set status message as error file.statusMessage = `❔ ${ Error.message }` file.status = 'finished' @@ -336,6 +368,14 @@ export default class AppFilesScanner { if ( file.machOEntries.length === 0 ) { console.log(`No Macho files found for ${file.name}`, file.machOEntries) + this.submitScanInfo ({ + filename: file.name, + appVersion: null, + result: 'error_no_macho_files', + machoMeta: null, + infoPlist: null + }) + file.statusMessage = `❔ Unkown app format` file.status = 'finished' @@ -474,6 +514,37 @@ export default class AppFilesScanner { this.files.unshift( this.files.splice( scanIndex, 1 )[0] ) } + // console.log('parsedMachoEntries', JSON.parse( JSON.stringify(parsedMachoEntries) )) + console.log( 'parsedMachoEntries', parsedMachoEntries ) + + this.submitScanInfo ({ + filename: file.name, + appVersion: file.appVersion, + result: file.statusMessage, + machoMeta: parsedMachoEntries.map( machoMeta => { + + const architectures = machoMeta.architectures.map( architecture => { + return { + bits: architecture.bits, + fileType: architecture.fileType, + header: architecture.header, + loadCommandsInfo: architecture.loadCommandsInfo, + magic: architecture.magic, + offset: architecture.offset, + processorSubType: architecture.processorSubType, + processorType: architecture.processorType, + } + }) + + return { + ...machoMeta, + file: undefined, // Remove file + architectures + } + }), + infoPlist: info + }) + file.status = 'finished' return diff --git a/nuxt.config.js b/nuxt.config.js index c97150b..ed2346f 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -95,7 +95,8 @@ export default { target: 'static', publicRuntimeConfig: { - allUpdateSubscribe: process.env.ALL_UPDATE_SUBSCRIBE + allUpdateSubscribe: process.env.ALL_UPDATE_SUBSCRIBE, + testResultStore: process.env.TEST_RESULT_STORE }, /*