-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCS-99643 Add max file size and file methods
- Loading branch information
Ivan Kudinov
committed
Jul 9, 2024
1 parent
4d0574e
commit 246186d
Showing
6 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import bridge from '@expressms/smartapp-bridge' | ||
import { | ||
ERROR_CODES, | ||
File, | ||
METHODS, | ||
} from '../../types' | ||
|
||
/** | ||
* Download and open single file with client | ||
* @param file File data to be opened | ||
* @returns Promise that'll be fullfilled, otherwise rejected with reason | ||
*/ | ||
const openFile = (file: File) => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge.sendClientEvent({ | ||
method: METHODS.OPEN_FILE, | ||
params: file, | ||
}) | ||
} | ||
|
||
/** | ||
* Download file list with client | ||
* @param files Files list to be opened | ||
* @returns Promise that'll be fullfilled, otherwise rejected with reason | ||
*/ | ||
const openFiles = (files: File[]) => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge.sendClientEvent({ | ||
method: METHODS.OPEN_FILES, | ||
params: files, | ||
}) | ||
} | ||
|
||
|
||
|
||
/** | ||
* Upload single file with client | ||
* @param mimeType Mime type of allowed files | ||
* @param maxSize Max file size in bytes | ||
* @returns Promise that'll be fullfilled with file metadata on success, otherwise rejected with reason | ||
*/ | ||
const uploadFile = ({ mimeType, maxSize }: { mimeType: string, maxSize?: number }) => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge.sendClientEvent({ | ||
method: METHODS.UPLOAD_FILE, | ||
params: { | ||
type: mimeType, | ||
maxSize, | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Upload files list with client | ||
* @param mimeType Mime type of allowed files | ||
* @param maxSize Max file size in bytes | ||
* @returns Promise that'll be fullfilled with files metadata on success, otherwise rejected with reason | ||
*/ | ||
const uploadFiles = ({ mimeType, maxSize }: { mimeType: string, maxSize?: number }) => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge.sendClientEvent({ | ||
method: METHODS.UPLOAD_FILES, | ||
params: { | ||
type: mimeType, | ||
maxSize, | ||
}, | ||
}) | ||
} | ||
|
||
export { | ||
openFile, | ||
openFiles, | ||
uploadFile, | ||
uploadFiles, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters