From 55bdf71c21567d3c8cd4a9e1f1f7daee747721f2 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 14 May 2019 21:08:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0API=EF=BC=9Auni.base6?= =?UTF-8?q?4ToArrayBuffer=E3=80=81uni.arrayBufferToBase64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 9 +++++---- src/core/helpers/promise.js | 26 +++++++++++++------------- src/core/helpers/protocol/base64.js | 11 +++++++++++ src/core/service/api/base64.js | 4 ++++ 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 src/core/helpers/protocol/base64.js create mode 100644 src/core/service/api/base64.js diff --git a/package.json b/package.json index 9ab868b0b3..52a142a1c4 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@vue/test-utils": "^1.0.0-beta.25", "babel-eslint": "^10.0.1", "babylon": "^6.18.0", + "base64-arraybuffer": "^0.2.0", "browserslist": "^4.4.2", "caniuse-lite": "^1.0.30000940", "chai": "^4.1.2", @@ -59,8 +60,8 @@ "globals": { "App": true, "Page": true, - "Component": true, - "Behavior":true, + "Component": true, + "Behavior": true, "getApp": true, "getCurrentPages": true, "plus": true, @@ -76,8 +77,8 @@ "__PLATFORM__": true, "__VERSION__": true, "__GLOBAL__": true, - "__PLATFORM_TITLE__": true, - "__PLATFORM_PREFIX__":true + "__PLATFORM_TITLE__": true, + "__PLATFORM_PREFIX__": true }, "rules": { "no-tabs": 0, diff --git a/src/core/helpers/promise.js b/src/core/helpers/promise.js index f237401716..f83f3cc15d 100644 --- a/src/core/helpers/promise.js +++ b/src/core/helpers/promise.js @@ -2,7 +2,7 @@ import { isFn } from 'uni-shared' -const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/ +const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/ const CONTEXT_API_RE = /^create|Manager$/ @@ -56,18 +56,18 @@ export function promisify (name, api) { success: resolve, fail: reject }), ...params) - /* eslint-disable no-extend-native */ - if (!Promise.prototype.finally) { - Promise.prototype.finally = function (callback) { - const promise = this.constructor - return this.then( - value => promise.resolve(callback()).then(() => value), - reason => promise.resolve(callback()).then(() => { - throw reason - }) - ) - } + /* eslint-disable no-extend-native */ + if (!Promise.prototype.finally) { + Promise.prototype.finally = function (callback) { + const promise = this.constructor + return this.then( + value => promise.resolve(callback()).then(() => value), + reason => promise.resolve(callback()).then(() => { + throw reason + }) + ) + } } })) } -} +} diff --git a/src/core/helpers/protocol/base64.js b/src/core/helpers/protocol/base64.js new file mode 100644 index 0000000000..9513a7a98d --- /dev/null +++ b/src/core/helpers/protocol/base64.js @@ -0,0 +1,11 @@ +export const base64ToArrayBuffer = [{ + name: 'base64', + type: String, + required: true +}] + +export const arrayBufferToBase64 = [{ + name: 'arrayBuffer', + type: [ArrayBuffer, Uint8Array], + required: true +}] diff --git a/src/core/service/api/base64.js b/src/core/service/api/base64.js new file mode 100644 index 0000000000..3164fe4c18 --- /dev/null +++ b/src/core/service/api/base64.js @@ -0,0 +1,4 @@ +import { encode, decode } from 'base64-arraybuffer' + +export const base64ToArrayBuffer = decode +export const arrayBufferToBase64 = encode -- GitLab