How to use the mime-types.extensions function in mime-types

To help you get started, we’ve selected a few mime-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ambientsprotocol / ambc / src / cli.js View on Github external
// --ipfs-api option
      const IPFS = require('ipfs-http-client')
      const addr = multiaddr(argv['ipfs-api'])
      const nodeAddress = addr.nodeAddress()
      ipfs = new IPFS(nodeAddress.address, nodeAddress.port)
    } else {
      const IPFS = require('ipfs')
      ipfs = await IPFS.create({ start: false })
    }
  } catch (e) {
    console.error(e)
    throw new Error('Please use npm to install either `ipfs` or `ipfs-http-client`.')
  }

  // Register new MIME type for .ambient files
  mime.extensions['text/ambients'] = ['ambient']
  mime.types.ambient = 'text/ambients'

  const file = fs.readFileSync(argv.input).toString().trim()

  let result
  switch (mime.lookup(argv.input)) {
    case 'application/javascript':
      result = await output(ipfs, file, argv); break
    case 'text/ambients':
      result = await output(ipfs, file, argv); break
    default:
      throw new Error('File type not recognized')
  }

  process.stdout.write(result + '\n')
  process.exit(0)
github tvdstaaij / nocto / services / mediaproxy.js View on Github external
function makeFileSuffix(media) {
    var suffix = '';
    var file = media.object;
    var type = media.type;

    // Strategy 1: use real filename if known
    if (_.isString(file.file_name)) {
        suffix = '/' + encodeURIComponentPlus(file.file_name);
    }

    // Strategy 2: use mime type to find an appropriate extension if it is known
    var preferredExtensions = ['mp3', 'ogg', 'jpg'];
    if (!suffix && _.isString(file.mime_type)) {
        var extensions = mime.extensions[file.mime_type] || [];
        var preferredMatches = _.intersection(extensions, preferredExtensions);
        if (!_.isEmpty(preferredMatches)) {
            suffix = '.' + _.head(preferredMatches);
        } else if (!_.isEmpty(extensions)) {
            suffix = '.' + _.head(extensions);
        } else {
            suffix = file.mime_type.replace(/^[^\/]*\//, '.');
        }
    }

    // Strategy 3: guess appropriate extension based on Telegram media type
    if (!suffix && type === 'sticker') {
        suffix = '/sticker.webp';
        if (svcConfig.decodeWebp) {
            suffix += '.png';
        }
github kanongil / node-hls-tools / lib / recorder.js View on Github external
const Bounce = require('@hapi/bounce');
const Mime = require('mime-types');
const StreamEach = require('stream-each');
const M3U8Parse = require('m3u8parse');
const debug = require('debug')('hls:recorder');

const HlsUploader = require('./hls-uploader');
const SegmentDecrypt = require('./segment-decrypt');


// Add custom extensions

Mime.extensions['audio/aac'] = ['aac'];
Mime.extensions['audio/ac3'] = ['ac3'];
Mime.extensions['video/iso.segment'] = ['m4s'];


const pathOrUriToURL = function (dirpathOrUri) {

  if (!dirpathOrUri.endsWith('/')) {
    dirpathOrUri = `${dirpathOrUri}/`;
  }

  const url = new URL(dirpathOrUri, 'r:/');
  return url.protocol === 'r:' ? Url.pathToFileURL(dirpathOrUri) : url;
};


const HlsStreamRecorder = class {

  constructor(reader, dst, options) {
github kanongil / node-hls-tools / lib / recorder.js View on Github external
const Path = require('path');
const Url = require('url');

const Bounce = require('@hapi/bounce');
const Mime = require('mime-types');
const StreamEach = require('stream-each');
const M3U8Parse = require('m3u8parse');
const debug = require('debug')('hls:recorder');

const HlsUploader = require('./hls-uploader');
const SegmentDecrypt = require('./segment-decrypt');


// Add custom extensions

Mime.extensions['audio/aac'] = ['aac'];
Mime.extensions['audio/ac3'] = ['ac3'];
Mime.extensions['video/iso.segment'] = ['m4s'];


const pathOrUriToURL = function (dirpathOrUri) {

  if (!dirpathOrUri.endsWith('/')) {
    dirpathOrUri = `${dirpathOrUri}/`;
  }

  const url = new URL(dirpathOrUri, 'r:/');
  return url.protocol === 'r:' ? Url.pathToFileURL(dirpathOrUri) : url;
};


const HlsStreamRecorder = class {
github jamonkko / console-log-server / src / index.js View on Github external
export default function consoleLogServer (opts = {}) {
  const mimeExtensions = _.flow(
    _.values,
    _.flatten,
    _.without(['json'])
  )(mime.extensions)

  opts = _.defaults({
    port: 3000,
    hostname: 'localhost',
    resultCode: 200,
    resultBody: null,
    resultHeader: [],
    log: (...args) => {
      console.log(...args)
    },
    defaultRoute: (req, res) => {
      const negotiatedType = req.accepts(mimeExtensions)
      const defaultHandler = () => opts.resultBody ? res.send(opts.resultBody) : res.end()
      const headers = _.flow(
        _.map((h) => h.split(':', 2)),
        _.fromPairs
github mattdesl / gh-readme-scrape / bin / cli.js View on Github external
#!/usr/bin/env node
var path = require('path')
var getUrls = require('gh-md-urls')
var parseRepo = require('github-url-to-object')
var got = require('got')
var contentType = require('content-type')
var mimeExtensions = require('mime-types').extensions
var async = require('async')
var mkdirp = require('mkdirp')
var path = require('path')
var fs = require('fs')
var chalk = require('chalk')
var ghauth = require('ghauth')

var ASYNC_LIMIT = 20
var argv = require('minimist')(process.argv.slice(2), {
  alias: {
    extension: 'e',
    rename: 'r'
  },
  boolean: ['verbose', 'auth']
})
github NuSkooler / enigma-bbs / core / mime_util.js View on Github external
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
		//	don't override any entries
		if(!_.isString(mimeTypes.types[ext])) {
			mimeTypes[ext] = mimeType;
		}

		if(!mimeTypes.extensions[mimeType]) {
			mimeTypes.extensions[mimeType] = [ ext ];
		}
	});
github bullhorn / express-compile / src / rig-mime-types.js View on Github external
_.each(Object.keys(typesToRig), (type) => {
    let ext = typesToRig[type];

    mimeTypes.types[ext] = type;
    mimeTypes.extensions[type] = _.clone([ext], true);
  });
}
github NuSkooler / enigma-bbs / core / mime_util.js View on Github external
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
		//	don't override any entries
		if(!_.isString(mimeTypes.types[ext])) {
			mimeTypes[ext] = mimeType;
		}

		if(!mimeTypes.extensions[mimeType]) {
			mimeTypes.extensions[mimeType] = [ ext ];
		}
	});