per domain uploads

This commit is contained in:
aj 2017-09-01 23:35:04 +00:00
parent 723a22439f
commit b5195b1a14
2 changed files with 40 additions and 21 deletions

View File

@ -2,6 +2,13 @@
// Angular file upload hack // Angular file upload hack
// //
// TODO modularize for reuse // 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) { function handleFiles(ev) {
var selector = 'js-file-upload'; var selector = 'js-file-upload';
var $scope; var $scope;
@ -15,10 +22,8 @@ function handleFiles(ev) {
// 'vm' is the Controller As name. // 'vm' is the Controller As name.
vm = $scope.vm; vm = $scope.vm;
vm.currentFiles = ev.target.files; vm.currentFiles = ev.target.files;
var file = vm.currentFiles[0]; analyzeFile(vm.currentFiles[0], vm);
vm.isZip = /\.zip$/.test(file.name);
vm.unzip = vm.isZip;
vm.stripZip = vm.isZip;
$scope.$digest(); $scope.$digest();
console.log('[handleFiles] vm.currentFiles:'); console.log('[handleFiles] vm.currentFiles:');
console.log(vm.currentFiles); console.log(vm.currentFiles);
@ -46,7 +51,7 @@ app.controller('websiteCtrl', [
var vm = this; var vm = this;
vm.domains = []; vm.domains = [];
//vm.unzipPath = '/'; //vm.unzipPath = '/';
vm.webPath = '/'; vm.uploadPath = '/';
Auth.api = function (apiname, opts) { Auth.api = function (apiname, opts) {
var els = []; var els = [];
@ -154,26 +159,38 @@ app.controller('websiteCtrl', [
vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', '')); 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) { vm._uploadFile = function (pkg, opts) {
opts.progress = opts.progress || opts;
return pkg.add({ return pkg.add({
hostname: opts.currentHost hostname: opts.domain
, domain: opts.currentHost , domain: opts.domain
, tld: opts.domain.tld , tld: opts.tld
, sld: opts.domain.sld , sld: opts.sld
//, sub: opts.record.sub //, sub: opts.record.sub
, multipart: { site: opts.currentFiles[0] } , multipart: { site: opts.newFile }
, progress: function (ev) { , progress: function (ev) {
// TODO must digest // 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 // TODO GiB, MiB, KiB, etc
opts.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2); opts.progress.uploadTotal = (ev.total / (1024 * 1024)).toFixed(2);
opts.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2); opts.progress.uploadProgress = (ev.loaded / (1024 * 1024)).toFixed(2);
} }
, unzip: opts.unzip , unzip: opts.unzip
, strip: opts.stripZip , strip: opts.stripZip
, path: opts.webPath , path: opts.uploadPath
}).then(function (result) { }).then(function (result) {
opts.uploadTotal = 0; opts.progress.uploadTotal = 0;
window.alert(JSON.stringify(result)); window.alert(JSON.stringify(result));
}); });
}; };
@ -225,7 +242,7 @@ app.controller('websiteCtrl', [
if (vm.sites.some(function (r) { if (vm.sites.some(function (r) {
return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain)); return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain));
})) { })) {
vm._uploadFile(pkg, vm); vm._uploadFileVm(pkg, vm);
return; return;
} }
@ -270,7 +287,7 @@ app.controller('websiteCtrl', [
return prom.then(function () { return prom.then(function () {
return pkg.claim(domainReq).then(function (result) { 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) { vm.Sites.setUpload = function (r) {
console.log("Hey! At least it can tell if there's a change!"); console.log("Hey! At least it can tell if there's a change!");
analyzeFile(r.newFile, r);
console.log(r); console.log(r);
}; };
vm.Sites.upload = function (r) { vm.Sites.upload = function (r) {
var pkg = Auth.oauth3.pkg('www@daplie.com'); var pkg = Auth.oauth3.pkg('www@daplie.com');
//analyzeFile(r.newFile, r);
vm._uploadFile(pkg, r); vm._uploadFile(pkg, r);
}; };
vm.Sites.archive = function (r) { vm.Sites.archive = function (r) {
@ -293,7 +312,7 @@ app.controller('websiteCtrl', [
, tld: r.tld , tld: r.tld
, sld: r.sld , sld: r.sld
//, sub: vm.record.sub //, sub: vm.record.sub
//, path: vm.webPath //, path: vm.uploadPath
}).then(function (result) { }).then(function (result) {
window.alert(JSON.stringify(result)); window.alert(JSON.stringify(result));
// TODO use iframe to initiate download? // TODO use iframe to initiate download?
@ -312,7 +331,7 @@ app.controller('websiteCtrl', [
, tld: r.tld , tld: r.tld
, sld: r.sld , sld: r.sld
//, sub: vm.record.sub //, sub: vm.record.sub
//, path: vm.webPath //, path: vm.uploadPath
}).then(function (result) { }).then(function (result) {
window.alert(JSON.stringify(result)); window.alert(JSON.stringify(result));
}); });

View File

@ -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 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> </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 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> <button ng-click="vm.Sites.upload(r)" type="button" name="button" class="btn btn-default">Add File</button>
</div> </div>