diff --git a/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts b/packages/uni-api/src/protocols/media/saveVideoToPhotosAlbum.ts index e15579abae3ed99f237318180fd4efbbfca3a795..8356c41f02d6bb20775d47187c5bd6d143f63155 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 fcbb709a041bf6c959d91f3f7d3f4e957fb2fdcb..a324801ebcea6f444bba50d5bc8d634760e31d78 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 0000000000000000000000000000000000000000..a216e2cc619d899a44d540424ece43205707cc84 --- /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 + )