Prettify
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const SRIToolbox = require('sri-toolbox')
|
||||
const getFileContentType = require('./getFileContentType')
|
||||
const getFileStats = require('./getFileStats')
|
||||
const getFileType = require('./getFileType')
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const SRIToolbox = require("sri-toolbox")
|
||||
const getFileContentType = require("./getFileContentType")
|
||||
const getFileStats = require("./getFileStats")
|
||||
const getFileType = require("./getFileType")
|
||||
|
||||
function getEntries(dir, file, maximumDepth) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -12,17 +12,10 @@ function getEntries(dir, file, maximumDepth) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(
|
||||
Promise.all(
|
||||
files.map(f => getFileStats(path.join(dir, file, f)))
|
||||
).then(statsArray => {
|
||||
Promise.all(files.map(f => getFileStats(path.join(dir, file, f)))).then(statsArray => {
|
||||
return Promise.all(
|
||||
statsArray.map((stats, index) =>
|
||||
getMetadataRecursive(
|
||||
dir,
|
||||
path.join(file, files[index]),
|
||||
stats,
|
||||
maximumDepth - 1
|
||||
)
|
||||
getMetadataRecursive(dir, path.join(file, files[index]), stats, maximumDepth - 1)
|
||||
)
|
||||
)
|
||||
})
|
||||
@ -42,7 +35,7 @@ function getIntegrity(file) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(SRIToolbox.generate({ algorithms: ['sha384'] }, data))
|
||||
resolve(SRIToolbox.generate({ algorithms: ["sha384"] }, data))
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -64,8 +57,7 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
})
|
||||
}
|
||||
|
||||
if (!stats.isDirectory() || maximumDepth === 0)
|
||||
return Promise.resolve(metadata)
|
||||
if (!stats.isDirectory() || maximumDepth === 0) return Promise.resolve(metadata)
|
||||
|
||||
return getEntries(dir, file, maximumDepth).then(files => {
|
||||
metadata.files = files
|
||||
@ -74,12 +66,9 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
}
|
||||
|
||||
function getMetadata(baseDir, path, stats, maximumDepth, callback) {
|
||||
getMetadataRecursive(baseDir, path, stats, maximumDepth).then(function(
|
||||
metadata
|
||||
) {
|
||||
getMetadataRecursive(baseDir, path, stats, maximumDepth).then(function(metadata) {
|
||||
callback(null, metadata)
|
||||
},
|
||||
callback)
|
||||
}, callback)
|
||||
}
|
||||
|
||||
module.exports = getMetadata
|
||||
|
||||
Reference in New Issue
Block a user