MCPcopy
hub / github.com/flowjs/flow.js / validateRequest

Function validateRequest

samples/Node.js/flow-node.js:27–61  ·  view source on GitHub ↗
(chunkNumber, chunkSize, totalSize, identifier, filename, fileSize)

Source from the content-addressed store, hash-verified

25 }
26
27 function validateRequest(chunkNumber, chunkSize, totalSize, identifier, filename, fileSize) {
28 // Clean up the identifier
29 identifier = cleanIdentifier(identifier);
30
31 // Check if the request is sane
32 if (chunkNumber == 0 || chunkSize == 0 || totalSize == 0 || identifier.length == 0 || filename.length == 0) {
33 return 'non_flow_request';
34 }
35 var numberOfChunks = Math.max(Math.floor(totalSize / (chunkSize * 1.0)), 1);
36 if (chunkNumber > numberOfChunks) {
37 return 'invalid_flow_request1';
38 }
39
40 // Is the file too big?
41 if ($.maxFileSize && totalSize > $.maxFileSize) {
42 return 'invalid_flow_request2';
43 }
44
45 if (typeof(fileSize) != 'undefined') {
46 if (chunkNumber < numberOfChunks && fileSize != chunkSize) {
47 // The chunk in the POST request isn't the correct size
48 return 'invalid_flow_request3';
49 }
50 if (numberOfChunks > 1 && chunkNumber == numberOfChunks && fileSize != ((totalSize % chunkSize) + parseInt(chunkSize))) {
51 // The chunks in the POST is the last one, and the fil is not the correct size
52 return 'invalid_flow_request4';
53 }
54 if (numberOfChunks == 1 && fileSize != totalSize) {
55 // The file is only a single chunk, and the data size does not fit
56 return 'invalid_flow_request5';
57 }
58 }
59
60 return 'valid';
61 }
62
63 //'found', filename, original_filename, identifier
64 //'not_found', null, null, null

Callers 1

flow-node.jsFile · 0.85

Calls 1

cleanIdentifierFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…