@@ -11,11 +11,6 @@ const toPull = require('stream-to-pull-stream')
11
11
const pushable = require ( 'pull-pushable' )
12
12
const EOL = require ( 'os' ) . EOL
13
13
const toStream = require ( 'pull-stream-to-stream' )
14
- // const fileType = require('file-type')
15
- // const mime = require('mime-types')
16
- // const GatewayResolver = require('../gateway/resolver')
17
- // const PathUtils = require('../gateway/utils/path')
18
- // const Stream = require('stream')
19
14
20
15
exports = module . exports
21
16
@@ -218,128 +213,3 @@ exports.add = {
218
213
)
219
214
}
220
215
}
221
-
222
- // exports.gateway = {
223
- // checkHash: (request, reply) => {
224
- // if (!request.params.hash) {
225
- // return reply('Path Resolve error: path must contain at least one component').code(400).takeover()
226
- // }
227
- //
228
- // return reply({
229
- // ref: `/ipfs/${request.params.hash}`
230
- // })
231
- // },
232
- // handler: (request, reply) => {
233
- // const ref = request.pre.args.ref
234
- // const ipfs = request.server.app.ipfs
235
- //
236
- // return GatewayResolver
237
- // .resolveMultihash(ipfs, ref)
238
- // .then((data) => {
239
- // ipfs
240
- // .files
241
- // .cat(data.multihash)
242
- // .then((stream) => {
243
- // if (ref.endsWith('/')) {
244
- // // remove trailing slash for files
245
- // return reply
246
- // .redirect(PathUtils.removeTrailingSlash(ref))
247
- // .permanent(true)
248
- // } else {
249
- // if (!stream._read) {
250
- // stream._read = () => {}
251
- // stream._readableState = {}
252
- // }
253
- // // response.continue()
254
- // let filetypeChecked = false
255
- // let stream2 = new Stream.PassThrough({highWaterMark: 1})
256
- // let response = reply(stream2).hold()
257
- //
258
- // pull(
259
- // toPull.source(stream),
260
- // pull.drain((chunk) => {
261
- // // Check file type. do this once.
262
- // if (chunk.length > 0 && !filetypeChecked) {
263
- // console.log('got first chunk')
264
- // let fileSignature = fileType(chunk)
265
- // console.log('file type: ', fileSignature)
266
- //
267
- // filetypeChecked = true
268
- // const mimeType = mime.lookup((fileSignature) ? fileSignature.ext : null)
269
- // console.log('ref ', ref)
270
- // console.log('mime-type ', mimeType)
271
- //
272
- // if (mimeType) {
273
- // console.log('writing mimeType')
274
- //
275
- // response
276
- // .header('Content-Type', mime.contentType(mimeType))
277
- // .header('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Ouput')
278
- // .header('Access-Control-Allow-Methods', 'GET')
279
- // .header('Access-Control-Allow-Origin', '*')
280
- // .header('Access-Control-Expose-Headers', 'X-Stream-Output, X-Chunked-Ouput')
281
- // .send()
282
- // } else {
283
- // response
284
- // .header('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Ouput')
285
- // .header('Access-Control-Allow-Methods', 'GET')
286
- // .header('Access-Control-Allow-Origin', '*')
287
- // .header('Access-Control-Expose-Headers', 'X-Stream-Output, X-Chunked-Ouput')
288
- // .send()
289
- // }
290
- // }
291
- //
292
- // stream2.write(chunk)
293
- // }, (err) => {
294
- // if (err) throw err
295
- // console.log('stream ended.')
296
- // stream2.end()
297
- // })
298
- // )
299
- // }
300
- // })
301
- // .catch((err) => {
302
- // if (err) {
303
- // log.error(err)
304
- // return reply(err.toString()).code(500)
305
- // }
306
- // })
307
- // }).catch((err) => {
308
- // console.log('err: ', err.toString(), ' fileName: ', err.fileName)
309
- //
310
- // const errorToString = err.toString()
311
- // if (errorToString === 'Error: This dag node is a directory') {
312
- // return GatewayResolver
313
- // .resolveDirectory(ipfs, ref, err.fileName)
314
- // .then((data) => {
315
- // if (typeof data === 'string') {
316
- // // no index file found
317
- // if (!ref.endsWith('/')) {
318
- // // for a directory, if URL doesn't end with a /
319
- // // append / and redirect permanent to that URL
320
- // return reply.redirect(`${ref}/`).permanent(true)
321
- // } else {
322
- // // send directory listing
323
- // return reply(data)
324
- // }
325
- // } else {
326
- // // found index file
327
- // // redirect to URL/<found-index-file>
328
- // return reply.redirect(PathUtils.joinURLParts(ref, data[0].name))
329
- // }
330
- // }).catch((err) => {
331
- // log.error(err)
332
- // return reply(err.toString()).code(500)
333
- // })
334
- // } else if (errorToString.startsWith('Error: no link named')) {
335
- // return reply(errorToString).code(404)
336
- // } else if (errorToString.startsWith('Error: multihash length inconsistent') ||
337
- // errorToString.startsWith('Error: Non-base58 character')) {
338
- // return reply(errorToString).code(400)
339
- // } else {
340
- // log.error(err)
341
- // return reply(errorToString).code(500)
342
- // }
343
- // })
344
- // }
345
- // }
0 commit comments