Skip to content

Commit

Permalink
add tasks module
Browse files Browse the repository at this point in the history
  • Loading branch information
thondery committed Feb 11, 2019
1 parent 05d3be0 commit 4bd22ea
Show file tree
Hide file tree
Showing 25 changed files with 941 additions and 65 deletions.
3 changes: 2 additions & 1 deletion backpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
webpack: (config, options, webpack) => {

config.entry = {
index: './server/index.ts'
index: './server/index.ts',
task: './server/task.ts'
}

config.resolve = {
Expand Down
3 changes: 3 additions & 0 deletions data/register.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; 用户注册设置

invitation = true
15 changes: 0 additions & 15 deletions data/store.ini

This file was deleted.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"author": "thondery <thondery@163.com>",
"license": "MIT",
"scripts": {
"dev": "backpack dev",
"build": "nuxt build && backpack build"
"dev": "npm run clear && backpack dev",
"build": "npm run clear && nuxt build && backpack build",
"clear": "rimraf ./build ./.nuxt"
},
"dependencies": {
"body-parser": "^1.18.3",
Expand All @@ -19,16 +20,20 @@
"errorhandler": "^1.5.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"inquirer-datepicker": "^0.1.2",
"inquirer-number-plus": "^1.0.0",
"jsonwebtoken": "^8.4.0",
"kenote-express-helper": "^1.0.5",
"kenote-mongoose-helper": "^1.0.5",
"kenote-task-helper": "^1.0.2",
"method-override": "^3.0.0",
"mongoose": "^5.4.10",
"nunjucks": "^3.1.7",
"nuxt": "2.3.4",
"nuxt-class-component": "^1.2.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"tty-table": "^2.7.0",
"vue-property-decorator": "^7.3.0"
},
"devDependencies": {
Expand All @@ -41,13 +46,15 @@
"@types/express-session": "^1.15.11",
"@types/fs-extra": "^5.0.4",
"@types/ini": "^1.3.30",
"@types/inquirer": "^0.0.43",
"@types/jsonwebtoken": "^8.3.0",
"@types/lodash": "^4.14.120",
"@types/method-override": "^0.0.31",
"@types/mongoose": "^5.3.12",
"@types/nunjucks": "^3.1.0",
"@types/passport": "^1.0.0",
"@types/passport-jwt": "^3.0.1",
"@types/uuid": "^3.4.4",
"awesome-typescript-loader": "^5.2.1",
"backpack-core": "^0.8.3",
"node-sass": "^4.11.0",
Expand Down
27 changes: 27 additions & 0 deletions server/config/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createDocument } from '../types/proxys/group'

export interface Groups {
[propsName: string]: createDocument
}

export const setting: Groups = {
['Creator']: {
name: '创建者',
level: 9999,
description: '创建者拥有系统所有权限,且只有一个帐号'
},
['superAdministrator']: {
name: '超级管理员',
level: 9998,
description: '除创建者外的最高权力者,拥有与创建者几乎相同的权限'
},
['teamAdministrator']: {
name: '团队管理员',
level: 7999,
description: '相关团队的最高权力者',
store: {
upload_type: [],
download_type: []
}
}
}
45 changes: 45 additions & 0 deletions server/models/exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Schema, model } from 'mongoose'

const schema: Schema = new Schema({
id: {
type: Number,
default: 0,
index: { unique: true }
},
name: {
type: String
},
cdkey: {
type: String,
required: true
},
type: {
type: String
},
setting: {
type: Object,
default: {}
},
stint: {
type: Number,
default: 0
},
uses: {
type: Number,
default: 0
},
used: {
type: Boolean,
default: false
},
create_at: {
type: Date,
default: Date.now
},
last_at: {
type: Date,
default: Date.now
}
})

export default model('exchange', schema)
14 changes: 4 additions & 10 deletions server/models/group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as mongoose from 'mongoose'
import { Schema, model } from 'mongoose'

const schema: mongoose.Schema = new mongoose.Schema({
const schema: Schema = new Schema({
id: {
type: Number,
default: 0,
Expand All @@ -18,16 +18,10 @@ const schema: mongoose.Schema = new mongoose.Schema({
type: String,
default: ''
},
team: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'team'
}
],
store: {
type: mongoose.Schema.Types.ObjectId,
type: Schema.Types.ObjectId,
ref: 'store'
}
})

export default mongoose.model('group', schema)
export default model('group', schema)
4 changes: 3 additions & 1 deletion server/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { Models } from '../types/model'
import teamModel from './team'
import storeModel from './store'
import groupModel from './group'
import exchangeModel from './exchange'

@MongoSetting(config.mongo)
@ModelMount({
teamModel,
storeModel,
groupModel
groupModel,
exchangeModel
})
class MyMongoDB extends MongoDB {}

Expand Down
6 changes: 3 additions & 3 deletions server/models/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as mongoose from 'mongoose'
import { Schema, model } from 'mongoose'

const schema: mongoose.Schema = new mongoose.Schema({
const schema: Schema = new Schema({
id: {
type: Number,
default: 0,
Expand All @@ -16,4 +16,4 @@ const schema: mongoose.Schema = new mongoose.Schema({
}
})

export default mongoose.model('store', schema)
export default model('store', schema)
6 changes: 3 additions & 3 deletions server/models/team.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as mongoose from 'mongoose'
import { Schema, model } from 'mongoose'

const schema: mongoose.Schema = new mongoose.Schema({
const schema: Schema = new Schema({
id: {
type: Number,
default: 0,
Expand Down Expand Up @@ -28,4 +28,4 @@ const schema: mongoose.Schema = new mongoose.Schema({
}
})

export default mongoose.model('team', schema)
export default model('team', schema)
15 changes: 13 additions & 2 deletions server/nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Nuxt, Builder } from 'nuxt'
import { Express } from 'express'
import { Express, NextFunction } from 'express'
import nuxtConfig from '../nuxt.config'
import { IRequest, IResponse } from './types/resuful'
import { loadData } from './utils'
import { Register } from './types/config'

const dev: boolean = process.env.NODE_ENV !== 'production'
const nuxt: any = new Nuxt({ ...nuxtConfig, dev })
Expand All @@ -11,5 +14,13 @@ if (process.env.NODE_ENV === 'development') {
}

export default (app: Express): void => {
app.use(nuxt.render)
app.use(nuxtHandler, nuxt.render)
}

async function nuxtHandler (req: IRequest, res: IResponse, next: NextFunction): Promise<any> {
let isPage: boolean = !/^(\/\_nuxt|\/__webpack_hmr)|(\.ico|\.png)$/.test(req.path)
if (isPage) {
req.__register = <Register> loadData('data/register.ini')
}
return next()
}
32 changes: 32 additions & 0 deletions server/proxys/exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as Bluebird from 'bluebird'
import * as mongoose from 'mongoose'
import { MongooseDao, MongooseDaoSetting, QueryOptions } from 'kenote-mongoose-helper'
import __Models from '../models'
import { createDocument, responseDocument } from '../types/proxys/exchange'
import * as uuid from 'uuid'

(<mongoose.Mongoose>mongoose).Promise = Bluebird
const Model: mongoose.Model<mongoose.Document, {}> = <mongoose.Model<mongoose.Document, {}>> __Models.exchangeModel
const options: QueryOptions = {
populate: { path: '' },
seqModel: __Models.seqModel
}

@MongooseDaoSetting({
idName: 'id'
})
class ExchangeDao extends MongooseDao {}

class ExchangeProxy {

public Dao: MongooseDao = new ExchangeDao(Model, options)

public async create (doc: createDocument): Bluebird<responseDocument | {}> {
let cdkey: string = uuid.v4()
let exchange: responseDocument | {} = await this.Dao.insert({ ...doc, cdkey })
return exchange
}

}

export default new ExchangeProxy()
14 changes: 4 additions & 10 deletions server/proxys/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ import { pick } from 'lodash'
(<mongoose.Mongoose>mongoose).Promise = Bluebird
const Model: mongoose.Model<mongoose.Document, {}> = <mongoose.Model<mongoose.Document, {}>> __Models.groupModel
const options: QueryOptions = {
populate: [
{
path: 'store',
select: ['upload_type', 'download_type']
},
{
path: 'team',
select: ['name', 'description']
}
],
populate: {
path: 'store',
select: ['upload_type', 'download_type']
},
seqModel: __Models.seqModel
}

Expand Down
22 changes: 22 additions & 0 deletions server/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TaskHelper, TaskSetting } from 'kenote-task-helper'
import initialize from './tasks/initialize'
import invitation from './tasks/invitation'

@TaskSetting({
title: '选择操作类型:',
tasks: [
{
name: '初始化数据',
value: 'initialize',
script: initialize
},
{
name: '注册邀请码',
value: 'invitation',
script: invitation
},
]
})
class Task extends TaskHelper {}

new Task().start()
Loading

0 comments on commit 4bd22ea

Please sign in to comment.