當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript koa-send類代碼示例

本文整理匯總了TypeScript中koa-send的典型用法代碼示例。如果您正苦於以下問題:TypeScript koa-send類的具體用法?TypeScript koa-send怎麽用?TypeScript koa-send使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了koa-send類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: send

export default async function(ctx: Koa.Context) {
	// Validate id
	if (!mongodb.ObjectID.isValid(ctx.params.id)) {
		ctx.throw(400, 'incorrect id');
		return;
	}

	const fileId = new mongodb.ObjectID(ctx.params.id);

	// Fetch drive file
	const file = await DriveFile.findOne({ _id: fileId });

	if (file == null) {
		ctx.status = 404;
		await send(ctx, '/dummy.png', { root: assets });
		return;
	}

	if (file.metadata.deletedAt) {
		ctx.status = 410;
		await send(ctx, '/tombstone.png', { root: assets });
		return;
	}

	if (file.metadata.withoutChunks) {
		ctx.status = 204;
		return;
	}

	const sendRaw = async () => {
		const bucket = await getDriveFileBucket();
		const readable = bucket.openDownloadStream(fileId);
		readable.on('error', commonReadableHandlerGenerator(ctx));
		ctx.set('Content-Type', file.contentType);
		ctx.body = readable;
	};

	if ('thumbnail' in ctx.query) {
		const thumb = await DriveFileThumbnail.findOne({
			'metadata.originalId': fileId
		});

		if (thumb != null) {
			ctx.set('Content-Type', 'image/jpeg');
			const bucket = await getDriveFileThumbnailBucket();
			ctx.body = bucket.openDownloadStream(thumb._id);
		} else {
			await sendRaw();
		}
	} else {
		if ('download' in ctx.query) {
			ctx.set('Content-Disposition', 'attachment');
		}

		await sendRaw();
	}
}
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:57,代碼來源:send-drive-file.ts

示例2: send

router.get('/assets/*', async ctx => {
	await send(ctx, ctx.path, {
		root: client,
		maxage: ms('7 days'),
		immutable: true
	});
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:7,代碼來源:index.ts

示例3: send

router.get('/assets/*', async ctx => {
	await send(ctx, ctx.params[0], {
		root: `${__dirname}/../../docs/assets/`,
		maxage: ms('7 days'),
		immutable: true
	});
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:7,代碼來源:docs.ts

示例4: sendIndex

    static sendIndex() {
      const _root = process.cwd();
      const _env = process.env.NODE_ENV;

      const _folder = _env === "production" ? "dist" : "dev";

      send(this, `${_root}/client/${_folder}/index.html`);
    }
開發者ID:bernardbr,項目名稱:generator-ng-fullstack,代碼行數:8,代碼來源:index.ts

示例5: send

app.use(async (ctx: Koa.Context) => {
    await send(ctx, 'stimpy.html', {
        root: '../static-files',
        index: 'index.html',
        maxAge: 10,
        hidden: true,
        format: true,
        gzip: true,
        setHeaders: () => {},
    });
});
開發者ID:CNManning,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:koa-send-tests.ts

示例6: async

 return async (ctx, next) => {
   try {
     if (ctx.path !== "/") {
       // If we're in production, try <dist>/public first
       return await koaSend(ctx, ctx.path, {
         immutable,
         root
       });
     }
   } catch (e) {
     /* Error? Go to next middleware... */
   }
   return next();
 };
開發者ID:leebenson,項目名稱:cli,代碼行數:14,代碼來源:app.ts

示例7: async

 return async (context: koa.Context, next: () => void) => {
   if (context.path.startsWith(pathRoot)) {
     const skipPath: boolean = skipPaths.some((current) => context.path.startsWith(current));
     if (context.path === pathRoot && context.method === 'GET') {
       context.type = 'text/html; charset=utf-8';
       context.body = uiHtml;
       context.status = 200;
       return;
     } else if (context.path === (pathPrefix + 'api-docs') && context.method === 'GET') {
       context.type = 'application/json; charset=utf-8';
       context.body = document;
       context.status = 200;
       return;
     } else if (!skipPath && context.method === 'GET') {
       const filePath = context.path.substring(pathRoot.length);
       await send(context, filePath, { root: SWAGGER_UI_PATH });
       return;
     }
   }
   return next();
 };
開發者ID:carlansley,項目名稱:swagger2-koa,代碼行數:21,代碼來源:ui.ts

示例8: send

app.use(async (ctx: Koa.Context) => {
    const path: string = await send(ctx, 'stimpy.html');
});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:3,代碼來源:koa-send-tests.ts

示例9: send

router.get("/", async (ctx, next) => {
  await send(ctx, "./public/index.html");
});
開發者ID:TeamCovertDragon,項目名稱:duanwu-statistics,代碼行數:3,代碼來源:index.ts


注:本文中的koa-send類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。