Skip to content
This repository has been 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 all 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)
// }
// })
// }
// }
57 changes: 39 additions & 18 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const API = require('../../src/http')
// const APIctl = require('ipfs-api')
const ncp = require('ncp').ncp
const path = require('path')
const clean = require('../utils/clean')
Expand All @@ -17,14 +15,18 @@ describe('HTTP GATEWAY', () => {
const repoTests = path.join(__dirname, '../repo-tests-run')

let http = {}
let gateway

before((done) => {
http.api = new API(repoTests)

ncp(repoExample, repoTests, (err) => {
expect(err).to.not.exist()

http.api.start(false, done)
http.api.start(false, () => {
gateway = http.api.server.select('Gateway')
done()
})
})
})

Expand All @@ -36,20 +38,39 @@ describe('HTTP GATEWAY', () => {
})
})

describe('## http-gateway spec tests', () => {
fs.readdirSync(path.join(__dirname, '/spec'))
.forEach((file) => require('./spec/' + file)(http))
})
describe('/ipfs/* route', () => {
it('returns 400 for request without argument', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs'
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result.Message).to.be.a('string')
done()
})
})

it('400 for request with invalid argument', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs/invalid'
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result.Message).to.be.a('string')
done()
})
})

// 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))
// })
it('valid hash', (done) => {
gateway.inject({
method: 'GET',
url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(res.rawPayload).to.deep.equal(new Buffer('hello world' + '\n'))
expect(res.payload).to.equal('hello world' + '\n')
done()
})
})
})
})
50 changes: 0 additions & 50 deletions test/gateway/spec/gateway.js

This file was deleted.