Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const path = require('path');
const sendToWormhole = require('stream-wormhole');
const Controller = require('egg').Controller;
const fs = require('fs');
const mkdirp = require('mkdirp');
class UploaderController extends Controller {
async upload() {
const ctx = this.ctx;
const stream = await ctx.getFileStream();
const name = path.basename(stream.filename);
let now = new Date();
let today = path.join(now.getFullYear().toString(), (now.getMonth() + 1).toString(), now.getDay().toString(),"/");
let folder = path.join(this.app.config.upload.localFilePrex, today);
// let filename = now.getTime() + '__' + name;
let filename = now.getTime() + '.jpg';
try {
'use strict';
const jwt = require('jsonwebtoken');
const ms = require('ms');
const Controller = require('egg').Controller;
class AdminController extends Controller {
// 管理员登录
async login() {
const { ctx } = this;
const model = ctx.request.body;
const isAuthenticated = await ctx.service.admin.findByLogin(model);
if (isAuthenticated) {
let cookieMxAge = ms('1d');
let jwtMxAge = Math.floor(Date.now() / 1000) + (60 * 60 * 24);
if (model.rememberMe === 'true') {
cookieMxAge = ms('30d');
jwtMxAge = Math.floor(Date.now() / 1000) + (60 * 60 * 30 * 24);
'use strict';
const Controller = require('egg').Controller;
class Home extends Controller {
async index() {
const ctx = this.ctx;
ctx.body = 'hello world';
}
async post() {
const ctx = this.ctx;
ctx.body = ctx.request.body;
}
async session() {
const ctx = this.ctx;
ctx.body = {
session: ctx.session,
'use strict';
const Controller = require('egg').Controller;
/**
* @Controller ticket
*/
class TicketController extends Controller {
/**
* @apikey
* @Router POST /ticket
* @Request body createUser name description for ticket
* @Request header string access_token
* @Response 200 baseResponse ok
*/
async index() {
this.ctx.body = 'hi, ' + this.app.plugins.swagger.name;
}
/**
'use strict';
const Controller = require('egg').Controller;
class NewsController extends Controller {
async list() {
const { ctx, app } = this;
const pageSize = app.config.news.pageSize;
const page = parseInt(ctx.query.page) || 1;
const idList = await ctx.service.hackerNews.getTopStories(page);
await ctx.render('news/list.tpl', {
list: idList[0],
page, pageSize,
});
}
}
module.exports = NewsController;
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
this.ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const egg_1 = require("egg");
const _ = require("lodash");
class FileController extends egg_1.Controller {
constructor() {
super(...arguments);
this.DEFAULT_PEER_COUNT = 10;
}
async uploadFile() {
const stream = await this.ctx.getFileStream();
const result = await this.ctx.service.storage.files.upload(stream);
this.ctx.body = result;
}
async uploadRaw() {
const body = this.ctx.request.body;
const content = _.get(body, 'content');
if (!content) {
this.ctx.logger.warn('body content is empty!');
this.ctx.status = 500;
this.ctx.body = 'please make sure content field is not empty';
const Controller = require('egg').Controller;
class ColumnController extends Controller {
//提问分页
async page() {
if (typeof this.ctx.params.index == 'undefined' || isNaN(this.ctx.params.index) || this.ctx.params.index < 1) {
await this.ctx.render('404.tpl');
return false;
}
let index = Math.floor(this.ctx.params.index) || 1;
this.ctx.locals.lay.base = {
keywords: "Egg中文社区,nodejs, node, express,egg,koa2,ThinkJS, socket.io,关注Web前端开发技术",
description: "Egg中文社区,nodejs, node, express,egg,koa2,ThinkJS, socket.io",
title: "Egg-中文社区",
name: "",
/**
* Created by bear on 2018/3/2.
*/
'use strict';
const Controller = require('egg').Controller;
class TopicsController extends Controller {
async index() {
const { size, num } = this.ctx.query;
const result = await this.service.topics.index(Number(size), Number(num));
this.ctx.body = result;
this.status = 200;
}
async show() {
const result = await this.service.topics.show(this.ctx.params);
this.ctx.body = result;
this.status = 200;
}
async create() {
const parmas = this.ctx.request.body;
const result = await this.service.topics.create(parmas);
this.ctx.body = result;