How to use the mime/lite.getType function in mime

To help you get started, we’ve selected a few mime 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 digidem / react-mapfilter / src / lib / data_analysis / value_types.js View on Github external
export function guessValueType(
  value: Primitive | Array
): $Values {
  if (Array.isArray(value)) return valueTypes.ARRAY
  if (value === null) return valueTypes.NULL
  if (typeof value !== 'string') return TYPES[typeof value]

  if (isUrl(value)) {
    // eslint-disable-next-line node/no-deprecated-api
    const parsedUrl = url.parse(value)
    const mimeType = mime.getType(parsedUrl.pathname)
    if (!mimeType) return valueTypes.URL
    if (mimeType.split('/')[0] === 'image') return valueTypes.IMAGE_URL
    if (mimeType.split('/')[0] === 'video') return valueTypes.VIDEO_URL
    if (mimeType.split('/')[0] === 'audio') return valueTypes.AUDIO_URL
    return valueTypes.URL
  }

  // Test date last because this is the most expensive
  if (isShortDate(value)) return valueTypes.DATE
  if (isodate.is(value)) return valueTypes.DATETIME

  return valueTypes.STRING
}
github MikaAK / s3-plugin-webpack / src / s3_plugin.js View on Github external
uploadFile(fileName, file) {
    let Key = this.options.basePath + fileName
    const s3Params = _.mapValues(this.uploadOptions, (optionConfig) => {
      return _.isFunction(optionConfig) ? optionConfig(fileName, file) : optionConfig
    })

    // avoid noname folders in bucket
    if (Key[0] === '/')
      Key = Key.substr(1)

    if (s3Params.ContentType === undefined)
      s3Params.ContentType = mime.getType(fileName)

    const Body = fs.createReadStream(file)
    const upload = this.client.upload(
      _.merge({Key, Body}, DEFAULT_UPLOAD_OPTIONS, s3Params)
    )

    if (!this.noCdnizer)
      this.cdnizerOptions.files.push(`*${fileName}*`)

    return {upload, promise: upload.promise()}
  }
github mimecuvalo / helloworld / server / api / upload.js View on Github external
}

  const fileInfo = [];
  for (const file of req.files) {
    const { localOriginal, localThumb, localNormal, publicOriginal, publicThumb, publicNormal } = getUniqueFilenames(
      req,
      file,
      currentUser.model.username
    );

    let isError = false;
    try {
      ensureDirectoriesExist(localOriginal, localThumb, localNormal);
      fs.renameSync(file.path, localOriginal);

      const mimetype = mime.getType(file.originalname);
      if (['image/apng', 'image/gif'].includes(mimetype)) {
        fs.copyFileSync(localOriginal, localThumb);
        fs.copyFileSync(localOriginal, localNormal);
      } else {
        await resize(localOriginal, localThumb, constants.thumbWidth, constants.thumbHeight);
        await resize(localOriginal, localNormal, constants.normalWidth, constants.normalHeight);
      }
    } catch (ex) {
      isError = true;
      console.error('Error uploading image.', ex);
    }

    fileInfo.push({
      original: publicOriginal,
      thumb: publicThumb,
      normal: publicNormal,
github mimecuvalo / helloworld / packages / hello-world-editor / media / unfurl.js View on Github external
export default async function unfurl(onLinkUnfurl, url, editorState) {
  if (url.match(/^
github PACTCare / Dweb.page / src / js / viewmodels / receivePage.js View on Github external
.then((decrypted) => {
            const typeM = MIME.getType(fileName);
            const blob = new Blob([decrypted], { type: typeM });
            blob.name = fileName;
            createLog(fileInput, fileName, false);
            downloadFile(fileName, blob);
          })
          .catch(() => {
github RangerMauve / datmobile / DatURL.js View on Github external
get mimeType () {
    return mime.getType(this.path)
  }
github steelbrain / pundle / packages / pundle-dev-middleware / src / index.js View on Github external
function respondWith(output, givenPathname) {
        const mimeType = mime.getType(path.extname(givenPathname) || '.html') || 'application/octet-stream'
        res.set('content-type', mimeType)
        res.end(output)
      }
github lukeed / sirv / packages / sirv / index.js View on Github external
list(dir, (name, abs, stats) => {
		if (!opts.dotfiles && name.charAt(0) === '.') {
			return;
		}

		let headers = {
			'Content-Length': stats.size,
			'Content-Type': mime.getType(name),
			'Last-Modified': stats.mtime.toUTCString(),
		};

		if (cc) headers['Cache-Control'] = cc;
		if (opts.etag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;

		FILES['/' + name.replace(/\\+/g, '/')] = { abs, stats, headers };
	});
github lukeed / sirv / packages / sirv / index.js View on Github external
return function (req, res, next) {
			let stats, file, uri=decodeURIComponent(req.path || req.pathname || parser(req).pathname);
			let arr = [uri].concat(toAssume(uri, extensions)).map(x => join(dir, x)).filter(fs.existsSync);
			while (file = arr.shift()) {
				stats = fs.statSync(file);
				if (stats.isDirectory()) continue;
				setHeaders(res, uri, stats);
				return send(req, res, file, stats, {
					'Content-Type': mime.getType(file),
					'Last-Modified': stats.mtime.toUTCString(),
					'Content-Length': stats.size,
				});
			}
			return next ? next() : isNotFound(req, res);
		}
	}
github steelbrain / pundle / packages / pundle-transformer-static / src / index.js View on Github external
function getMimeTypeByExtension(extension: string): string {
    return mime.getType(extension) || 'application/octet-stream'
  }