Skip to content

Commit ef47341

Browse files
authored
Merge pull request #109 from adaptlearning/issue/92
allow a tagged version of the framework to be used to create a course
2 parents 84f04d8 + 8a1011f commit ef47341

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

lib/RepositoryDownloader.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ RepositoryDownloader.prototype.fetch = function(destination) {
2020
download = require('download'),
2121
totalSize,
2222
receivedSize,
23-
previousPercent = 0;
23+
previousPercent = 0,
24+
fileName = '';
2425

2526
download(this.url, destination, {
2627
extract: true
2728
})
2829
.on('response', function (response) {
2930
totalSize = Number(response.headers['content-length']);
31+
fileName = getFileName(response.headers['content-disposition']);
3032
receivedSize = 0;
3133
})
3234
.on('data', function(data) {
@@ -46,11 +48,23 @@ RepositoryDownloader.prototype.fetch = function(destination) {
4648
deferred.reject(err);
4749
})
4850
.then(function() {
49-
deferred.resolve(destination);
51+
deferred.resolve(fileName);
5052
});
5153

5254
return deferred.promise;
5355
};
5456

57+
function getFileName(disposition) {
58+
var fileName = "";
59+
if (disposition && disposition.indexOf('attachment') !== -1) {
60+
var regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
61+
var matches = regex.exec(disposition);
62+
if (matches != null && matches[1]) {
63+
fileName = matches[1].replace(/['"]/g, '');
64+
}
65+
}
66+
return fileName;
67+
}
68+
5569
module.exports = RepositoryDownloader;
5670

lib/commands/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function confirm(properties) {
6666
required: true
6767
},
6868
branch: {
69-
description: 'branch',
69+
description: 'branch/tag',
7070
pattern: /\w/,
7171
type: 'string',
7272
default: properties.branch || 'not specified',

lib/promise/getRepository.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ module.exports = function (properties) {
99
repository: properties.repository || Constants.FrameworkRepository,
1010
branch : properties.branch
1111
}),
12-
tmp = properties.tmp = path.join(Constants.HomeDirectory, '.adapt', 'tmp', uuid.v1()),
13-
downloadedSource = path.join(tmp, (properties.repositoryName || Constants.FrameworkRepositoryName) + '-' + properties.branch);
12+
tmp = properties.tmp = path.join(Constants.HomeDirectory, '.adapt', 'tmp', uuid.v1());
1413

1514
return downloader.fetch(tmp)
16-
.then(function () {
17-
return fs.copyTree(downloadedSource, properties.localDir)
15+
.then(function (fileName) {
16+
return fs.copyTree(getDownloadedSourcePath(properties, fileName), properties.localDir)
1817
.then(function () {
1918
return properties;
2019
});
2120
});
22-
};
21+
};
22+
23+
function getDownloadedSourcePath(properties, fileName) {
24+
var fName = fileName ? fs.base(fileName, fs.extension(fileName)) : ((properties.repositoryName || Constants.FrameworkRepositoryName) + '-' + properties.branch);
25+
return path.join(properties.tmp, fName);
26+
}

0 commit comments

Comments
 (0)