Commit a513cfe6 authored by nano's avatar nano

sso login

parent ad75b565
This diff is collapsed.
import Router = require('koa-router'); import Router = require('koa-router');
import {toObjectID} from 'iridium'
import {mongodb} from '../models/iridium' import {mongodb} from '../models/iridium'
import {App, AppSchema} from "../models/App"; import {App, AppSchema} from "../models/App";
import * as vercomp from 'vercomp'
import {Context} from "koa"; import {Context} from "koa";
import {Package} from "../models/Package";
const router = new Router(); const router = new Router();
// router.get('/apps', async (ctx: Context, next) => { // router.get('/apps', async (ctx: Context, next) => {
...@@ -24,20 +21,35 @@ const router = new Router(); ...@@ -24,20 +21,35 @@ const router = new Router();
// }); // });
router.get('/v1/apps', async (ctx: Context, next) => { router.get('/v1/apps', async (ctx: Context, next) => {
ctx.body = await mongodb.Apps.find({}).toArray() let payload = ctx.request.query
if((!payload.author && !payload.admin)) {
ctx.throw(400, 'params error')
}
let apps = {}
if(payload.admin == 'true') {
apps = await mongodb.Apps.find({}).toArray()
} else {
apps = await mongodb.Apps.find({author: payload.author}).toArray()
}
ctx.body = apps
}) })
router.post('/v1/app/:id', async (ctx: Context, next) => { router.post('/v1/app/:id', async (ctx: Context, next) => {
if (!ctx.request.body.id || ctx.params.id !== ctx.request.body.id) { let payload = ctx.request.body
if(!payload.id) {
ctx.throw(400, 'params error')
}
if (ctx.params.id !== payload.id) {
ctx.throw(400, "App is not same") ctx.throw(400, "App is not same")
} }
let exists = await mongodb.Apps.findOne({id: ctx.request.body.id}); let exists = await mongodb.Apps.findOne({id: payload.id});
if (exists) { if (exists) {
ctx.throw(400, "App id is exists") ctx.throw(400, "App is exists")
} }
try { try {
ctx.body = await mongodb.Apps.insert(ctx.request.body) ctx.body = await mongodb.Apps.insert(payload)
} catch (e) { } catch (e) {
ctx.throw(400, e) ctx.throw(400, e)
} }
......
...@@ -20,13 +20,21 @@ import config from '../../config' ...@@ -20,13 +20,21 @@ import config from '../../config'
// path: path.join(__dirname, '../../test/upload') // path: path.join(__dirname, '../../test/upload')
// } // }
const checkExtension = async (file) => { const checkPackage = async (file) => {
const ext = mime.extension(file.mime); const ext = mime.extension(file.mime);
if (['zip', 'gz', 'rar', '7z'].indexOf(ext) === -1) { if (['zip', 'gz', 'rar', '7z'].indexOf(ext) === -1) {
throw new Error('Unsupported file type'); throw new Error('Unsupported file type');
} }
} }
const checkImage = async (file) => {
const ext = mime.extension(file.mime);
if (['png', 'jpg', 'jpeg', 'gif', 'webp'].indexOf(ext) === -1) {
throw new Error('Unsupported file type');
}
}
import Router = require('koa-router'); import Router = require('koa-router');
const ossStream = Client(new OSS({ const ossStream = Client(new OSS({
accessKeyId: process.env["OSS_ACCESS_ID"], accessKeyId: process.env["OSS_ACCESS_ID"],
...@@ -42,7 +50,7 @@ const UploadImage = async (ctx: Context) => { ...@@ -42,7 +50,7 @@ const UploadImage = async (ctx: Context) => {
const {files} = await busboy(ctx.req); const {files} = await busboy(ctx.req);
ctx.body = await Promise.all(files.map(async file => { ctx.body = await Promise.all(files.map(async file => {
await checkExtension(file) await checkImage(file)
const filename = `test/${uuid.v1()}`; const filename = `test/${uuid.v1()}`;
...@@ -150,7 +158,7 @@ const uploadPackageUrl = async (ctx: Context) => { ...@@ -150,7 +158,7 @@ const uploadPackageUrl = async (ctx: Context) => {
const [file] = files const [file] = files
try { try {
await checkExtension(file) await checkPackage(file)
// 打包 // 打包
const bundled = await bundle(path.basename(file.path)) const bundled = await bundle(path.basename(file.path))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment