Download wp-calypso/client/data/media/use-add-external-media.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/media/use-add-external-media.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/media/use-add-external-media.js
-
curl -L -o use-add-external-media.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/media/use-add-external-media.js
664 Bytes
| import { useCallback } from 'react'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import { useUploadMediaMutation } from './use-upload-media-mutation'; | |
| const getExternalUploader = | |
| ( service ) => | |
| ( file, siteId, postId = 0 ) => | |
| wpcom.req.post( `/sites/${ siteId }/external-media-upload`, { | |
| external_ids: [ file.guid ], | |
| service, | |
| post_id: postId, | |
| } ); | |
| export const useAddExternalMedia = () => { | |
| const { uploadMediaAsync } = useUploadMediaMutation(); | |
| return useCallback( | |
| ( file, site, postId, service ) => { | |
| const uploader = getExternalUploader( service ); | |
| return uploadMediaAsync( file, site, postId, uploader ); | |
| }, | |
| [ uploadMediaAsync ] | |
| ); | |
| }; | |