1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

add content-range

This commit is contained in:
Matthias Kretschmann 2019-09-09 22:22:25 +02:00
parent 2f741d300e
commit da357b82c2
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -32,34 +32,45 @@ export class UrlCheckRouter {
headers: { Range: 'bytes=0-' }
},
(error, response) => {
if (
response &&
(response.statusCode.toString().startsWith('2') ||
response.statusCode.toString().startsWith('416'))
) {
const { headers, statusCode } = response
const successResponses =
statusCode.toString().startsWith('2') ||
statusCode.toString().startsWith('416')
if (response && successResponses) {
const result: any = {}
result.found = true
if (response.headers['content-length']) {
if (headers['content-length']) {
result.contentLength = parseInt(
response.headers['content-length']
headers['content-length']
) // convert to number
}
if (response.headers['content-type']) {
const typeAndCharset = response.headers[
'content-type'
].split(';')
// sometimes servers send content-range header,
// try to use it if content-length is not present
if (
headers['content-range'] &&
!headers['content-length']
) {
const size = headers['content-range'].split('/')[1]
result.contentLength = parseInt(size) // convert to number
}
result.contentType = typeAndCharset[0] // eslint-disable-line prefer-destructuring
if (headers['content-type']) {
const typeAndCharset = headers['content-type'].split(
';'
)
/* eslint-disable prefer-destructuring */
result.contentType = typeAndCharset[0]
if (typeAndCharset[1]) {
/* eslint-disable prefer-destructuring */
result.contentCharset = typeAndCharset[1].split(
'='
)[1]
/* eslint-enable prefer-destructuring */
}
/* eslint-enable prefer-destructuring */
}
return res.send({ status: 'success', result })
}