per domain uploads
This commit is contained in:
parent
723a22439f
commit
b5195b1a14
|
@ -2,6 +2,13 @@
|
|||
// Angular file upload hack
|
||||
//
|
||||
// TODO modularize for reuse
|
||||
function analyzeFile(file, vm) {
|
||||
vm.isZip = /\.zip$/.test(file.name);
|
||||
vm.unzip = vm.isZip;
|
||||
vm.stripZip = vm.isZip;
|
||||
return vm;
|
||||
}
|
||||
|
||||
function handleFiles(ev) {
|
||||
var selector = 'js-file-upload';
|
||||
var $scope;
|
||||
|
@ -15,10 +22,8 @@ function handleFiles(ev) {
|
|||
// 'vm' is the Controller As name.
|
||||
vm = $scope.vm;
|
||||
vm.currentFiles = ev.target.files;
|
||||
var file = vm.currentFiles[0];
|
||||
vm.isZip = /\.zip$/.test(file.name);
|
||||
vm.unzip = vm.isZip;
|
||||
vm.stripZip = vm.isZip;
|
||||
analyzeFile(vm.currentFiles[0], vm);
|
||||
|
||||
$scope.$digest();
|
||||
console.log('[handleFiles] vm.currentFiles:');
|
||||
console.log(vm.currentFiles);
|
||||
|
@ -46,7 +51,7 @@ app.controller('websiteCtrl', [
|
|||
var vm = this;
|
||||
vm.domains = [];
|
||||
//vm.unzipPath = '/';
|
||||
vm.webPath = '/';
|
||||
vm.uploadPath = '/';
|
||||
|
||||
Auth.api = function (apiname, opts) {
|
||||
var els = [];
|
||||
|
@ -154,26 +159,38 @@ app.controller('websiteCtrl', [
|
|||
vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', ''));
|
||||
};
|
||||
|
||||
vm._uploadFileVm = function (pkg, opts) {
|
||||
return vm._uploadFile(pkg, {
|
||||
domain: vm.currentHost
|
||||
, tld: vm.domain.tld
|
||||
, sld: vm.domain.sld
|
||||
, sub: vm.domain.sub
|
||||
, newFile: vm.currentFiles[0]
|
||||
, uploadPath: vm.uploadPath
|
||||
, progress: vm
|
||||
});
|
||||
};
|
||||
vm._uploadFile = function (pkg, opts) {
|
||||
opts.progress = opts.progress || opts;
|
||||
return pkg.add({
|
||||
hostname: opts.currentHost
|
||||
, domain: opts.currentHost
|
||||
, tld: opts.domain.tld
|
||||
, sld: opts.domain.sld
|
||||
hostname: opts.domain
|
||||
, domain: opts.domain
|
||||
, tld: opts.tld
|
||||
, sld: opts.sld
|
||||
//, sub: opts.record.sub
|
||||
, multipart: { site: opts.currentFiles[0] }
|
||||
, multipart: { site: opts.newFile }
|
||||
, progress: function (ev) {
|
||||
// TODO must digest
|
||||
opts.uploadPercent = Math.round((ev.loaded / ev.total) * 100);
|
||||
opts.progress.uploadPercent = Math.round((ev.loaded / ev.total) * 100);
|
||||
// TODO GiB, MiB, KiB, etc
|
||||
opts.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2);
|
||||
opts.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2);
|
||||
opts.progress.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2);
|
||||
opts.progress.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2);
|
||||
}
|
||||
, unzip: opts.unzip
|
||||
, strip: opts.stripZip
|
||||
, path: opts.webPath
|
||||
, path: opts.uploadPath
|
||||
}).then(function (result) {
|
||||
opts.uploadTotal = 0;
|
||||
opts.progress.uploadTotal = 0;
|
||||
window.alert(JSON.stringify(result));
|
||||
});
|
||||
};
|
||||
|
@ -225,7 +242,7 @@ app.controller('websiteCtrl', [
|
|||
if (vm.sites.some(function (r) {
|
||||
return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain));
|
||||
})) {
|
||||
vm._uploadFile(pkg, vm);
|
||||
vm._uploadFileVm(pkg, vm);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -270,7 +287,7 @@ app.controller('websiteCtrl', [
|
|||
|
||||
return prom.then(function () {
|
||||
return pkg.claim(domainReq).then(function (result) {
|
||||
return vm._uploadFile(pkg, vm);
|
||||
return vm._uploadFileVm(pkg, vm);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -278,10 +295,12 @@ app.controller('websiteCtrl', [
|
|||
};
|
||||
vm.Sites.setUpload = function (r) {
|
||||
console.log("Hey! At least it can tell if there's a change!");
|
||||
analyzeFile(r.newFile, r);
|
||||
console.log(r);
|
||||
};
|
||||
vm.Sites.upload = function (r) {
|
||||
var pkg = Auth.oauth3.pkg('www@daplie.com');
|
||||
//analyzeFile(r.newFile, r);
|
||||
vm._uploadFile(pkg, r);
|
||||
};
|
||||
vm.Sites.archive = function (r) {
|
||||
|
@ -293,7 +312,7 @@ app.controller('websiteCtrl', [
|
|||
, tld: r.tld
|
||||
, sld: r.sld
|
||||
//, sub: vm.record.sub
|
||||
//, path: vm.webPath
|
||||
//, path: vm.uploadPath
|
||||
}).then(function (result) {
|
||||
window.alert(JSON.stringify(result));
|
||||
// TODO use iframe to initiate download?
|
||||
|
@ -312,7 +331,7 @@ app.controller('websiteCtrl', [
|
|||
, tld: r.tld
|
||||
, sld: r.sld
|
||||
//, sub: vm.record.sub
|
||||
//, path: vm.webPath
|
||||
//, path: vm.uploadPath
|
||||
}).then(function (result) {
|
||||
window.alert(JSON.stringify(result));
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
<div ng-if="vm.uploadTotal"><span ng-bind="vm.uploadPercent">99</span>% | <span ng-bind="vm.uploadProgress">1</span> MiB / <span ng-bind="vm.uploadTotal">100</span> MiB</div>
|
||||
|
||||
<div><label>Web path</label> <input type="text" ng-model="vm.webPath" /></div>
|
||||
<div><label>Web path</label> <input type="text" ng-model="vm.uploadPath" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -119,7 +119,7 @@
|
|||
|
||||
<div ng-if="r.uploadTotal"><span ng-bind="r.uploadPercent">99</span>% | <span ng-bind="r.uploadProgress">1</span> MiB / <span ng-bind="r.uploadTotal">100</span> MiB</div>
|
||||
|
||||
<div><label>Web path</label> <input type="text" ng-model="r.webPath" /></div>
|
||||
<div><label>Web path</label> <input type="text" ng-model="r.uploadPath" /></div>
|
||||
|
||||
<button ng-click="vm.Sites.upload(r)" type="button" name="button" class="btn btn-default">Add File</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue