2018-03-26 23:32:43 +02:00
// @flow
2018-10-29 18:23:53 +01:00
import * as MODALS from 'constants/modal_types' ;
2019-07-12 16:58:24 +02:00
import * as ACTIONS from 'constants/action_types' ;
2019-10-23 21:39:51 +02:00
import * as PAGES from 'constants/pages' ;
2021-10-17 10:36:14 +02:00
import { batchActions } from 'util/batch-actions' ;
2022-01-13 06:10:55 +01:00
import { THUMBNAIL _CDN _SIZE _LIMIT _BYTES } from 'config' ;
2021-10-17 10:36:14 +02:00
import { doCheckPendingClaims } from 'redux/actions/claims' ;
2020-04-24 15:51:00 +02:00
import {
2021-03-30 01:05:18 +02:00
makeSelectClaimForUri ,
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
selectMyActiveClaims ,
2021-10-17 10:36:14 +02:00
selectMyClaims ,
selectMyChannelClaims ,
// selectMyClaimsWithoutChannels,
selectReflectingById ,
} from 'redux/selectors/claims' ;
import { makeSelectPublishFormValue , selectPublishFormValues , selectMyClaimForUri } from 'redux/selectors/publish' ;
2020-06-12 22:44:25 +02:00
import { doError } from 'redux/actions/notifications' ;
2019-07-13 04:59:45 +02:00
import { push } from 'connected-react-router' ;
import analytics from 'analytics' ;
2022-02-01 21:11:35 +01:00
import { doOpenModal , doSetIncognito , doSetActiveChannel } from 'redux/actions/app' ;
2021-10-17 10:36:14 +02:00
import { CC _LICENSES , COPYRIGHT , OTHER , NONE , PUBLIC _DOMAIN } from 'constants/licenses' ;
2021-12-13 07:45:27 +01:00
import { IMG _CDN _PUBLISH _URL , IMG _CDN _STATUS _URL } from 'constants/cdn_urls' ;
2021-10-17 10:36:14 +02:00
import * as THUMBNAIL _STATUSES from 'constants/thumbnail_upload_statuses' ;
import { creditsToString } from 'util/format-credits' ;
import Lbry from 'lbry' ;
// import LbryFirst from 'extras/lbry-first/lbry-first';
import { isClaimNsfw } from 'util/claim' ;
2021-12-23 19:21:25 +01:00
import { LBRY _FIRST _TAG , SCHEDULED _LIVESTREAM _TAG } from 'constants/tags' ;
2021-10-17 10:36:14 +02:00
2021-10-21 17:17:17 +02:00
function resolveClaimTypeForAnalytics ( claim ) {
if ( ! claim ) {
return 'undefined_claim' ;
}
switch ( claim . value _type ) {
case 'stream' :
if ( claim . value ) {
if ( ! claim . value . source ) {
return 'livestream' ;
} else {
return claim . value . stream _type ;
}
} else {
return 'stream' ;
}
default :
// collection, channel, repost, undefined
return claim . value _type ;
}
}
2021-03-26 23:03:16 +01:00
export const NO _FILE = '---' ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
function resolvePublishPayload ( publishData , myClaimForUri , myChannels , preview ) {
const {
name ,
bid ,
filePath ,
description ,
language ,
releaseTimeEdited ,
2021-12-30 20:36:28 +01:00
releaseAnytime ,
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
// license,
licenseUrl ,
useLBRYUploader ,
licenseType ,
otherLicenseDescription ,
thumbnail ,
channel ,
title ,
contentIsFree ,
fee ,
// uri,
tags ,
// locations,
optimize ,
isLivestreamPublish ,
remoteFileUrl ,
} = publishData ;
// Handle scenario where we have a claim that has the same name as a channel we are publishing with.
const myClaimForUriEditing = myClaimForUri && myClaimForUri . name === name ? myClaimForUri : null ;
let publishingLicense ;
switch ( licenseType ) {
case COPYRIGHT :
case OTHER :
publishingLicense = otherLicenseDescription ;
break ;
default :
publishingLicense = licenseType ;
}
// get the claim id from the channel name, we will use that instead
const namedChannelClaim = myChannels ? myChannels . find ( ( myChannel ) => myChannel . name === channel ) : null ;
const channelId = namedChannelClaim ? namedChannelClaim . claim _id : '' ;
2021-12-30 20:36:28 +01:00
const nowTimeStamp = Number ( Math . round ( Date . now ( ) / 1000 ) ) ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
const publishPayload : {
name : ? string ,
bid : string ,
description ? : string ,
channel _id ? : string ,
file _path ? : string ,
license _url ? : string ,
license ? : string ,
thumbnail _url ? : string ,
2021-12-30 20:36:28 +01:00
release _time : number ,
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
fee _currency ? : string ,
fee _amount ? : string ,
languages ? : Array < string > ,
tags : Array < string > ,
locations ? : Array < any > ,
blocking : boolean ,
optimize _file ? : boolean ,
preview ? : boolean ,
remote _url ? : string ,
} = {
name ,
title ,
description ,
locations : [ ] ,
bid : creditsToString ( bid ) ,
languages : [ language ] ,
tags : tags && tags . map ( ( tag ) => tag . name ) ,
thumbnail _url : thumbnail ,
2021-12-30 20:36:28 +01:00
release _time : nowTimeStamp ,
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
blocking : true ,
preview : false ,
} ;
// Temporary solution to keep the same publish flow with the new tags api
// Eventually we will allow users to enter their own tags on publish
// `nsfw` will probably be removed
if ( remoteFileUrl ) {
publishPayload . remote _url = remoteFileUrl ;
}
if ( publishingLicense ) {
publishPayload . license = publishingLicense ;
}
if ( licenseUrl ) {
publishPayload . license _url = licenseUrl ;
}
if ( thumbnail ) {
publishPayload . thumbnail _url = thumbnail ;
}
if ( useLBRYUploader ) {
2021-12-23 19:21:25 +01:00
publishPayload . tags . push ( LBRY _FIRST _TAG ) ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
}
2021-12-30 20:36:28 +01:00
// Set release time to the newly edited time.
// On edits, if not explicitly set to anytime, keep the original release/transaction time as release_time
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
if ( releaseTimeEdited ) {
publishPayload . release _time = releaseTimeEdited ;
2021-12-30 20:36:28 +01:00
} else if ( ! releaseAnytime && myClaimForUriEditing && myClaimForUriEditing . value . release _time ) {
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
publishPayload . release _time = Number ( myClaimForUri . value . release _time ) ;
2021-12-30 20:36:28 +01:00
} else if ( ! releaseAnytime && myClaimForUriEditing && myClaimForUriEditing . timestamp ) {
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
publishPayload . release _time = Number ( myClaimForUriEditing . timestamp ) ;
}
2021-12-30 20:36:28 +01:00
// Remove internal scheduled tag if it exists.
publishPayload . tags = publishPayload . tags . filter ( ( tag ) => tag !== SCHEDULED _LIVESTREAM _TAG ) ;
// Add internal scheduled tag if claim is a livestream and is being scheduled in the future.
2021-12-29 17:57:54 +01:00
if ( isLivestreamPublish && publishPayload . release _time > nowTimeStamp ) {
publishPayload . tags . push ( SCHEDULED _LIVESTREAM _TAG ) ;
}
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
if ( channelId ) {
publishPayload . channel _id = channelId ;
}
if ( myClaimForUriEditing && myClaimForUriEditing . value && myClaimForUriEditing . value . locations ) {
publishPayload . locations = myClaimForUriEditing . value . locations ;
}
if ( ! contentIsFree && fee && fee . currency && Number ( fee . amount ) > 0 ) {
publishPayload . fee _currency = fee . currency ;
publishPayload . fee _amount = creditsToString ( fee . amount ) ;
}
if ( optimize ) {
publishPayload . optimize _file = true ;
}
// Only pass file on new uploads, not metadata only edits.
// The sdk will figure it out
if ( filePath && ! isLivestreamPublish ) {
publishPayload . file _path = filePath ;
}
if ( preview ) {
publishPayload . preview = true ;
publishPayload . optimize _file = false ;
}
return publishPayload ;
}
2020-11-16 20:09:00 +01:00
export const doPublishDesktop = ( filePath : string , preview ? : boolean ) => ( dispatch : Dispatch , getState : ( ) => { } ) => {
2021-03-24 06:22:02 +01:00
const publishPreview = ( previewResponse ) => {
2020-07-31 15:33:49 +02:00
dispatch (
doOpenModal ( MODALS . PUBLISH _PREVIEW , {
previewResponse ,
} )
) ;
} ;
2021-03-30 01:05:18 +02:00
const noFileParam = ! filePath || filePath === NO _FILE ;
const state = getState ( ) ;
const editingUri = makeSelectPublishFormValue ( 'editingURI' ) ( state ) || '' ;
2021-04-14 06:06:11 +02:00
const remoteUrl = makeSelectPublishFormValue ( 'remoteFileUrl' ) ( state ) ;
2021-03-30 01:05:18 +02:00
const claim = makeSelectClaimForUri ( editingUri ) ( state ) || { } ;
const hasSourceFile = claim . value && claim . value . source ;
2021-04-14 06:06:11 +02:00
const redirectToLivestream = noFileParam && ! hasSourceFile && ! remoteUrl ;
2021-03-26 23:03:16 +01:00
2020-07-09 16:58:43 +02:00
const publishSuccess = ( successResponse , lbryFirstError ) => {
2019-07-12 16:58:24 +02:00
const state = getState ( ) ;
2019-07-13 04:59:45 +02:00
const myClaims = selectMyClaims ( state ) ;
2019-04-24 16:02:08 +02:00
const pendingClaim = successResponse . outputs [ 0 ] ;
2019-10-16 23:36:50 +02:00
analytics . apiLogPublish ( pendingClaim ) ;
2019-10-12 03:55:54 +02:00
const { permanent _url : url } = pendingClaim ;
2018-11-02 19:33:00 +01:00
const actions = [ ] ;
2019-11-13 16:59:34 +01:00
// @if TARGET='app'
2020-07-23 19:02:07 +02:00
actions . push ( push ( ` / $ / ${ PAGES . UPLOADS } ` ) ) ;
2019-11-13 16:59:34 +01:00
// @endif
2019-11-07 20:39:22 +01:00
2018-11-02 19:33:00 +01:00
actions . push ( {
2018-04-06 08:00:36 +02:00
type : ACTIONS . PUBLISH _SUCCESS ,
2021-10-21 17:17:17 +02:00
data : {
type : resolveClaimTypeForAnalytics ( pendingClaim ) ,
} ,
2018-04-06 08:00:36 +02:00
} ) ;
2021-03-30 01:05:18 +02:00
2018-11-02 19:33:00 +01:00
// We have to fake a temp claim until the new pending one is returned by claim_list_mine
// We can't rely on claim_list_mine because there might be some delay before the new claims are returned
// Doing this allows us to show the pending claim immediately, it will get overwritten by the real one
2021-03-24 06:22:02 +01:00
const isMatch = ( claim ) => claim . claim _id === pendingClaim . claim _id ;
2018-11-02 19:33:00 +01:00
const isEdit = myClaims . some ( isMatch ) ;
2019-06-25 06:05:46 +02:00
2020-04-24 15:51:00 +02:00
actions . push ( {
2021-10-17 10:36:14 +02:00
type : ACTIONS . UPDATE _PENDING _CLAIMS ,
2020-04-24 15:51:00 +02:00
data : {
claims : [ pendingClaim ] ,
} ,
} ) ;
2020-05-07 14:22:55 +02:00
// @if TARGET='app'
actions . push ( {
2021-10-17 10:36:14 +02:00
type : ACTIONS . ADD _FILES _REFLECTING ,
2020-05-07 14:22:55 +02:00
data : pendingClaim ,
} ) ;
// @endif
2020-04-24 15:51:00 +02:00
dispatch ( batchActions ( ... actions ) ) ;
dispatch (
2019-11-13 16:59:34 +01:00
doOpenModal ( MODALS . PUBLISH , {
uri : url ,
isEdit ,
filePath ,
2020-07-09 16:58:43 +02:00
lbryFirstError ,
2019-11-13 16:59:34 +01:00
} )
) ;
2020-07-23 16:22:57 +02:00
dispatch ( doCheckPendingClaims ( ) ) ;
2020-05-07 14:22:55 +02:00
// @if TARGET='app'
dispatch ( doCheckReflectingFiles ( ) ) ;
// @endif
2021-03-30 01:05:18 +02:00
// @if TARGET='web'
if ( redirectToLivestream ) {
dispatch ( push ( ` / $ / ${ PAGES . LIVESTREAM } ` ) ) ;
}
// @endif
2018-04-06 08:00:36 +02:00
} ;
2018-03-26 23:32:43 +02:00
2021-03-24 06:22:02 +01:00
const publishFail = ( error ) => {
2019-07-12 16:58:24 +02:00
const actions = [ ] ;
2019-11-13 16:59:34 +01:00
actions . push ( {
type : ACTIONS . PUBLISH _FAIL ,
} ) ;
2022-01-06 08:29:17 +01:00
actions . push ( doError ( { message : error . message , cause : error . cause } ) ) ;
2019-07-12 16:58:24 +02:00
dispatch ( batchActions ( ... actions ) ) ;
2018-03-26 23:32:43 +02:00
} ;
2019-07-09 08:02:08 +02:00
2020-07-31 15:33:49 +02:00
if ( preview ) {
dispatch ( doPublish ( publishSuccess , publishFail , publishPreview ) ) ;
return ;
}
2019-11-13 16:59:34 +01:00
// Redirect on web immediately because we have a file upload progress componenet
// on the publishes page. This doesn't exist on desktop so wait until we get a response
// from the SDK
// @if TARGET='web'
2021-03-30 01:05:18 +02:00
if ( ! redirectToLivestream ) {
dispatch ( push ( ` / $ / ${ PAGES . UPLOADS } ` ) ) ;
}
2019-11-13 16:59:34 +01:00
// @endif
2019-10-23 21:39:51 +02:00
dispatch ( doPublish ( publishSuccess , publishFail ) ) ;
2018-03-26 23:32:43 +02:00
} ;
2021-10-17 10:36:14 +02:00
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
export const doPublishResume = ( publishPayload : any ) => ( dispatch : Dispatch , getState : ( ) => { } ) => {
const publishSuccess = ( successResponse , lbryFirstError ) => {
const state = getState ( ) ;
const myClaimIds : Set < string > = selectMyActiveClaims ( state ) ;
const pendingClaim = successResponse . outputs [ 0 ] ;
const { permanent _url : url } = pendingClaim ;
analytics . apiLogPublish ( pendingClaim ) ;
// We have to fake a temp claim until the new pending one is returned by claim_list_mine
// We can't rely on claim_list_mine because there might be some delay before the new claims are returned
// Doing this allows us to show the pending claim immediately, it will get overwritten by the real one
const isEdit = myClaimIds . has ( pendingClaim . claim _id ) ;
const actions = [ ] ;
actions . push ( {
type : ACTIONS . PUBLISH _SUCCESS ,
data : {
type : resolveClaimTypeForAnalytics ( pendingClaim ) ,
} ,
} ) ;
actions . push ( {
type : ACTIONS . UPDATE _PENDING _CLAIMS ,
data : {
claims : [ pendingClaim ] ,
} ,
} ) ;
dispatch ( batchActions ( ... actions ) ) ;
dispatch (
doOpenModal ( MODALS . PUBLISH , {
uri : url ,
isEdit ,
lbryFirstError ,
} )
) ;
dispatch ( doCheckPendingClaims ( ) ) ;
} ;
const publishFail = ( error ) => {
const actions = [ ] ;
actions . push ( {
type : ACTIONS . PUBLISH _FAIL ,
} ) ;
2022-01-06 08:29:17 +01:00
actions . push ( doError ( { message : error . message , cause : error . cause } ) ) ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
dispatch ( batchActions ( ... actions ) ) ;
} ;
dispatch ( doPublish ( publishSuccess , publishFail , false , publishPayload ) ) ;
} ;
2021-10-17 10:36:14 +02:00
export const doResetThumbnailStatus = ( ) => ( dispatch : Dispatch ) => {
dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : {
thumbnailPath : '' ,
thumbnailError : undefined ,
} ,
} ) ;
2021-12-13 07:45:27 +01:00
return fetch ( IMG _CDN _STATUS _URL )
2021-10-17 10:36:14 +02:00
. then ( ( res ) => res . json ( ) )
2021-12-13 07:45:27 +01:00
. then ( ( json ) => {
if ( json . status !== 'online' ) {
2021-10-17 10:36:14 +02:00
throw Error ( ) ;
}
return dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : {
uploadThumbnailStatus : THUMBNAIL _STATUSES . READY ,
thumbnail : '' ,
} ,
} ) ;
} )
. catch ( ( ) =>
dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : {
uploadThumbnailStatus : THUMBNAIL _STATUSES . API _DOWN ,
thumbnail : '' ,
} ,
} )
) ;
} ;
2022-02-24 16:20:07 +01:00
export const doBeginPublish = ( name : string ) => ( dispatch : Dispatch ) => {
dispatch ( doClearPublish ( ) ) ;
// $FlowFixMe
dispatch ( doPrepareEdit ( { name } ) ) ;
dispatch ( push ( ` / $ / ${ PAGES . UPLOAD } ` ) ) ;
} ;
2021-10-17 10:36:14 +02:00
export const doClearPublish = ( ) => ( dispatch : Dispatch ) => {
dispatch ( { type : ACTIONS . CLEAR _PUBLISH } ) ;
return dispatch ( doResetThumbnailStatus ( ) ) ;
} ;
export const doUpdatePublishForm = ( publishFormValue : UpdatePublishFormData ) => ( dispatch : Dispatch ) =>
dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : { ... publishFormValue } ,
} ) ;
export const doUploadThumbnail = (
filePath ? : string ,
thumbnailBlob ? : File ,
fsAdapter ? : any ,
fs ? : any ,
path ? : any ,
cb ? : ( string ) => void
) => ( dispatch : Dispatch ) => {
2022-01-07 20:39:27 +01:00
let thumbnail , fileExt , fileName , fileType , stats , size ;
2021-10-17 10:36:14 +02:00
const uploadError = ( error = '' ) => {
dispatch (
batchActions (
{
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : {
uploadThumbnailStatus : THUMBNAIL _STATUSES . READY ,
thumbnail : '' ,
nsfw : false ,
} ,
} ,
doError ( error )
)
) ;
} ;
dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
2021-12-13 07:45:27 +01:00
data : { thumbnailError : undefined } ,
2021-10-17 10:36:14 +02:00
} ) ;
const doUpload = ( data ) => {
2021-12-13 07:45:27 +01:00
return fetch ( IMG _CDN _PUBLISH _URL , {
2021-10-17 10:36:14 +02:00
method : 'POST' ,
body : data ,
} )
. then ( ( res ) => res . text ( ) )
2022-01-06 04:49:19 +01:00
. then ( ( text ) => {
try {
return text . length ? JSON . parse ( text ) : { } ;
} catch {
throw new Error ( text ) ;
}
} )
2021-10-17 10:36:14 +02:00
. then ( ( json ) => {
2021-12-13 07:45:27 +01:00
if ( json . type !== 'success' ) {
return uploadError (
json . message || _ _ ( 'There was an error in the upload. The format or extension might not be supported.' )
) ;
}
2021-10-17 10:36:14 +02:00
if ( cb ) {
2021-12-13 07:45:27 +01:00
cb ( json . message ) ;
2021-10-17 10:36:14 +02:00
}
2021-12-13 07:45:27 +01:00
2021-10-17 10:36:14 +02:00
return dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : {
uploadThumbnailStatus : THUMBNAIL _STATUSES . COMPLETE ,
2021-12-13 07:45:27 +01:00
thumbnail : json . message ,
2021-10-17 10:36:14 +02:00
} ,
} ) ;
} )
. catch ( ( err ) => {
let message = err . message ;
// This sucks but ¯\_(ツ)_/¯
if ( message === 'Failed to fetch' ) {
2022-02-22 20:17:41 +01:00
// message = __('Thumbnail upload service may be down, try again later.');
message = _ _ (
'Thumbnail upload service may be down, try again later. Some plugins like AdGuard Français may be blocking the service. If using Brave, go to brave://adblock and disable it, or turn down shields.'
) ;
2021-10-17 10:36:14 +02:00
}
2022-01-07 20:39:27 +01:00
const userInput = [ fileName , fileExt , fileType , thumbnail , size ] ;
2022-01-06 08:34:42 +01:00
uploadError ( { message , cause : ` ${ userInput . join ( ' | ' ) } ` } ) ;
2021-10-17 10:36:14 +02:00
} ) ;
} ;
dispatch ( {
type : ACTIONS . UPDATE _PUBLISH _FORM ,
data : { uploadThumbnailStatus : THUMBNAIL _STATUSES . IN _PROGRESS } ,
} ) ;
if ( fsAdapter && fsAdapter . readFile && filePath ) {
fsAdapter . readFile ( filePath , 'base64' ) . then ( ( base64Image ) => {
fileExt = 'png' ;
fileName = 'thumbnail.png' ;
fileType = 'image/png' ;
const data = new FormData ( ) ;
// $FlowFixMe
2021-12-13 07:45:27 +01:00
data . append ( 'file-input' , { uri : 'file://' + filePath , type : fileType , name : fileName } ) ;
data . append ( 'upload' , 'Upload' ) ;
2021-10-17 10:36:14 +02:00
return doUpload ( data ) ;
} ) ;
} else {
if ( filePath && fs && path ) {
thumbnail = fs . readFileSync ( filePath ) ;
fileExt = path . extname ( filePath ) ;
fileName = path . basename ( filePath ) ;
2022-01-07 20:39:27 +01:00
stats = fs . statSync ( filePath ) ;
size = stats . size ;
2021-10-17 10:36:14 +02:00
fileType = ` image/ ${ fileExt . slice ( 1 ) } ` ;
} else if ( thumbnailBlob ) {
fileExt = ` . ${ thumbnailBlob . type && thumbnailBlob . type . split ( '/' ) [ 1 ] } ` ;
fileName = thumbnailBlob . name ;
fileType = thumbnailBlob . type ;
2022-01-07 20:39:27 +01:00
size = thumbnailBlob . size ;
2021-10-17 10:36:14 +02:00
} else {
return null ;
}
2022-02-09 13:11:05 +01:00
if ( size && size >= THUMBNAIL _CDN _SIZE _LIMIT _BYTES ) {
const maxSizeMB = THUMBNAIL _CDN _SIZE _LIMIT _BYTES / ( 1024 * 1024 ) ;
uploadError ( _ _ ( 'Thumbnail size over %max_size%MB, please edit and reupload.' , { max _size : maxSizeMB } ) ) ;
return ;
}
2021-10-17 10:36:14 +02:00
const data = new FormData ( ) ;
const file = thumbnailBlob || ( thumbnail && new File ( [ thumbnail ] , fileName , { type : fileType } ) ) ;
// $FlowFixMe
2021-12-13 07:45:27 +01:00
data . append ( 'file-input' , file ) ;
data . append ( 'upload' , 'Upload' ) ;
2021-10-17 10:36:14 +02:00
return doUpload ( data ) ;
}
} ;
2022-02-01 21:11:35 +01:00
export const doEditForChannel = ( publishData : any , uri : string , fileInfo : FileListItem , fs : any ) => (
dispatch : Dispatch
) => {
if ( publishData . signing _channel ) {
dispatch ( doSetIncognito ( false ) ) ;
dispatch ( doSetActiveChannel ( publishData . signing _channel . claim _id ) ) ;
} else {
dispatch ( doSetIncognito ( true ) ) ;
}
dispatch ( doPrepareEdit ( publishData , uri , fileInfo , fs ) ) ;
} ;
2021-10-17 10:36:14 +02:00
export const doPrepareEdit = ( claim : StreamClaim , uri : string , fileInfo : FileListItem , fs : any ) => (
dispatch : Dispatch
) => {
const { name , amount , value = { } } = claim ;
const channelName = ( claim && claim . signing _channel && claim . signing _channel . name ) || null ;
const {
author ,
description ,
// use same values as default state
// fee will be undefined for free content
fee = {
amount : '0' ,
currency : 'LBC' ,
} ,
languages ,
release _time ,
license ,
license _url : licenseUrl ,
thumbnail ,
title ,
tags ,
} = value ;
const publishData : UpdatePublishFormData = {
name ,
bid : Number ( amount ) ,
contentIsFree : fee . amount === '0' ,
author ,
description ,
fee ,
languages ,
releaseTime : release _time ,
releaseTimeEdited : undefined ,
thumbnail : thumbnail ? thumbnail . url : null ,
title ,
uri ,
uploadThumbnailStatus : thumbnail ? THUMBNAIL _STATUSES . MANUAL : undefined ,
licenseUrl ,
nsfw : isClaimNsfw ( claim ) ,
tags : tags ? tags . map ( ( tag ) => ( { name : tag } ) ) : [ ] ,
} ;
// Make sure custom licenses are mapped properly
// If the license isn't one of the standard licenses, map the custom license and description/url
if ( ! CC _LICENSES . some ( ( { value } ) => value === license ) ) {
if ( ! license || license === NONE || license === PUBLIC _DOMAIN ) {
publishData . licenseType = license ;
} else if ( license && ! licenseUrl && license !== NONE ) {
publishData . licenseType = COPYRIGHT ;
} else {
publishData . licenseType = OTHER ;
}
publishData . otherLicenseDescription = license ;
} else {
publishData . licenseType = license ;
}
if ( channelName ) {
publishData [ 'channel' ] = channelName ;
}
dispatch ( { type : ACTIONS . DO _PREPARE _EDIT , data : publishData } ) ;
} ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
export const doPublish = ( success : Function , fail : Function , preview : Function , payload : any ) => (
2021-10-17 10:36:14 +02:00
dispatch : Dispatch ,
getState : ( ) => { }
) => {
if ( ! preview ) {
dispatch ( { type : ACTIONS . PUBLISH _START } ) ;
}
const state = getState ( ) ;
const myClaimForUri = selectMyClaimForUri ( state ) ;
const myChannels = selectMyChannelClaims ( state ) ;
// const myClaims = selectMyClaimsWithoutChannels(state);
// get redux publish form
const publishData = selectPublishFormValues ( state ) ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
const publishPayload = payload || resolvePublishPayload ( publishData , myClaimForUri , myChannels , preview ) ;
2021-10-17 10:36:14 +02:00
if ( preview ) {
return Lbry . publish ( publishPayload ) . then ( ( previewResponse : PublishResponse ) => {
return preview ( previewResponse ) ;
} , fail ) ;
}
return Lbry . publish ( publishPayload ) . then ( ( response : PublishResponse ) => {
// TODO: Restore LbryFirst
// if (!useLBRYUploader) {
return success ( response ) ;
// }
// $FlowFixMe
// publishPayload.permanent_url = response.outputs[0].permanent_url;
//
// return LbryFirst.upload(publishPayload)
// .then(() => {
// // Return original publish response so app treats it like a normal publish
// return success(response);
// })
// .catch((error) => {
// return success(response, error);
// });
} , fail ) ;
} ;
// Calls file_list until any reflecting files are done
export const doCheckReflectingFiles = ( ) => ( dispatch : Dispatch , getState : GetState ) => {
const state = getState ( ) ;
const { checkingReflector } = state . claims ;
let reflectorCheckInterval ;
const checkFileList = async ( ) => {
const state = getState ( ) ;
const reflectingById = selectReflectingById ( state ) ;
const ids = Object . keys ( reflectingById ) ;
const newReflectingById = { } ;
const promises = [ ] ;
// TODO: just use file_list({claim_id: Array<claimId>})
if ( Object . keys ( reflectingById ) . length ) {
ids . forEach ( ( claimId ) => {
promises . push ( Lbry . file _list ( { claim _id : claimId } ) ) ;
} ) ;
Promise . all ( promises )
. then ( ( results ) => {
results . forEach ( ( res ) => {
if ( res . items [ 0 ] ) {
const fileListItem = res . items [ 0 ] ;
const fileClaimId = fileListItem . claim _id ;
const {
is _fully _reflected : done ,
uploading _to _reflector : uploading ,
reflector _progress : progress ,
} = fileListItem ;
if ( uploading ) {
newReflectingById [ fileClaimId ] = {
fileListItem : fileListItem ,
progress ,
stalled : ! done && ! uploading ,
} ;
}
}
} ) ;
} )
. then ( ( ) => {
dispatch ( {
type : ACTIONS . UPDATE _FILES _REFLECTING ,
data : newReflectingById ,
} ) ;
if ( ! Object . keys ( newReflectingById ) . length ) {
dispatch ( {
type : ACTIONS . TOGGLE _CHECKING _REFLECTING ,
data : false ,
} ) ;
clearInterval ( reflectorCheckInterval ) ;
}
} ) ;
} else {
dispatch ( {
type : ACTIONS . TOGGLE _CHECKING _REFLECTING ,
data : false ,
} ) ;
clearInterval ( reflectorCheckInterval ) ;
}
} ;
// do it once...
checkFileList ( ) ;
// then start the interval if it's not already started
if ( ! checkingReflector ) {
dispatch ( {
type : ACTIONS . TOGGLE _CHECKING _REFLECTING ,
data : true ,
} ) ;
reflectorCheckInterval = setInterval ( ( ) => {
checkFileList ( ) ;
} , 5000 ) ;
}
} ;
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
export function doUpdateUploadAdd (
file : File | string ,
params : { [ key : string ] : any } ,
uploader : TusUploader | XMLHttpRequest
) {
return ( dispatch : Dispatch , getState : GetState ) => {
dispatch ( {
type : ACTIONS . UPDATE _UPLOAD _ADD ,
data : { file , params , uploader } ,
} ) ;
} ;
}
2021-12-07 15:48:09 +01:00
export const doUpdateUploadProgress = ( props : { guid : string , progress ? : string , status ? : string } ) => (
dispatch : Dispatch
) =>
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
dispatch ( {
type : ACTIONS . UPDATE _UPLOAD _PROGRESS ,
data : props ,
} ) ;
2021-12-07 15:48:09 +01:00
/ * *
* doUpdateUploadRemove
*
* @ param guid
* @ param params Optional . Retain to allow removal of old keys , which are
* derived from ` name#channel ` instead of using a guid .
* Can be removed after January 2022.
* @ returns { ( function ( Dispatch , GetState ) : void ) | * }
* /
export function doUpdateUploadRemove ( guid : string , params ? : { [ key : string ] : any } ) {
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
return ( dispatch : Dispatch , getState : GetState ) => {
dispatch ( {
type : ACTIONS . UPDATE _UPLOAD _REMOVE ,
2021-12-07 15:48:09 +01:00
data : { guid , params } ,
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
} ) ;
} ;
}