Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

clean up, remove commented out lines. #971

Merged
merged 3 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 0 additions & 130 deletions src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const toPull = require('stream-to-pull-stream')
const pushable = require('pull-pushable')
const EOL = require('os').EOL
const toStream = require('pull-stream-to-stream')
// const fileType = require('file-type')
// const mime = require('mime-types')
// const GatewayResolver = require('../gateway/resolver')
// const PathUtils = require('../gateway/utils/path')
// const Stream = require('stream')

exports = module.exports

Expand Down Expand Up @@ -218,128 +213,3 @@ exports.add = {
)
}
}

// exports.gateway = {
// checkHash: (request, reply) => {
// if (!request.params.hash) {
// return reply('Path Resolve error: path must contain at least one component').code(400).takeover()
// }
//
// return reply({
// ref: `/ipfs/${request.params.hash}`
// })
// },
// handler: (request, reply) => {
// const ref = request.pre.args.ref
// const ipfs = request.server.app.ipfs
//
// return GatewayResolver
// .resolveMultihash(ipfs, ref)
// .then((data) => {
// ipfs
// .files
// .cat(data.multihash)
// .then((stream) => {
// if (ref.endsWith('/')) {
// // remove trailing slash for files
// return reply
// .redirect(PathUtils.removeTrailingSlash(ref))
// .permanent(true)
// } else {
// if (!stream._read) {
// stream._read = () => {}
// stream._readableState = {}
// }
// // response.continue()
// let filetypeChecked = false
// let stream2 = new Stream.PassThrough({highWaterMark: 1})
// let response = reply(stream2).hold()
//
// pull(
// toPull.source(stream),
// pull.drain((chunk) => {
// // Check file type. do this once.
// if (chunk.length > 0 && !filetypeChecked) {
// console.log('got first chunk')
// let fileSignature = fileType(chunk)
// console.log('file type: ', fileSignature)
//
// filetypeChecked = true
// const mimeType = mime.lookup((fileSignature) ? fileSignature.ext : null)
// console.log('ref ', ref)
// console.log('mime-type ', mimeType)
//
// if (mimeType) {
// console.log('writing mimeType')
//
// response
// .header('Content-Type', mime.contentType(mimeType))
// .header('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Ouput')
// .header('Access-Control-Allow-Methods', 'GET')
// .header('Access-Control-Allow-Origin', '*')
// .header('Access-Control-Expose-Headers', 'X-Stream-Output, X-Chunked-Ouput')
// .send()
// } else {
// response
// .header('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Ouput')
// .header('Access-Control-Allow-Methods', 'GET')
// .header('Access-Control-Allow-Origin', '*')
// .header('Access-Control-Expose-Headers', 'X-Stream-Output, X-Chunked-Ouput')
// .send()
// }
// }
//
// stream2.write(chunk)
// }, (err) => {
// if (err) throw err
// console.log('stream ended.')
// stream2.end()
// })
// )
// }
// })
// .catch((err) => {
// if (err) {
// log.error(err)
// return reply(err.toString()).code(500)
// }
// })
// }).catch((err) => {
// console.log('err: ', err.toString(), ' fileName: ', err.fileName)
//
// const errorToString = err.toString()
// if (errorToString === 'Error: This dag node is a directory') {
// return GatewayResolver
// .resolveDirectory(ipfs, ref, err.fileName)
// .then((data) => {
// if (typeof data === 'string') {
// // no index file found
// if (!ref.endsWith('/')) {
// // for a directory, if URL doesn't end with a /
// // append / and redirect permanent to that URL
// return reply.redirect(`${ref}/`).permanent(true)
// } else {
// // send directory listing
// return reply(data)
// }
// } else {
// // found index file
// // redirect to URL/<found-index-file>
// return reply.redirect(PathUtils.joinURLParts(ref, data[0].name))
// }
// }).catch((err) => {
// log.error(err)
// return reply(err.toString()).code(500)
// })
// } else if (errorToString.startsWith('Error: no link named')) {
// return reply(errorToString).code(404)
// } else if (errorToString.startsWith('Error: multihash length inconsistent') ||
// errorToString.startsWith('Error: Non-base58 character')) {
// return reply(errorToString).code(400)
// } else {
// log.error(err)
// return reply(errorToString).code(500)
// }
// })
// }
// }
12 changes: 0 additions & 12 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,4 @@ describe('HTTP GATEWAY', () => {
fs.readdirSync(path.join(__dirname, '/spec'))
.forEach((file) => require('./spec/' + file)(http))
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ya7ya there are not "gateway spec tests" you probably just have "tests" :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid ma bad, I'll fix that,
I'm looking at the gateway_test.go to try to port these tests to js-ipfs .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! That's perfect @ya7ya :)


// describe('## interface tests', () => {
// fs.readdirSync(path.join(__dirname, '/interface'))
// .forEach((file) => require('./interface/' + file))
// })
//
// describe('## custom ipfs-api tests', () => {
// const ctl = APIctl('/ip4/127.0.0.1/tcp/6001')
//
// fs.readdirSync(path.join(__dirname, '/over-ipfs-api'))
// .forEach((file) => require('./over-ipfs-api/' + file)(ctl))
// })
})