當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。