当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mime-types.contentType函数代码示例

本文整理汇总了TypeScript中mime-types.contentType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript contentType函数的具体用法?TypeScript contentType怎么用?TypeScript contentType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了contentType函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: deploy

 async deploy(args) {
   this._s3 = new (this._getAWS(this.resources)).S3();
   let bucket = this.resources.target;
   let source = path.resolve(this.resources.source);
   this.bucket = bucket;
   this.source = source;
   console.log("Deploy", source, "on S3 Bucket", bucket);
   await this.createBucket(bucket);
   let files = Finder.from(source).findFiles();
   // Should implement multithread here - cleaning too
   for (let i in files) {
     let file = files[i];
     let key = path.relative(source, file);
     // Need to have mimetype to serve the content correctly
     let mimetype = mime.contentType(path.extname(file));
     await this._s3
       .putObject({
         Bucket: bucket,
         Body: fs.createReadStream(file),
         Key: key,
         ContentType: mimetype
       })
       .promise();
     console.log("Uploaded", file, "to", key, "(" + mimetype + ")");
   }
   if (!this.resources.staticWebsite) {
     return;
   }
   await this._createWebsite();
 }
开发者ID:loopingz,项目名称:webda-shell,代码行数:30,代码来源:s3.ts

示例2: if

 files.forEach(file => {
   let info: any = {};
   if (typeof file === "string") {
     info.src = file;
     info.key = path.relative(process.cwd(), file);
   } else if (file.src === undefined || file.key === undefined) {
     throw Error("Should have src and key defined");
   } else {
     info.src = file.src;
     info.key = file.key;
   }
   // Need to have mimetype to serve the content correctly
   let mimetype = mime.contentType(path.extname(info.src));
   promise = promise
     .then(() => {
       return this._s3
         .putObject({
           Bucket: bucket,
           Body: fs.createReadStream(info.src),
           Key: info.key,
           ContentType: mimetype
         })
         .promise();
     })
     .then(() => {
       console.log(
         "Uploaded",
         info.src,
         "to",
         info.key,
         "(" + mimetype + ")"
       );
     });
 });
开发者ID:loopingz,项目名称:webda-shell,代码行数:34,代码来源:aws.ts

示例3: serverRequest

export function serverRequest(
	settings: Partial<ReactConverterSettings>,
	req: IncomingMessage,
	res: ServerResponse
) {
	const baseFolder = path.resolve(process.cwd(), process.env.DOCS || 'docs')

	let url = req.url

	if (!url) {
		return
	}

	url = decodeURIComponent(url)

	if (url.startsWith('/favicon.ico')) {
		url = favicon
	}

	if (url.startsWith(ASSETS)) {
		const filePath = path.join(__dirname, url.slice(ASSETS.length))
		res.setHeader('Content-Type', mime.contentType(path.extname(filePath)))
		return fs.readFileSync(filePath)
	}

	const urlPath = path.join(baseFolder, url)

	if (fs.existsSync(urlPath) && fs.statSync(urlPath).isFile()) {
		return fs.readFileSync(urlPath)
	} else {
		let indexPath = path.join(baseFolder, url, 'index.json')
		if (fs.existsSync(indexPath)) {
			const content = fs.readFileSync(indexPath).toString()
			res.setHeader('Content-Type', 'text/html; charset=utf-8')
			return renderHTML(JSON.parse(content).reflection, settings)
		} else {
			throw new Error(`File not found: ${url}`)
		}
	}
}
开发者ID:docscript,项目名称:docscript,代码行数:40,代码来源:server.ts

示例4:

import * as mime from 'mime-types';

mime.lookup('json');             // 'application/json'
mime.lookup('.md');              // 'text/x-markdown'
mime.lookup('file.html');        // 'text/html'
mime.lookup('folder/file.js');   // 'application/javascript'
mime.lookup('folder/.htaccess'); // false

mime.lookup('cats'); // false
mime.contentType('markdown');  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json'); // 'application/json; charset=utf-8'

// from a full path
mime.contentType('.json'); // 'application/json; charset=utf-8'

mime.extension('application/octet-stream'); // 'bin'

mime.charset('text/x-markdown'); // 'UTF-8'
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:18,代码来源:mime-types-tests.ts

示例5: fileFilter

 static fileFilter(req: any, file, cb) {
   const ext = contentType(file.mimetype);
   const ext1 = file.mimetype;
   return cb(null, true);
 }
开发者ID:mbechev,项目名称:Feedback,代码行数:5,代码来源:file.service.ts


注:本文中的mime-types.contentType函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。