Skip to content

Commit

Permalink
Merge pull request #710 from adaptlearning/feature/#709
Browse files Browse the repository at this point in the history
Separate the setting of assetType and metadata
  • Loading branch information
brian-learningpool committed Jul 2, 2015
2 parents 07c5e37 + 47d615d commit d6d13f8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@
</div>

{{#ifValueEquals assetType "image"}}
<div class="asset-management-list-item-image" data-style="background-image:url(api/asset/thumb/{{_id}})">
{{#if metadata}}
<div class="asset-management-list-item-image" data-style="background-image:url(api/asset/thumb/{{_id}})">
{{else}}
<div class="asset-management-list-item-image">
<i class="fa fa-file-image-o"></i>
</div>
{{/if}}
</div>
{{/ifValueEquals}}

{{#ifValueEquals assetType "video"}}
<div class="asset-management-list-item-image" data-style="background-image:url(api/asset/thumb/{{_id}})">
{{#if metadata}}
<div class="asset-management-list-item-image" data-style="background-image:url(api/asset/thumb/{{_id}})"}>
{{else}}
<div class="asset-management-list-item-image">
<i class="fa fa-file-video-o"></i>
</div>
{{/if}}
</div>
{{/ifValueEquals}}

Expand Down
11 changes: 10 additions & 1 deletion plugins/content/bower/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,16 @@ function handleUploadedPlugin (req, res, next) {

// first entry should be our target directory
var packageJson;
var canonicalDir = path.join(outputPath, files[0]);
var canonicalDir;

if (files.indexOf("bower.json") != -1) {
// We're at the root level so the zip file is in the expected format
canonicalDir = outputPath
}
else {
return next(new Error('Cannot find expected bower.json file in the plugin root, please check the structure of your zip file and try again.'));
}

try {
packageJson = require(path.join(canonicalDir, 'bower.json'));
} catch (error) {
Expand Down
69 changes: 39 additions & 30 deletions plugins/filestorage/localfs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,44 +373,53 @@ LocalFileStorage.prototype.createThumbnail = function (filePath, fileType, optio

LocalFileStorage.prototype.inspectFile = function (filePath, fileType, next) {
var data = {
assetType : fileType.substr(0, fileType.indexOf('/')),
metadata : null
assetType: null,
metadata: null
};


fileType = fileType.split('/')[0];

switch (fileType) {
case 'image':
case 'video':
case 'audio':
data.assetType = fileType;
break;
default:
data.assetType = 'other';
break;
}

// early return if we can't create thumbnails
if (!configuration.getConfig('useffmpeg')) {
return next(null, data);
}

fileType = fileType.split('/')[0];

// Interrogate the uploaded file
probe(filePath, function (err, probeData) {
// Derive assetType and (if available) store extra metadata depending on the type of file uploaded
switch (fileType) {
case 'image':
data.assetType = 'image';
data.metadata = probeData
? { width: probeData.streams[0].width, height: probeData.streams[0].height}
: null;
break;
case 'video':
data.assetType = 'video';
data.metadata = probeData
? {duration: probeData.streams[0].duration, width: probeData.streams[0].width, height: probeData.streams[0].height}
: null;
break;
case 'audio':
data.assetType = 'audio';
data.metadata = probeData
? {duration: probeData.streams[0].duration}
: null;
break;
default:
data.assetType = 'other';
data.metadata = null;
break;
if (probeData) {
// Store extra metadata depending on the type of file uploaded
switch (fileType) {
case 'image':
data.metadata = {
width: probeData.streams[0].width,
height: probeData.streams[0].height
}
break;
case 'video':
data.metadata = {
duration: probeData.streams[0].duration,
width: probeData.streams[0].width,
height: probeData.streams[0].height
}
break;
case 'audio':
data.metadata = {
duration: probeData.streams[0].duration
}
break;
}
}

return next(null, data);
});
};
Expand Down

0 comments on commit d6d13f8

Please sign in to comment.