From f0c80840a1915a83eae76332dbc7860e54c81f26 Mon Sep 17 00:00:00 2001 From: tianjiaxing Date: Thu, 24 Jun 2021 20:19:53 +0800 Subject: [PATCH] feat(App): saveVideoToPhotosAlbum --- .../protocols/media/saveVideoToPhotosAlbum.ts | 18 +++++++++++++ .../uni-app-plus/src/service/api/index.ts | 1 + .../api/media/saveVideoToPhotosAlbum.ts | 25 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 packages/uni-app-plus/src/service/api/media/saveVideoToPhotosAlbum.ts diff --git a/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts b/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts index e15579aba..8356c41f0 100644 --- a/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts +++ b/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts @@ -1,3 +1,21 @@ +import { getRealPath } from '@dcloudio/uni-platform' export const API_SAVE_VIDEO_TO_PHOTOS_ALBUM = 'saveVideoToPhotosAlbum' export type API_TYPE_SAVE_VIDEO_TO_PHOTOS_ALBUM = typeof uni.saveVideoToPhotosAlbum + +export const SaveVideoToPhotosAlbumOptions: ApiOptions = + { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath) + }, + }, + } + +export const SaveVideoToPhotosAlbumProtocol: ApiProtocol = + { + filePath: { + type: String, + required: true, + }, + } diff --git a/packages/uni-app-plus/src/service/api/index.ts b/packages/uni-app-plus/src/service/api/index.ts index fcbb709a0..a324801eb 100644 --- a/packages/uni-app-plus/src/service/api/index.ts +++ b/packages/uni-app-plus/src/service/api/index.ts @@ -13,6 +13,7 @@ export * from './media/getImageInfo' export * from './media/getVideoInfo' export * from './media/previewImage' export * from './media/getRecorderManager' +export * from './media/saveVideoToPhotosAlbum' export * from './keyboard/keyboard' diff --git a/packages/uni-app-plus/src/service/api/media/saveVideoToPhotosAlbum.ts b/packages/uni-app-plus/src/service/api/media/saveVideoToPhotosAlbum.ts new file mode 100644 index 000000000..a216e2cc6 --- /dev/null +++ b/packages/uni-app-plus/src/service/api/media/saveVideoToPhotosAlbum.ts @@ -0,0 +1,25 @@ +import { + API_SAVE_VIDEO_TO_PHOTOS_ALBUM, + API_TYPE_SAVE_VIDEO_TO_PHOTOS_ALBUM, + defineAsyncApi, + SaveVideoToPhotosAlbumOptions, + SaveVideoToPhotosAlbumProtocol, +} from '@dcloudio/uni-api' +import { + warpPlusSuccessCallback, + warpPlusErrorCallback, +} from '../../../helpers/plus' + +export const saveVideoToPhotosAlbum = + defineAsyncApi( + API_SAVE_VIDEO_TO_PHOTOS_ALBUM, + (options, { resolve, reject }) => { + plus.gallery.save( + options.filePath, + (e) => warpPlusSuccessCallback(resolve), + (e) => warpPlusErrorCallback(reject) + ) + }, + SaveVideoToPhotosAlbumProtocol, + SaveVideoToPhotosAlbumOptions + ) -- GitLab