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 @@