diff --git a/app/components/services/oss2.js b/app/components/services/oss2.js index 278562c9..b54bcc4f 100644 --- a/app/components/services/oss2.js +++ b/app/components/services/oss2.js @@ -6,6 +6,7 @@ angular.module('web') var DEF_ADDR = 'oss://'; //var ALY = require('aliyun-sdk'); var path = require('path'); + var AliOSS = require('ali-oss'); return { createFolder: createFolder, @@ -13,9 +14,10 @@ angular.module('web') restoreFile: restoreFile, loadStorageStatus: loadStorageStatus, - getMeta: getMeta, - getFileInfo: getMeta, //head object + getMeta: getMeta2, + getFileInfo: getMeta2, //head object setMeta: setMeta, + setMeta2: setMeta2, checkFileExists: checkFileExists, checkFolderExists: checkFolderExists, @@ -75,6 +77,25 @@ angular.module('web') return client; } + function getClient3(opt){ + const options = prepaireOptions(opt); + const final = { + accessKeyId: options.accessKeyId, + accessKeySecret: options.secretAccessKey, + bucket: opt.bucket, + endpoint: options.endpoint, + region: opt.region, + timeout: options.httpOptions.timeout, + cname: options.cname, + isRequestPay: options.isRequestPayer + } + if(options.hasOwnProperty('securityToken')) { + final.stsToken = options.securityToken + } + const client = new AliOSS(final) + return client + } + function signatureUrl2(region, bucket, key, expires, xprocess) { var client = getClient2({ region: region, @@ -1031,6 +1052,109 @@ angular.module('web') }); } + function getMeta2(region, bucket, key) { + const client = getClient3({ region, bucket }); + function adapter(obj) { + const outputStructure = { + AcceptRanges: { + name: "accept-ranges", + }, + CacheControl: { + name: "Cache-Control", + }, + ContentDisposition: { + name: "Content-Disposition", + }, + ContentEncoding: { + name: "Content-Encoding", + }, + ContentLanguage: { + name: "Content-Language", + }, + ContentLength: { + type: "integer", + name: "Content-Length", + }, + ContentType: { + name: "Content-Type", + }, + DeleteMarker: { + type: "boolean", + name: "x-oss-delete-marker", + }, + ETag: { + name: "ETag", + }, + Expiration: { + name: "x-oss-expiration", + }, + Expires: { + type: "timestamp", + name: "Expires", + }, + LastModified: { + type: "timestamp", + name: "Last-Modified", + }, + // "Metadata": { + // "type": "map", + // "name": "x-oss-meta-", + // "members": {}, + // "keys": {} + // }, + // MissingMeta: { + // type: "integer", + // name: "x-oss-missing-meta", + // }, + Restore: { + name: "x-oss-restore", + }, + ServerSideEncryption: { + name: "x-oss-server-side-encryption", + }, + VersionId: { + name: "x-oss-version-id", + }, + WebsiteRedirectLocation: { + name: "x-oss-website-redirect-location", + }, + }; + const output = { + Metadata: obj.meta, + }; + const { hasOwnProperty } = Object.prototype; + const headers = obj.res.headers; + // extract output + for (let key in outputStructure) { + if (hasOwnProperty.call(outputStructure, key)) { + const name = outputStructure[key].name.toLowerCase(); + if (headers[name] !== undefined) { + output[key] = headers[name]; + } + } + } + // extract x-oss-... + for (let key in headers) { + if (key.indexOf("x-oss-") == 0) { + let arr = key.substring("x-oss-".length).split("-"); + for (let i = 0; i < arr.length; i++) { + arr[i] = arr[i][0].toUpperCase() + arr[i].substring(1); + } + output[arr.join("")] = headers[key]; + } else if (key === "content-md5") { + output["ContentMD5"] = headers["content-md5"]; + } + } + // extract requestId + output.RequestId = + headers["x-oss-request-id"] || headers["x-oss-requestid"]; + return output; + } + return client.head(key).then((res) => { + return adapter(res); + }); + } + function setMeta(region, bucket, key, headers, metas) { return new Promise(function (a, b) { var client = getClient({ @@ -1064,6 +1188,14 @@ angular.module('web') }); } + function setMeta2(region, bucket, key, headers, meta) { + const client = getClient2({region , bucket}); + return client.copy(key, key, { + headers, + meta + }).catch(handleError) + } + function restoreFile(region, bucket, key, days) { return new Promise(function (a, b) { diff --git a/app/main/files/_/file-toolbar.html b/app/main/files/_/file-toolbar.html index 8e085b3d..f8dc0584 100644 --- a/app/main/files/_/file-toolbar.html +++ b/app/main/files/_/file-toolbar.html @@ -120,7 +120,7 @@
  • - + {{'http.headers'|translate}} diff --git a/app/main/files/files.js b/app/main/files/files.js index 93da6434..f948e77f 100644 --- a/app/main/files/files.js +++ b/app/main/files/files.js @@ -1,4 +1,7 @@ angular.module('web') +.filter('canSetHeader', function() { + return sel => sel && sel.has && sel.has.length && sel.has.every(f => !f.isFolder); +}) .controller('filesCtrl', ['$scope', '$rootScope', '$uibModal', '$timeout','$translate', 'AuthInfo', 'ossSvs2', 'settingsSvs', 'fileSvs', 'safeApply', 'Toast', 'Dialog', function ($scope, $rootScope, $modal, $timeout, $translate, AuthInfo, ossSvs2, settingsSvs, fileSvs, safeApply, Toast, Dialog) { var T = $translate.instant; @@ -234,9 +237,9 @@ angular.module('web') //Http头 return ' ' + T('http.headers') }, function ($itemScope, $event) { - showHttpHeaders($scope.sel.has[0]) + showHttpHeaders($scope.sel.has) }, function(){ - return $scope.sel.has && $scope.sel.has.length==1 && !$scope.sel.has[0].isFolder; + return $scope.sel.has && $scope.sel.has.length && $scope.sel.has.every(f => !f.isFolder); }], [function(){ @@ -1111,7 +1114,7 @@ angular.module('web') controller: 'updateHttpHeadersModalCtrl', resolve: { item: function () { - return angular.copy(item); + return angular.copy(Array.isArray(item) ? item : [item]); }, currentInfo: function () { return angular.copy($scope.currentInfo); @@ -1193,4 +1196,4 @@ angular.module('web') } - ]); + ]); \ No newline at end of file diff --git a/app/main/files/modals/update-http-headers-modal.js b/app/main/files/modals/update-http-headers-modal.js index 8ea5137f..1ed2b2ec 100644 --- a/app/main/files/modals/update-http-headers-modal.js +++ b/app/main/files/modals/update-http-headers-modal.js @@ -22,9 +22,8 @@ angular.module('web') $scope.isLoading = true; $scope.step=2; var ignoreError = true; - - ossSvs2.getMeta(currentInfo.region, currentInfo.bucket, item.path).then(function(result){ - + if(item.length > 1) return; + ossSvs2.getMeta(currentInfo.region, currentInfo.bucket, item[0].path).then(function(result){ $scope.headers = { 'ContentLanguage': result.ContentLanguage, 'ContentType': result.ContentType, @@ -63,11 +62,10 @@ angular.module('web') }); //console.log(headers, metas) Toast.info(T('setting.on')); //'正在设置..' - - ossSvs2.setMeta(currentInfo.region, currentInfo.bucket, item.path, headers, metas).then(function(result){ + Promise.all(item.map(i => ossSvs2.setMeta2(currentInfo.region, currentInfo.bucket, i.path, headers, metas))).then(result => { Toast.success(T('setting.success')); //'设置成功' + }).finally(() => { cancel(); - }); }