-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
326 additions
and
286 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
40 changes: 40 additions & 0 deletions
40
packages/core/chunked-sender/src/chunkedSender/createChunkedSender.js
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,40 @@ | ||
// @flow | ||
import { logger } from "@rpldy/shared"; | ||
import xhrSend from "@rpldy/sender"; | ||
import { getMandatoryOptions } from "../utils"; | ||
import processChunks from "./processChunks"; | ||
|
||
import type { BatchItem } from "@rpldy/shared"; | ||
import type { OnProgress, SendResult } from "@rpldy/sender"; | ||
import type { TriggerMethod } from "@rpldy/life-events"; | ||
import type { ChunkedOptions, ChunkedSender, ChunkedSendOptions } from "../types"; | ||
|
||
const createChunkedSender = (chunkedOptions: ?ChunkedOptions, trigger: TriggerMethod): ChunkedSender => { | ||
const options = getMandatoryOptions(chunkedOptions); | ||
|
||
const send = (items: BatchItem[], url: ?string, sendOptions: ChunkedSendOptions, onProgress: OnProgress): SendResult => { | ||
let result; | ||
|
||
if (!options.chunked || items.length > 1 || items[0].url || !items[0].file.size) { | ||
result = xhrSend(items, url, sendOptions, onProgress); | ||
logger.debugLog(`chunkedSender: sending items as normal, un-chunked requests`); | ||
} else { | ||
logger.debugLog(`chunkedSender: sending file as a chunked request`); | ||
result = processChunks( | ||
items[0], | ||
options, | ||
url, | ||
sendOptions, | ||
onProgress, | ||
trigger); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
return { | ||
send, | ||
}; | ||
}; | ||
|
||
export default createChunkedSender; |
40 changes: 40 additions & 0 deletions
40
packages/core/chunked-sender/src/chunkedSender/getChunkedState.js
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,40 @@ | ||
// @flow | ||
import createState from "@rpldy/simple-state"; | ||
|
||
import type { ChunkedSendOptions, MandatoryChunkedOptions } from "../types"; | ||
import type { Chunk, ChunkedState, State } from "./types"; | ||
|
||
const getChunkedState = ( | ||
chunks: Chunk[], | ||
url: ?string, | ||
sendOptions: ChunkedSendOptions, | ||
chunkedOptions: MandatoryChunkedOptions | ||
): ChunkedState => { | ||
const { state, update } = createState<State>({ | ||
finished: false, | ||
aborted: false, | ||
error: false, | ||
uploaded: {}, | ||
requests: {}, | ||
responses: [], | ||
chunkCount: chunks.length, | ||
startByte: sendOptions.startByte || 0, | ||
chunks, | ||
url, | ||
sendOptions, | ||
...chunkedOptions, | ||
}); | ||
|
||
const getState = (): State => state; | ||
|
||
const updateState = (updater: (State) => void) => { | ||
update(updater); | ||
}; | ||
|
||
return { | ||
getState, | ||
updateState, | ||
}; | ||
}; | ||
|
||
export default getChunkedState; |
6 changes: 4 additions & 2 deletions
6
packages/core/chunked-sender/src/chunkedSender/getChunksToSend.js
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 |
---|---|---|
@@ -1,40 +1 @@ | ||
// @flow | ||
import { logger } from "@rpldy/shared"; | ||
import xhrSend from "@rpldy/sender"; | ||
import { getMandatoryOptions } from "../utils"; | ||
import processChunks from "./processChunks"; | ||
|
||
import type { BatchItem } from "@rpldy/shared"; | ||
import type { OnProgress, SendResult } from "@rpldy/sender"; | ||
import type { TriggerMethod } from "@rpldy/life-events"; | ||
import type { ChunkedOptions, ChunkedSender, ChunkedSendOptions } from "../types"; | ||
|
||
const createChunkedSender = (chunkedOptions: ?ChunkedOptions, trigger: TriggerMethod): ChunkedSender => { | ||
const options = getMandatoryOptions(chunkedOptions); | ||
|
||
const send = (items: BatchItem[], url: ?string, sendOptions: ChunkedSendOptions, onProgress: OnProgress): SendResult => { | ||
let result; | ||
|
||
if (!options.chunked || items.length > 1 || items[0].url || !items[0].file.size) { | ||
result = xhrSend(items, url, sendOptions, onProgress); | ||
logger.debugLog(`chunkedSender: sending items as normal, un-chunked requests`); | ||
} else { | ||
logger.debugLog(`chunkedSender: sending file as a chunked request`); | ||
result = processChunks( | ||
items[0], | ||
options, | ||
url, | ||
sendOptions, | ||
onProgress, | ||
trigger); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
return { | ||
send, | ||
}; | ||
}; | ||
|
||
export default createChunkedSender; | ||
export default from "./createChunkedSender"; |
11 changes: 8 additions & 3 deletions
11
packages/core/chunked-sender/src/chunkedSender/processChunkProgressData.js
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
Oops, something went wrong.