├── conf ├── server.conf.ts ├── api.conf.ts └── db.conf.ts ├── release ├── src │ ├── @types │ │ ├── $http.js │ │ └── $http.js.map │ ├── core │ │ ├── koa.js.map │ │ ├── koa.js │ │ ├── graphql │ │ │ └── renderGraphQL.js.map │ │ ├── postData │ │ │ └── index.js.map │ │ ├── jwt │ │ │ ├── index.js.map │ │ │ ├── sign.js.map │ │ │ ├── verify.js.map │ │ │ ├── sign.js │ │ │ └── verify.js │ │ └── cors │ │ │ └── index.js.map │ ├── utils │ │ ├── tools │ │ │ ├── index.js.map │ │ │ ├── crypto.js │ │ │ ├── crypto.js.map │ │ │ ├── delay.js.map │ │ │ ├── index.js │ │ │ ├── delay.js │ │ │ ├── guid.js │ │ │ └── guid.js.map │ │ ├── http.js.map │ │ ├── http.js │ │ └── session │ │ │ ├── store.js.map │ │ │ └── index.js.map │ ├── models │ │ ├── ResponseData.js.map │ │ ├── Chat.js.map │ │ ├── ResponseData.js │ │ ├── PageInfo.js.map │ │ ├── PageInfo.js │ │ ├── BaseModel.js.map │ │ ├── BaseModel.js │ │ └── Chat.js │ ├── controllers │ │ ├── BaseController.js.map │ │ ├── BaseController.js │ │ ├── DemoController.js.map │ │ ├── FileController.js.map │ │ ├── ServerAPIController.js.map │ │ ├── CommentController.js.map │ │ ├── LeaveMessageController.js.map │ │ ├── AccountController.js.map │ │ ├── ArticleTypeController.js.map │ │ └── TagController.js.map │ ├── middlewares │ │ ├── jwt.js.map │ │ ├── jwt.js │ │ ├── xJwt.js.map │ │ ├── xJwt.js │ │ ├── cors.js.map │ │ ├── index.js.map │ │ ├── cors.js │ │ ├── index.js │ │ ├── auth.js.map │ │ ├── catch.js.map │ │ ├── response.js.map │ │ └── request.js.map │ ├── entities │ │ ├── mongo │ │ │ ├── index.js.map │ │ │ ├── test_mongo.js.map │ │ │ ├── index.js │ │ │ ├── baseModel.js.map │ │ │ ├── api.js.map │ │ │ ├── errors.js.map │ │ │ ├── baseModel.js │ │ │ └── test_mongo.js │ │ └── mysql │ │ │ ├── index.js.map │ │ │ ├── tag.js.map │ │ │ ├── articleType.js.map │ │ │ ├── leaveMessage.js.map │ │ │ ├── user.js.map │ │ │ ├── comment.js.map │ │ │ ├── article.js.map │ │ │ ├── index.js │ │ │ ├── baseEntity.js.map │ │ │ ├── balls.js.map │ │ │ ├── tag.js │ │ │ ├── articleType.js │ │ │ ├── baseEntity.js │ │ │ ├── leaveMessage.js │ │ │ ├── user.js │ │ │ ├── comment.js │ │ │ └── article.js │ ├── schema │ │ ├── demo.js.map │ │ ├── demo.js │ │ └── graphql │ │ │ ├── index.js.map │ │ │ ├── common.js.map │ │ │ ├── LeaveMessage.js.map │ │ │ ├── index.js │ │ │ ├── Comment.js.map │ │ │ ├── Tag.js.map │ │ │ ├── ArticleType.js.map │ │ │ ├── common.js │ │ │ └── User.js.map │ ├── constants │ │ └── index.js.map │ ├── routes │ │ ├── index.js.map │ │ ├── graphql.js.map │ │ └── index.js │ ├── database │ │ ├── conectDB.js.map │ │ └── conectDB.js │ └── app.js.map └── conf │ ├── server.js.map │ ├── server.js │ ├── server.conf.js.map │ ├── server.conf.js │ ├── db.conf.js.map │ └── db.conf.js ├── src ├── controllers │ ├── BaseController.ts │ ├── DemoController.ts │ ├── FileController.ts │ ├── ServerAPIController.ts │ ├── CommentController.ts │ ├── LeaveMessageController.ts │ ├── GeoLogController.ts │ ├── AccountController.ts │ └── ArticleTypeController.ts ├── @types │ └── global.d.ts ├── types │ ├── user.ts │ └── base.ts ├── utils │ ├── tools │ │ ├── index.ts │ │ ├── delay.ts │ │ ├── crypto.ts │ │ ├── formatDate.ts │ │ └── guid.ts │ ├── http.ts │ └── session │ │ ├── store.ts │ │ └── index.ts ├── models │ ├── Stocks.ts │ ├── Chat.ts │ ├── PageInfo.ts │ ├── ResponseData.ts │ └── BaseModel.ts ├── server.ts ├── entities │ ├── mysql │ │ ├── shares │ │ │ ├── shareEntites.ts │ │ │ ├── GJRecord.ts │ │ │ ├── stock.ts │ │ │ └── stockHistory.ts │ │ ├── tag.ts │ │ ├── articleType.ts │ │ ├── leaveMessage.ts │ │ ├── user.ts │ │ ├── comment.ts │ │ ├── article.ts │ │ ├── index.ts │ │ ├── baseEntity.ts │ │ └── balls.ts │ └── mongo │ │ ├── test_mongo.ts │ │ ├── index.ts │ │ ├── baseModel.ts │ │ ├── api.ts │ │ └── errors.ts ├── middlewares │ ├── jwt.ts │ ├── xJwt.ts │ ├── cors.ts │ ├── index.ts │ ├── auth.ts │ ├── catch.ts │ └── response.ts ├── services │ ├── LogsService.ts │ ├── UserService.ts │ ├── GeoLogService.ts │ ├── StockService.ts │ └── StockHistoryService.ts ├── core │ ├── koa.ts │ ├── postData │ │ └── index.ts │ ├── jwt │ │ ├── index.ts │ │ ├── sign.ts │ │ └── verify.ts │ └── cors │ │ └── index.ts ├── constants │ └── index.ts ├── custom.d.ts ├── schema │ ├── demo.ts │ └── graphql │ │ ├── index.ts │ │ └── LeaveMessage.ts ├── daos │ ├── LogsDao.ts │ ├── UserDao.ts │ ├── GeoLogDao.ts │ ├── StockHistoryDao.ts │ └── StockDao.ts ├── routes │ ├── graphql.ts │ └── index.ts ├── database │ ├── dbUtils.ts │ └── conectDB.ts └── app.ts ├── nodemon.json ├── shell └── database.sql ├── .gitignore ├── README.md ├── tsconfig.json └── package.json /conf/server.conf.ts: -------------------------------------------------------------------------------- 1 | 2 | export const PORT = 8200 -------------------------------------------------------------------------------- /release/src/@types/$http.js: -------------------------------------------------------------------------------- 1 | //# sourceMappingURL=$http.js.map -------------------------------------------------------------------------------- /src/controllers/BaseController.ts: -------------------------------------------------------------------------------- 1 | 2 | class BaseController{ 3 | 4 | } 5 | 6 | export default BaseController -------------------------------------------------------------------------------- /src/@types/global.d.ts: -------------------------------------------------------------------------------- 1 | 2 | declare global { 3 | 4 | type AnyObject = Record 5 | } 6 | 7 | export {} 8 | -------------------------------------------------------------------------------- /release/src/core/koa.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"koa.js","sourceRoot":"","sources":["../../../src/core/koa.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/types/user.ts: -------------------------------------------------------------------------------- 1 | import { User } from '@/entities/mysql/user' 2 | 3 | export type UserLogin = Pick 4 | -------------------------------------------------------------------------------- /src/utils/tools/index.ts: -------------------------------------------------------------------------------- 1 | export * from './guid' 2 | export * from './delay' 3 | export * from './crypto' 4 | export * from './formatDate' -------------------------------------------------------------------------------- /release/src/core/koa.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=koa.js.map -------------------------------------------------------------------------------- /release/src/@types/$http.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"$http.js","sourceRoot":"","sources":["../../../src/@types/$http.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/models/Stocks.ts: -------------------------------------------------------------------------------- 1 | 2 | export enum EMarket { 3 | 上证 = 1, 4 | 深证 5 | } 6 | 7 | export enum EBLock { 8 | 主板 = 1, 9 | 创业板, 10 | 科创板 11 | } 12 | -------------------------------------------------------------------------------- /src/server.ts: -------------------------------------------------------------------------------- 1 | import { Application } from './app' 2 | import { PORT } from '../conf/server.conf' 3 | 4 | const App = new Application(PORT) 5 | 6 | // App.start(PORT) -------------------------------------------------------------------------------- /nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src", "conf"], 3 | "ext": "ts,js", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "ts-node src/server.ts", 6 | "delay": 300 7 | } -------------------------------------------------------------------------------- /src/utils/tools/delay.ts: -------------------------------------------------------------------------------- 1 | 2 | export const Delay = (ms: number = 0): Promise => new Promise((resolve, reject) => { 3 | setTimeout(() => { 4 | resolve() 5 | }, ms) 6 | }) 7 | -------------------------------------------------------------------------------- /release/conf/server.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"server.js","sourceRoot":"","sources":["../../conf/server.ts"],"names":[],"mappings":";;AAAA,kCAA4B;AAC5B,6CAAoC;AAEpC,aAAG,CAAC,KAAK,CAAC,kBAAI,CAAC,CAAA"} -------------------------------------------------------------------------------- /release/src/utils/tools/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/tools/index.ts"],"names":[],"mappings":";;;;;AAAA,4BAAsB;AACtB,6BAAuB;AACvB,8BAAwB"} -------------------------------------------------------------------------------- /src/utils/tools/crypto.ts: -------------------------------------------------------------------------------- 1 | import * as Crypto from 'crypto'; 2 | 3 | export const cryptoPwd = (pwd: string, key: string) => { 4 | return Crypto.createHmac('sha256', key).update(pwd).digest('hex'); 5 | } -------------------------------------------------------------------------------- /release/src/models/ResponseData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ResponseData.js","sourceRoot":"","sources":["../../../src/models/ResponseData.ts"],"names":[],"mappings":";;AAIA;IAAA;IAOA,CAAC;IAAD,mBAAC;AAAD,CAAC,AAPD,IAOC;AAPY,oCAAY"} -------------------------------------------------------------------------------- /shell/database.sql: -------------------------------------------------------------------------------- 1 | -- database sql 2 | 3 | -- Blog 4 | CREATE DATABASE `Blog` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; 5 | 6 | -- Shares 7 | CREATE dATABASE `Shares` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; 8 | -------------------------------------------------------------------------------- /release/src/controllers/BaseController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../../../src/controllers/BaseController.ts"],"names":[],"mappings":";;AACA;IAAA;IAEA,CAAC;IAAD,qBAAC;AAAD,CAAC,AAFD,IAEC;AAED,kBAAe,cAAc,CAAA"} -------------------------------------------------------------------------------- /src/entities/mysql/shares/shareEntites.ts: -------------------------------------------------------------------------------- 1 | import { GJRecord } from './GJRecord' 2 | import { Stock } from './stock' 3 | import { History } from './stockHistory' 4 | 5 | 6 | export const ShareEntities = [ 7 | GJRecord, 8 | Stock, 9 | History 10 | ] -------------------------------------------------------------------------------- /src/middlewares/jwt.ts: -------------------------------------------------------------------------------- 1 | import * as JWT from 'koa-jwt' 2 | import { Context } from 'koa' 3 | import { JWT_SECRET, JWT_KEY } from '../constants' 4 | 5 | export default JWT({ 6 | secret: JWT_SECRET, 7 | key: JWT_KEY 8 | }).unless({path: [/\/api\/login/]}) 9 | -------------------------------------------------------------------------------- /src/models/Chat.ts: -------------------------------------------------------------------------------- 1 | import { BaseModel } from './BaseModel' 2 | import { Entity } from 'typeorm'; 3 | 4 | @Entity() 5 | export class Chat extends BaseModel { 6 | 7 | message: string 8 | 9 | username: string 10 | 11 | ip: string 12 | 13 | } -------------------------------------------------------------------------------- /release/conf/server.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var app_1 = require("../src/app"); 4 | var server_conf_1 = require("./server.conf"); 5 | app_1.default.start(server_conf_1.PORT); 6 | //# sourceMappingURL=server.js.map -------------------------------------------------------------------------------- /release/conf/server.conf.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"server.conf.js","sourceRoot":"","sources":["../../conf/server.conf.ts"],"names":[],"mappings":";;AACA,IAAM,MAAM,GAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAE7D,IAAI,IAAI,GAAW,IAAI,CAAA;AAOrB,oBAAI;AALN,IAAG,MAAM,EAAE;IACT,eAAA,IAAI,GAAG,IAAI,CAAA;CACZ"} -------------------------------------------------------------------------------- /release/conf/server.conf.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var _PROD_ = process.env.NODE_ENV === 'production'; 4 | var PORT = 8020; 5 | exports.PORT = PORT; 6 | if (_PROD_) { 7 | exports.PORT = PORT = 8021; 8 | } 9 | //# sourceMappingURL=server.conf.js.map -------------------------------------------------------------------------------- /release/src/middlewares/jwt.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../src/middlewares/jwt.ts"],"names":[],"mappings":";;AAAA,6BAA8B;AAE9B,0CAAkD;AAElD,kBAAe,GAAG,CAAC;IACjB,MAAM,EAAE,sBAAU;IAClB,GAAG,EAAE,mBAAO;CACb,CAAC,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,CAAC,cAAc,CAAC,EAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /release/src/models/Chat.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Chat.js","sourceRoot":"","sources":["../../../src/models/Chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuC;AACvC,mCAAiC;AAGjC;IAA0B,wBAAS;IAAnC;;IAQA,CAAC;IARY,IAAI;QADhB,gBAAM,EAAE;OACI,IAAI,CAQhB;IAAD,WAAC;CAAA,AARD,CAA0B,qBAAS,GAQlC;AARY,oBAAI"} -------------------------------------------------------------------------------- /release/src/utils/tools/crypto.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Crypto = require("crypto"); 4 | exports.cryptoPwd = function (pwd, key) { 5 | return Crypto.createHmac('sha256', key).update(pwd).digest('hex'); 6 | }; 7 | //# sourceMappingURL=crypto.js.map -------------------------------------------------------------------------------- /src/entities/mongo/test_mongo.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import { Entity, Column } from 'typeorm' 3 | import { BaseEntity } from './baseModel' 4 | 5 | @Entity() 6 | export class TestMongo extends BaseEntity{ 7 | 8 | @Column() 9 | name: string 10 | 11 | @Column() 12 | ip: string 13 | 14 | } -------------------------------------------------------------------------------- /src/entities/mysql/tag.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('tag') 6 | export class Tag extends BaseEntity { 7 | 8 | @Column() 9 | name: string; 10 | 11 | @Column() 12 | remark: string 13 | 14 | } -------------------------------------------------------------------------------- /src/types/base.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | export enum DateFormat { 4 | DateTimeS = 'yyyy-MM-dd HH:mm:ss:SSS', 5 | DateTime = 'yyyy-MM-dd HH:mm:ss', 6 | DateM = 'yyyy-MM-dd HH:mm', 7 | Date = 'yyyy-MM-dd', 8 | } 9 | 10 | 11 | export enum UserType { 12 | root, 13 | admin, 14 | normal, 15 | test = 9, 16 | } -------------------------------------------------------------------------------- /src/entities/mongo/index.ts: -------------------------------------------------------------------------------- 1 | import { TestMongo } from './test_mongo' 2 | import { API } from './api' 3 | import { Errors } from './errors' 4 | 5 | 6 | export const MongoEntities:any[] = [ 7 | TestMongo, 8 | API, 9 | Errors 10 | ] 11 | 12 | export default { 13 | TestMongo, 14 | API, 15 | Errors 16 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #editor 2 | .vscode 3 | .idea 4 | 5 | # dependencies 6 | /node_modules 7 | # conf 8 | 9 | # misc 10 | .DS_Store 11 | .env.local 12 | .env.development.local 13 | .env.test.local 14 | .env.production.local 15 | 16 | npm-debug.log* 17 | yarn-debug.log* 18 | yarn-error.log* 19 | 20 | 21 | *.suo 22 | .gitkeep -------------------------------------------------------------------------------- /release/src/entities/mongo/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/entities/mongo/index.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AACxC,6BAA2B;AAC3B,mCAAiC;AAGpB,QAAA,aAAa,GAAS;IACjC,sBAAS;IACT,SAAG;IACH,eAAM;CACP,CAAA;AAED,kBAAe;IACb,SAAS,wBAAA;IACT,GAAG,WAAA;IACH,MAAM,iBAAA;CACP,CAAA"} -------------------------------------------------------------------------------- /release/src/models/ResponseData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var ResponseData = /** @class */ (function () { 4 | function ResponseData() { 5 | } 6 | return ResponseData; 7 | }()); 8 | exports.ResponseData = ResponseData; 9 | //# sourceMappingURL=ResponseData.js.map -------------------------------------------------------------------------------- /release/src/utils/tools/crypto.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../../src/utils/tools/crypto.ts"],"names":[],"mappings":";;AAAA,+BAAiC;AAEpB,QAAA,SAAS,GAAG,UAAC,GAAW,EAAE,GAAW;IAChD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC,CAAA"} -------------------------------------------------------------------------------- /src/entities/mysql/articleType.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('articleType') 6 | export class ArticleType extends BaseEntity { 7 | 8 | @Column() 9 | name: string; 10 | 11 | @Column() 12 | remark: string 13 | 14 | } -------------------------------------------------------------------------------- /release/src/controllers/BaseController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var BaseController = /** @class */ (function () { 4 | function BaseController() { 5 | } 6 | return BaseController; 7 | }()); 8 | exports.default = BaseController; 9 | //# sourceMappingURL=BaseController.js.map -------------------------------------------------------------------------------- /src/middlewares/xJwt.ts: -------------------------------------------------------------------------------- 1 | import JWT from '../core/jwt/index' 2 | import { JWT_SECRET, JWT_KEY, NO_AUTH_URLS } from '../constants' 3 | 4 | const _PROD_ = process.env.NODE_ENV === 'production' 5 | 6 | export default JWT({ 7 | debug: _PROD_ ? false : true, 8 | secret: JWT_SECRET, 9 | key: JWT_KEY, 10 | unless: NO_AUTH_URLS 11 | }) -------------------------------------------------------------------------------- /src/utils/tools/formatDate.ts: -------------------------------------------------------------------------------- 1 | import { format } from 'date-fns' 2 | import { DateFormat } from '@/types/base' 3 | 4 | 5 | export const formatDate = (date: number | Date, formatStr = DateFormat.DateTime) => { 6 | try { 7 | return format(date, formatStr) 8 | } catch(e) { 9 | return format(new Date, formatStr) 10 | } 11 | } -------------------------------------------------------------------------------- /release/src/models/PageInfo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PageInfo.js","sourceRoot":"","sources":["../../../src/models/PageInfo.ts"],"names":[],"mappings":";;AACA,OAAO;AACP;IAAA;QACE,SAAI,GAAW,CAAC,CAAC;QACjB,UAAK,GAAW,CAAC,CAAC;QAClB,aAAQ,GAAW,EAAE,CAAC;QACtB,cAAS,GAAW,CAAC,CAAC;QACtB,UAAK,GAAW,CAAC,CAAC;IACpB,CAAC;IAAD,eAAC;AAAD,CAAC,AAND,IAMC;AANY,4BAAQ"} -------------------------------------------------------------------------------- /release/src/utils/tools/delay.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../src/utils/tools/delay.ts"],"names":[],"mappings":";;AACa,QAAA,KAAK,GAAG,UAAC,EAAc;IAAd,mBAAA,EAAA,MAAc;IAAoB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAClF,UAAU,CAAC;YACT,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;IACR,CAAC,CAAC;AAJsD,CAItD,CAAA"} -------------------------------------------------------------------------------- /release/src/entities/mysql/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/entities/mysql/index.ts"],"names":[],"mappings":";;AAAA,qCAAmC;AACnC,6CAA2C;AAC3C,qCAAmC;AACnC,+BAA6B;AAC7B,6BAA2B;AAC3B,+CAA6C;AAC7C,iCAA+B;AAGlB,QAAA,QAAQ,GAAS;IAC5B,iBAAO;IACP,yBAAW;IACX,iBAAO;IACP,WAAI;IACJ,SAAG;IACH,2BAAY;IACZ,aAAK;CACN,CAAA"} -------------------------------------------------------------------------------- /release/src/utils/tools/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function __export(m) { 3 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; 4 | } 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | __export(require("./guid")); 7 | __export(require("./delay")); 8 | __export(require("./crypto")); 9 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /src/models/PageInfo.ts: -------------------------------------------------------------------------------- 1 | 2 | // 分页信息 3 | export class PageInfo { 4 | page: number = 1; 5 | total: number = 0; 6 | pageSize: number = 10; 7 | totalPage: number = 0; 8 | count: number = 0; 9 | } 10 | 11 | export interface IPageInfo { 12 | page: number 13 | total: number 14 | pageSize: number 15 | totalPage: number 16 | count: number 17 | } -------------------------------------------------------------------------------- /release/src/middlewares/jwt.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var JWT = require("koa-jwt"); 4 | var constants_1 = require("../constants"); 5 | exports.default = JWT({ 6 | secret: constants_1.JWT_SECRET, 7 | key: constants_1.JWT_KEY 8 | }).unless({ path: [/\/api\/login/] }); 9 | //# sourceMappingURL=jwt.js.map -------------------------------------------------------------------------------- /conf/api.conf.ts: -------------------------------------------------------------------------------- 1 | 2 | export const Stock_Name_Origin = '' 3 | 4 | export const Stock_Name_API_Host = '' 5 | 6 | export const Stock_Name_API_Url = '' 7 | 8 | export const UA = '' 9 | 10 | export const Stock_His_API_Host = '' 11 | 12 | export const Stock_His_API_Url = '' 13 | 14 | export const Stock_His_API_Origin = '' 15 | 16 | export const Stock_His_API_Cookie = '' -------------------------------------------------------------------------------- /src/services/LogsService.ts: -------------------------------------------------------------------------------- 1 | import LogsDao from '../daos/LogsDao' 2 | 3 | 4 | class LogsService { 5 | 6 | async getStats() { 7 | const statusCnt = await LogsDao.getStatusCount() 8 | const pathCnt = await LogsDao.getStatusCount('path') 9 | return { 10 | statusCnt, 11 | pathCnt, 12 | } 13 | } 14 | } 15 | 16 | export default new LogsService -------------------------------------------------------------------------------- /release/src/core/graphql/renderGraphQL.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"renderGraphQL.js","sourceRoot":"","sources":["../../../../src/core/graphql/renderGraphQL.ts"],"names":[],"mappings":";;AAKC,CAAC;AAEF,sCAAsC;AACtC,IAAM,gBAAgB,GAAG,OAAO,CAAC;AAEjC;;;;;;GAMG;AACH,SAAgB,aAAa;IAE3B,4BAA4B;IAC5B,OAAO,qaAQ0E,gBAAgB,iIACb,gBAAgB,mGACnC,gBAAgB,6nmBA8gB7D,gBAAgB,+FAM9B,CAAC;AACT,CAAC;AAliBD,sCAkiBC"} -------------------------------------------------------------------------------- /release/src/utils/tools/delay.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Delay = function (ms) { 4 | if (ms === void 0) { ms = 0; } 5 | return new Promise(function (resolve, reject) { 6 | setTimeout(function () { 7 | resolve(); 8 | }, ms); 9 | }); 10 | }; 11 | //# sourceMappingURL=delay.js.map -------------------------------------------------------------------------------- /release/src/middlewares/xJwt.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"xJwt.js","sourceRoot":"","sources":["../../../src/middlewares/xJwt.ts"],"names":[],"mappings":";;AAAA,2CAAmC;AACnC,0CAAgE;AAEhE,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,kBAAe,eAAG,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;IAC5B,MAAM,EAAE,sBAAU;IAClB,GAAG,EAAE,mBAAO;IACZ,MAAM,EAAE,wBAAY;CACrB,CAAC,CAAA"} -------------------------------------------------------------------------------- /release/src/entities/mysql/tag.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"tag.js","sourceRoot":"","sources":["../../../../src/entities/mysql/tag.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAAyB,uBAAU;IAAnC;;IAQA,CAAC;IALC;QADC,gBAAM,EAAE;;qCACI;IAGb;QADC,gBAAM,EAAE;;uCACK;IANH,GAAG;QADf,gBAAM,CAAC,KAAK,CAAC;OACD,GAAG,CAQf;IAAD,UAAC;CAAA,AARD,CAAyB,uBAAU,GAQlC;AARY,kBAAG"} -------------------------------------------------------------------------------- /release/src/entities/mongo/test_mongo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"test_mongo.js","sourceRoot":"","sources":["../../../../src/entities/mongo/test_mongo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAwC;AACxC,yCAAwC;AAGxC;IAA+B,6BAAU;IAAzC;;IAQA,CAAC;IALC;QADC,gBAAM,EAAE;;2CACG;IAGZ;QADC,gBAAM,EAAE;;yCACC;IANC,SAAS;QADrB,gBAAM,EAAE;OACI,SAAS,CAQrB;IAAD,gBAAC;CAAA,AARD,CAA+B,sBAAU,GAQxC;AARY,8BAAS"} -------------------------------------------------------------------------------- /release/src/entities/mysql/articleType.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"articleType.js","sourceRoot":"","sources":["../../../../src/entities/mysql/articleType.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAAiC,+BAAU;IAA3C;;IAQA,CAAC;IALC;QADC,gBAAM,EAAE;;6CACI;IAGb;QADC,gBAAM,EAAE;;+CACK;IANH,WAAW;QADvB,gBAAM,CAAC,aAAa,CAAC;OACT,WAAW,CAQvB;IAAD,kBAAC;CAAA,AARD,CAAiC,uBAAU,GAQ1C;AARY,kCAAW"} -------------------------------------------------------------------------------- /src/entities/mysql/leaveMessage.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('leaveMessage') 6 | export class LeaveMessage extends BaseEntity { 7 | 8 | @Column() 9 | description: string; 10 | 11 | @Column() 12 | parentId: string; 13 | 14 | @Column() 15 | ip: string; 16 | 17 | // @Column() 18 | // client: string; 19 | 20 | } -------------------------------------------------------------------------------- /src/utils/tools/guid.ts: -------------------------------------------------------------------------------- 1 | 2 | const s4 = (): string => 3 | Math.floor((1 + Math.random()) * 0x10000) 4 | .toString(16) 5 | .substring(1); 6 | 7 | export const Guid = (): string => { 8 | return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4(); 9 | }; 10 | 11 | export const Guid8 = (): string => { 12 | return s4() + s4(); 13 | }; 14 | 15 | export const Guid16 = (): string => { 16 | return s4() + s4() + s4() + s4(); 17 | }; 18 | -------------------------------------------------------------------------------- /release/src/entities/mysql/leaveMessage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"leaveMessage.js","sourceRoot":"","sources":["../../../../src/entities/mysql/leaveMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAAkC,gCAAU;IAA5C;;IAcA,CAAC;IAXC;QADC,gBAAM,EAAE;;qDACW;IAGpB;QADC,gBAAM,EAAE;;kDACQ;IAGjB;QADC,gBAAM,EAAE;;4CACE;IATA,YAAY;QADxB,gBAAM,CAAC,cAAc,CAAC;OACV,YAAY,CAcxB;IAAD,mBAAC;CAAA,AAdD,CAAkC,uBAAU,GAc3C;AAdY,oCAAY"} -------------------------------------------------------------------------------- /release/src/models/PageInfo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | // 分页信息 4 | var PageInfo = /** @class */ (function () { 5 | function PageInfo() { 6 | this.page = 1; 7 | this.total = 0; 8 | this.pageSize = 10; 9 | this.totalPage = 0; 10 | this.count = 0; 11 | } 12 | return PageInfo; 13 | }()); 14 | exports.PageInfo = PageInfo; 15 | //# sourceMappingURL=PageInfo.js.map -------------------------------------------------------------------------------- /src/entities/mysql/user.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('user') 6 | export class User extends BaseEntity { 7 | 8 | @Column() 9 | username: string; 10 | 11 | @Column() 12 | password: string; 13 | 14 | @Column() 15 | nickName: string; 16 | 17 | @Column() 18 | userType: number; 19 | 20 | @Column() 21 | sex: number; 22 | 23 | @Column() 24 | remark: string 25 | 26 | } -------------------------------------------------------------------------------- /release/src/middlewares/xJwt.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var index_1 = require("../core/jwt/index"); 4 | var constants_1 = require("../constants"); 5 | var _PROD_ = process.env.NODE_ENV === 'production'; 6 | exports.default = index_1.default({ 7 | debug: _PROD_ ? false : true, 8 | secret: constants_1.JWT_SECRET, 9 | key: constants_1.JWT_KEY, 10 | unless: constants_1.NO_AUTH_URLS 11 | }); 12 | //# sourceMappingURL=xJwt.js.map -------------------------------------------------------------------------------- /src/entities/mysql/comment.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('comment') 6 | export class Comment extends BaseEntity { 7 | 8 | @Column() 9 | description: string; 10 | 11 | @Column() 12 | articleId: string; 13 | 14 | @Column() 15 | parentId: string; 16 | 17 | @Column() 18 | ip: string; 19 | 20 | @Column() 21 | client: string; 22 | 23 | @Column() 24 | url: string; 25 | 26 | } -------------------------------------------------------------------------------- /release/conf/db.conf.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"db.conf.js","sourceRoot":"","sources":["../../conf/db.conf.ts"],"names":[],"mappings":";;AACa,QAAA,SAAS,GAAG;IACvB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,WAAW;CACtB,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,WAAW;CACtB,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,WAAW;CACtB,CAAA"} -------------------------------------------------------------------------------- /release/src/entities/mongo/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var test_mongo_1 = require("./test_mongo"); 4 | var api_1 = require("./api"); 5 | var errors_1 = require("./errors"); 6 | exports.MongoEntities = [ 7 | test_mongo_1.TestMongo, 8 | api_1.API, 9 | errors_1.Errors 10 | ]; 11 | exports.default = { 12 | TestMongo: test_mongo_1.TestMongo, 13 | API: api_1.API, 14 | Errors: errors_1.Errors 15 | }; 16 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /release/src/entities/mysql/user.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../../src/entities/mysql/user.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAA0B,wBAAU;IAApC;;IAoBA,CAAC;IAjBC;QADC,gBAAM,EAAE;;0CACQ;IAGjB;QADC,gBAAM,EAAE;;0CACQ;IAGjB;QADC,gBAAM,EAAE;;0CACQ;IAGjB;QADC,gBAAM,EAAE;;0CACQ;IAGjB;QADC,gBAAM,EAAE;;qCACG;IAGZ;QADC,gBAAM,EAAE;;wCACK;IAlBH,IAAI;QADhB,gBAAM,CAAC,MAAM,CAAC;OACF,IAAI,CAoBhB;IAAD,WAAC;CAAA,AApBD,CAA0B,uBAAU,GAoBnC;AApBY,oBAAI"} -------------------------------------------------------------------------------- /release/src/entities/mysql/comment.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../../src/entities/mysql/comment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAA6B,2BAAU;IAAvC;;IAoBA,CAAC;IAjBC;QADC,gBAAM,EAAE;;gDACW;IAGpB;QADC,gBAAM,EAAE;;8CACS;IAGlB;QADC,gBAAM,EAAE;;6CACQ;IAGjB;QADC,gBAAM,EAAE;;uCACE;IAGX;QADC,gBAAM,EAAE;;2CACM;IAGf;QADC,gBAAM,EAAE;;wCACG;IAlBD,OAAO;QADnB,gBAAM,CAAC,SAAS,CAAC;OACL,OAAO,CAoBnB;IAAD,cAAC;CAAA,AApBD,CAA6B,uBAAU,GAoBtC;AApBY,0BAAO"} -------------------------------------------------------------------------------- /src/models/ResponseData.ts: -------------------------------------------------------------------------------- 1 | 2 | import { PageInfo, IPageInfo } from './PageInfo' 3 | 4 | export class ResponseData{ 5 | /** 6 | * client use 7 | */ 8 | public data: T; 9 | public msg?: string; 10 | public status?: number; 11 | /** 12 | * pager info 13 | */ 14 | public meta?: PageInfo; 15 | public errors?: string[]; 16 | // [key: string]: any 17 | } 18 | 19 | export interface ReturnPage extends Partial, 'data'>> { 20 | list: T[] 21 | total: number 22 | } 23 | -------------------------------------------------------------------------------- /src/entities/mongo/baseModel.ts: -------------------------------------------------------------------------------- 1 | import {Entity, Column, ObjectIdColumn, VersionColumn, CreateDateColumn, Generated} from "typeorm"; 2 | import { toDate } from 'date-fns' 3 | 4 | @Entity() 5 | export class BaseEntity { 6 | 7 | @ObjectIdColumn({ unique: true }) 8 | id: string; 9 | 10 | @Column() 11 | createdBy?: string; 12 | 13 | @Column({ 14 | default: +new Date 15 | }) 16 | createdAt: Date; 17 | 18 | @VersionColumn({ 19 | default: 0 20 | }) 21 | version?: number; 22 | 23 | @Column() 24 | ip: string 25 | } -------------------------------------------------------------------------------- /release/src/utils/tools/guid.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var s4 = function () { 4 | return Math.floor((1 + Math.random()) * 0x10000) 5 | .toString(16) 6 | .substring(1); 7 | }; 8 | exports.Guid = function () { 9 | return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4(); 10 | }; 11 | exports.Guid8 = function () { 12 | return s4() + s4(); 13 | }; 14 | exports.Guid16 = function () { 15 | return s4() + s4() + s4() + s4(); 16 | }; 17 | //# sourceMappingURL=guid.js.map -------------------------------------------------------------------------------- /conf/db.conf.ts: -------------------------------------------------------------------------------- 1 | // mysql config 2 | export const MysqlConf = { 3 | host: 'localhost', 4 | port: 3306, 5 | username: 'root', 6 | password: 'Mysql-pwd-123', 7 | } 8 | 9 | // mongodb config 10 | export const MongoConf = { 11 | host: 'localhost', 12 | port: 27017, 13 | username: 'admin', 14 | password: 'Mongo-pwd-123', 15 | database: 'blog_logs' 16 | } 17 | 18 | // redis config 19 | export const RedisConf = { 20 | host: 'localhost', 21 | port: 6379, 22 | username: 'default', 23 | password: 'Redis-pwd-123', 24 | lazyConnect: true, 25 | } -------------------------------------------------------------------------------- /release/src/entities/mongo/baseModel.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"baseModel.js","sourceRoot":"","sources":["../../../../src/entities/mongo/baseModel.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAmG;AACnG,+BAAgC;AAGhC;IAAA;IAoBA,CAAC;IAjBC;QADC,wBAAc,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;0CACtB;IAGX;QADC,gBAAM,EAAE;;iDACU;IAKnB;QAHC,gBAAM,CAAC;YACN,OAAO,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,yBAAyB,CAAC;SACpD,CAAC;;iDACuB;IAKzB;QAHC,uBAAa,CAAC;YACb,OAAO,EAAE,CAAC;SACX,CAAC;;+CACe;IAGjB;QADC,gBAAM,EAAE;;0CACC;IAnBC,UAAU;QADtB,gBAAM,EAAE;OACI,UAAU,CAoBtB;IAAD,iBAAC;CAAA,AApBD,IAoBC;AApBY,gCAAU"} -------------------------------------------------------------------------------- /release/src/schema/demo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"demo.js","sourceRoot":"","sources":["../../../src/schema/demo.ts"],"names":[],"mappings":";;AAAA,mCAQiB;AAIjB,IAAI,KAAK,GAAG,CAAC,CAAC;AAEd,IAAI,MAAM,GAAG,IAAI,uBAAa,CAAC;IAC7B,KAAK,EAAE,IAAI,2BAAiB,CAAC;QAC3B,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE;YACN,KAAK,EAAE;gBACL,IAAI,EAAE,oBAAU;gBAChB,IAAI,EAAE;oBACJ,EAAE,EAAE;wBACF,IAAI,EAAE,IAAI;wBACV,IAAI,EAAE,oBAAU,CAAC,QAAQ;qBAC1B;iBACF;gBACD,OAAO,EAAE,UAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;oBAClB,EAAE,KAAK,CAAC;oBACR,OAAO,KAAK,CAAC;gBACf,CAAC;aACF;SACF;KACF,CAAC;CACH,CAAC,CAAC;AAGD,wBAAM"} -------------------------------------------------------------------------------- /src/services/UserService.ts: -------------------------------------------------------------------------------- 1 | import UserDao from '../daos/UserDao' 2 | 3 | 4 | class UserService { 5 | 6 | async getById(id: string) { 7 | const user = await UserDao.getById(id) 8 | return user 9 | } 10 | 11 | async getByUsername(username: string) { 12 | const user = await UserDao.getByUsername(username) 13 | return user 14 | } 15 | 16 | async getByIds(ids: string[]) { 17 | const users = await UserDao.getByIds(ids) 18 | return users 19 | } 20 | 21 | async save(args: any) { 22 | // 23 | } 24 | } 25 | 26 | export default new UserService -------------------------------------------------------------------------------- /src/middlewares/cors.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import Cors from '../core/cors' 3 | 4 | const _PROD_ = process.env.NODE_ENV === 'production' 5 | 6 | export default Cors({ 7 | origin: function (ctx: Context) { 8 | const origin = ctx.header.origin 9 | if (_PROD_) { 10 | return false; 11 | } else { 12 | return origin; 13 | } 14 | }, 15 | credentials: true, 16 | allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], 17 | allowHeaders: ['Content-Type', 'Authorization-User', 'X-Requested-With', 'Accept', 'token', 'x-url', 'x-store'] 18 | }) 19 | -------------------------------------------------------------------------------- /release/src/models/BaseModel.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../../../src/models/BaseModel.ts"],"names":[],"mappings":";;AAAA,wCAAsC;AAItC;IAAA;QACU,QAAG,GAAW,YAAI,EAAE,CAAA;QACpB,gBAAW,GAAW,IAAI,CAAC,GAAG,EAAE,CAAA;QAoBxC,YAAO,GAAY,CAAC,CAAA;IACtB,CAAC;IAjBC,sBAAI,yBAAE;QAFN,aAAa;aAEb,cAAW,OAAO,IAAI,CAAC,GAAG,CAAA,CAAC,CAAC;aAC5B,UAAO,GAAG,IAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA,CAAA,CAAC;;;OADA;IAK5B,sBAAI,iCAAU;aAAd,cAAmB,OAAO,IAAI,CAAC,WAAW,CAAA,CAAC,CAAC;aAC5C,UAAe,WAAW,IAAI,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA,CAAC,CAAC;;;OADlB;IAY9C,gBAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,8BAAS"} -------------------------------------------------------------------------------- /release/src/middlewares/cors.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../../src/middlewares/cors.ts"],"names":[],"mappings":";;AACA,qCAA+B;AAE/B,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,kBAAe,cAAI,CAAC;IAClB,MAAM,EAAE,UAAU,GAAY;QAC5B,IAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAA;QAChC,IAAI,MAAM,EAAE;YACV,OAAO,KAAK,CAAC;SACd;aAAM;YACL,OAAO,MAAM,CAAC;SACf;IACH,CAAC;IACD,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC;IACzD,YAAY,EAAE,CAAC,cAAc,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC;CAChH,CAAC,CAAA"} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # koa-graphql-typescript 2 | 3 | ### 项目主要技术结构 4 | 5 | *** 6 | * koa2 7 | * graphql 8 | * typescript 9 | * ioredis 10 | * mysql2 11 | * mongodb 12 | * koa-router 13 | 14 | ### 安装 15 | *** 16 | 在终端下操作 17 | 18 | 项目地址: (`git clone`) 19 | 20 | ``` 21 | git clone git@github.com:xpioneer/koa-graphql-typescript.git 22 | ``` 23 | 24 | 安装node_modules依赖 `yarn` 25 | 26 | ``` 27 | yarn #in your command terminal 28 | ``` 29 | *** 30 | 31 | 32 | ### 运行 33 | 启动开发服务: (http://localhost:8020) 34 | 35 | ``` 36 | yarn start 37 | ``` 38 | 39 | 生产环境打包 40 | 41 | ``` 42 | yarn build 43 | ``` 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /release/conf/db.conf.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.MySqlConf = { 4 | database: 'Blog', 5 | host: 'localhost', 6 | port: 3306, 7 | username: 'root', 8 | password: 'mysql-pwd' 9 | }; 10 | exports.RedisConf = { 11 | host: 'localhost', 12 | port: 6379, 13 | username: 'root', 14 | password: 'redis-pwd' 15 | }; 16 | exports.MongoConf = { 17 | database: 'test', 18 | host: 'localhost', 19 | port: 27017, 20 | username: 'root', 21 | password: 'mongo-pwd' 22 | }; 23 | //# sourceMappingURL=db.conf.js.map -------------------------------------------------------------------------------- /src/middlewares/index.ts: -------------------------------------------------------------------------------- 1 | import * as Koa from 'koa' 2 | import Auth from './auth' 3 | import KoaBody from '../core/postData' 4 | import Cors from './cors'; 5 | import Request from './request'; 6 | import Response from './response'; 7 | import Routes from '../routes'; 8 | // import JWT from './jwt' 9 | import JWT from './xJwt' 10 | 11 | const Middlewares = (App: Koa) => { 12 | App.use(KoaBody) 13 | App.use(JWT) 14 | App.use(Auth) 15 | App.use(Cors); 16 | App.use(Request); 17 | App.use(Response); 18 | 19 | App.use(Routes.routes());//inject routes 20 | }; 21 | 22 | export default Middlewares; 23 | -------------------------------------------------------------------------------- /src/models/BaseModel.ts: -------------------------------------------------------------------------------- 1 | import { Guid } from "../utils/tools"; 2 | 3 | 4 | 5 | export class BaseModel { 6 | private _id: string = Guid() 7 | private _created_at: number = Date.now() 8 | 9 | // id: string 10 | 11 | get id() { return this._id } 12 | set id(_id) {this._id = _id} 13 | 14 | created_by: string 15 | 16 | get created_at() { return this._created_at } 17 | set created_at(_created_at) { this._created_at = _created_at } 18 | 19 | updated_by?: string 20 | 21 | updated_at?: number 22 | 23 | deleted_by?: string 24 | 25 | deleted_at?: number 26 | 27 | version?: number = 0 28 | } -------------------------------------------------------------------------------- /release/src/constants/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;AACA,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,+CAA+C;AAClC,QAAA,UAAU,GAAG,qBAAqB,CAAA;AAE/C,iCAAiC;AACpB,QAAA,OAAO,GAAG,UAAU,CAAA;AAEjC,eAAe;AACF,QAAA,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAE,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAErE,sBAAsB;AACT,QAAA,YAAY,GAAG;IAC1B,CAAC,cAAc,EAAG,SAAS,CAAC;IAC5B,CAAC,WAAW,EAAE,QAAQ,CAAC;IACvB,CAAC,QAAQ,EAAG,QAAQ,CAAC;CACtB,CAAA;AAGY,QAAA,KAAK,GAAG,+/7JA8mBb,CAAA;AAEK,QAAA,KAAK,GAAG,uzrRA2oCpB,CAAA"} -------------------------------------------------------------------------------- /release/src/middlewares/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middlewares/index.ts"],"names":[],"mappings":";;AACA,+BAAyB;AACzB,6CAAsC;AACtC,+BAA0B;AAC1B,qCAAgC;AAChC,uCAAkC;AAClC,oCAA+B;AAC/B,0BAA0B;AAC1B,+BAAwB;AAExB,IAAM,WAAW,GAAG,UAAC,GAAQ;IAC3B,GAAG,CAAC,GAAG,CAAC,kBAAO,CAAC,CAAA;IAChB,GAAG,CAAC,GAAG,CAAC,cAAG,CAAC,CAAA;IACZ,GAAG,CAAC,GAAG,CAAC,cAAI,CAAC,CAAA;IACb,GAAG,CAAC,GAAG,CAAC,cAAI,CAAC,CAAC;IACd,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,CAAC;IACjB,GAAG,CAAC,GAAG,CAAC,kBAAQ,CAAC,CAAC;IAElB,GAAG,CAAC,GAAG,CAAC,gBAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA,eAAe;AAC1C,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"} -------------------------------------------------------------------------------- /src/entities/mysql/article.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('article') 6 | export class Article extends BaseEntity { 7 | 8 | @Column() 9 | title: string; 10 | 11 | @Column() 12 | abstract: string; 13 | 14 | @Column({ 15 | type: 'longtext' 16 | }) 17 | description: string; 18 | 19 | @Column({length: 32}) 20 | typeId: string 21 | 22 | @Column({ 23 | default: 0 24 | }) 25 | isTop: number 26 | 27 | 28 | @Column() 29 | pics: string; 30 | 31 | @Column() 32 | tag: string; 33 | 34 | } -------------------------------------------------------------------------------- /src/entities/mysql/index.ts: -------------------------------------------------------------------------------- 1 | import { Article } from './article' 2 | import { ArticleType } from './articleType' 3 | import { Comment } from './comment' 4 | import { User } from './user' 5 | import { Tag } from './tag' 6 | import { LeaveMessage } from './leaveMessage' 7 | import { Balls } from './balls' 8 | import { SystemLog } from './systemLog' 9 | import { ShareEntities } from './shares/shareEntites' 10 | 11 | export const Entities:any[] = [ 12 | Article, 13 | ArticleType, 14 | Comment, 15 | User, 16 | Tag, 17 | LeaveMessage, 18 | Balls, 19 | SystemLog 20 | ] 21 | 22 | export { 23 | ShareEntities 24 | } -------------------------------------------------------------------------------- /src/services/GeoLogService.ts: -------------------------------------------------------------------------------- 1 | import GeoLogDao from '@/daos/GeoLogDao' 2 | import { Context } from 'koa' 3 | // import { SystemLog } from '@/entities/mysql/systemLog' 4 | 5 | 6 | class GeoLogService { 7 | 8 | async getEveryDay() { 9 | return GeoLogDao.getEveryDay() 10 | } 11 | 12 | async getGeographicStatsByCity() { 13 | return GeoLogDao.getGeographicStatsByCity() 14 | } 15 | 16 | async getGeographicStatsByChina() { 17 | return GeoLogDao.getGeographicStatsByChina() 18 | } 19 | 20 | getVisitMapStats() { 21 | return GeoLogDao.getVisitMapStats() 22 | } 23 | } 24 | 25 | export default new GeoLogService -------------------------------------------------------------------------------- /src/utils/http.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | const $http = axios.create({ 4 | baseURL: "", 5 | // headers: { 'X-Requested-With': 'XMLHttpRequest' }, 6 | // withCredentials: true, 7 | responseType: 'json', // default 8 | timeout: 30000 9 | }) 10 | 11 | $http.interceptors.request.use(config => { 12 | // console.log('$http', config) 13 | return config 14 | }, error => { 15 | return Promise.reject(error) 16 | }) 17 | 18 | $http.interceptors.response.use(response => { 19 | return Promise.resolve(response.data) 20 | }, error => { 21 | return Promise.reject(error.response) 22 | }) 23 | 24 | export default $http -------------------------------------------------------------------------------- /src/entities/mysql/shares/GJRecord.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from '../baseEntity' 4 | 5 | @Entity('gj_trade') 6 | export class GJRecord extends BaseEntity { 7 | 8 | @Column() 9 | tradeAt: number; 10 | 11 | @Column() 12 | amount: number; 13 | 14 | @Column() 15 | price: number; 16 | 17 | @Column() 18 | total: number; 19 | 20 | @Column() 21 | code: number; 22 | 23 | @Column() 24 | position: number; 25 | 26 | @Column() 27 | name: string; 28 | 29 | @Column() 30 | direction: number; 31 | 32 | @Column() 33 | remark: string 34 | 35 | } -------------------------------------------------------------------------------- /release/src/entities/mysql/article.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"article.js","sourceRoot":"","sources":["../../../../src/entities/mysql/article.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAA6B,2BAAU;IAAvC;;IA4BA,CAAC;IAzBC;QADC,gBAAM,EAAE;;0CACK;IAGd;QADC,gBAAM,EAAE;;6CACQ;IAKjB;QAHC,gBAAM,CAAC;YACN,IAAI,EAAE,UAAU;SACjB,CAAC;;gDACkB;IAGpB;QADC,gBAAM,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC;;2CACP;IAKd;QAHC,gBAAM,CAAC;YACN,OAAO,EAAE,CAAC;SACX,CAAC;;0CACW;IAIb;QADC,gBAAM,EAAE;;yCACI;IAGb;QADC,gBAAM,EAAE;;wCACG;IA1BD,OAAO;QADnB,gBAAM,CAAC,SAAS,CAAC;OACL,OAAO,CA4BnB;IAAD,cAAC;CAAA,AA5BD,CAA6B,uBAAU,GA4BtC;AA5BY,0BAAO"} -------------------------------------------------------------------------------- /release/src/utils/tools/guid.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"guid.js","sourceRoot":"","sources":["../../../../src/utils/tools/guid.ts"],"names":[],"mappings":";;AACA,IAAM,EAAE,GAAG;IACT,OAAA,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC;SACtC,QAAQ,CAAC,EAAE,CAAC;SACZ,SAAS,CAAC,CAAC,CAAC;AAFf,CAEe,CAAC;AAEL,QAAA,IAAI,GAAG;IAClB,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AAC/D,CAAC,CAAC;AAEW,QAAA,KAAK,GAAG;IACnB,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AACrB,CAAC,CAAC;AAEW,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC"} -------------------------------------------------------------------------------- /release/src/entities/mysql/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var article_1 = require("./article"); 4 | var articleType_1 = require("./articleType"); 5 | var comment_1 = require("./comment"); 6 | var user_1 = require("./user"); 7 | var tag_1 = require("./tag"); 8 | var leaveMessage_1 = require("./leaveMessage"); 9 | var balls_1 = require("./balls"); 10 | exports.Entities = [ 11 | article_1.Article, 12 | articleType_1.ArticleType, 13 | comment_1.Comment, 14 | user_1.User, 15 | tag_1.Tag, 16 | leaveMessage_1.LeaveMessage, 17 | balls_1.Balls 18 | ]; 19 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /src/entities/mysql/baseEntity.ts: -------------------------------------------------------------------------------- 1 | import {Entity, Column, PrimaryColumn, Generated} from "typeorm"; 2 | 3 | // @Entity() 4 | export class BaseEntity { 5 | 6 | @PrimaryColumn({ unique: true }) 7 | id?: string; 8 | 9 | @Column() 10 | createdBy?: string; 11 | 12 | @Column() 13 | createdAt: number; 14 | 15 | @Column({select: false}) 16 | updatedBy?: string; 17 | 18 | @Column({select: false}) 19 | updatedAt?: number; 20 | 21 | @Column({select: false}) 22 | deletedBy?: string; 23 | 24 | @Column({select: false}) 25 | deletedAt?: number; 26 | 27 | @Column({ 28 | select: false, 29 | default: 0 30 | }) 31 | version?: number; 32 | } -------------------------------------------------------------------------------- /src/core/koa.ts: -------------------------------------------------------------------------------- 1 | 2 | // import { ResponseData, ReturnPage } from '@/models/ResponseData'; 3 | // import * as Koa from 'koa' 4 | 5 | // export interface Context extends Koa.Context { 6 | // // post fields 7 | // fields?: T 8 | 9 | // body: any 10 | 11 | // // session 12 | // session?: object 13 | 14 | // // request 15 | // getParams?: { 16 | // offset: number 17 | // limit: number 18 | // } 19 | 20 | // params: AnyObject 21 | 22 | // // response 23 | // Json?: (res: T | ResponseData | (() => T)) => ResponseData 24 | // Pages?: (res: ReturnPage) => ResponseData 25 | // } 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/constants/index.ts: -------------------------------------------------------------------------------- 1 | 2 | const _PROD_ = process.env.NODE_ENV === 'production' 3 | 4 | // JWT Secret Key, is very very very classified 5 | export const JWT_SECRET = 'koa-grapqhql-secret' 6 | 7 | // JWT Key, indicate current user 8 | export const JWT_KEY = 'CUR_USER' 9 | 10 | // JWT EXP_TIME 11 | export const EXP_TIME = _PROD_ ? 1000 * 60 * 60 : 1000 * 60 * 60 * 2 12 | 13 | // don't need auth url 14 | export const NO_AUTH_URLS = [ 15 | [/\/api\/login/, /^post$/i], 16 | [/\/api\/register/, /^post$/i], 17 | [/\/graphql/, /^get$/i], 18 | [/\/view/, /^get$/i] 19 | ] 20 | 21 | 22 | export const Baidu = `Baidu WebPage` 23 | 24 | export const Tmall = `Tmall WebPage` -------------------------------------------------------------------------------- /release/src/entities/mysql/baseEntity.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"baseEntity.js","sourceRoot":"","sources":["../../../../src/entities/mysql/baseEntity.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAiE;AAEjE,YAAY;AACZ;IAAA;IA4BA,CAAC;IAzBC;QADC,uBAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;0CACpB;IAGZ;QADC,gBAAM,EAAE;;iDACU;IAGnB;QADC,gBAAM,EAAE;;iDACS;IAGlB;QADC,gBAAM,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC;;iDACL;IAGnB;QADC,gBAAM,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC;;iDACL;IAGnB;QADC,gBAAM,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC;;iDACL;IAGnB;QADC,gBAAM,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC;;iDACL;IAMnB;QAJC,gBAAM,CAAC;YACN,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,CAAC;SACX,CAAC;;+CACe;IACnB,iBAAC;CAAA,AA5BD,IA4BC;AA5BY,gCAAU"} -------------------------------------------------------------------------------- /release/src/utils/http.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/utils/http.ts"],"names":[],"mappings":";;AAAA,+BAAyB;AAEzB,IAAM,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC;IACzB,OAAO,EAAE,EAAE;IACX,qDAAqD;IACrD,yBAAyB;IACzB,YAAY,EAAE,MAAM;IACpB,OAAO,EAAE,KAAK;CACf,CAAC,CAAA;AAEF,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,MAAM;IACnC,+BAA+B;IAC/B,OAAO,MAAM,CAAA;AACf,CAAC,EAAE,UAAA,KAAK;IACN,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC,CAAC,CAAA;AAEF,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAA,QAAQ;IACtC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AACvC,CAAC,EAAE,UAAA,KAAK;IACN,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACvC,CAAC,CAAC,CAAA;AAEF,kBAAe,KAAK,CAAA"} -------------------------------------------------------------------------------- /release/src/controllers/DemoController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"DemoController.js","sourceRoot":"","sources":["../../../src/controllers/DemoController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,0CAA4C;AAI5C;IAAA;IAoBA,CAAC;IAjBc,oBAAK,GAAlB,UAAmB,GAAY;;;;gBAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACf,IAAI,GAAK,GAAG,CAAC,MAAM,KAAf,CAAe;gBAC3B,IAAG,IAAI,KAAK,OAAO,EAAE;oBACnB,GAAG,CAAC,IAAI,GAAG,iBAAK,CAAA;iBACjB;qBAAM,IAAI,IAAI,KAAK,OAAO,EAAE;oBAC3B,GAAG,CAAC,IAAI,GAAG,iBAAK,CAAA;iBACjB;qBAAM;oBACL,GAAG,CAAC,IAAI,GAAG,gBAAgB,CAAA;iBAC5B;;;;KACF;IAEY,sBAAO,GAApB,UAAqB,GAAY;;;gBAC/B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;;;;KAExB;IAEH,qBAAC;AAAD,CAAC,AApBD,IAoBC"} -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "downlevelIteration": true, 10 | "removeComments": false, 11 | "noImplicitAny": false, 12 | "suppressImplicitAnyIndexErrors": true, 13 | "lib": ["esnext"], 14 | "outDir": "./release/", 15 | "baseUrl": ".", 16 | "paths": { 17 | "@/*": ["src/*"] 18 | } 19 | }, 20 | "compileOnSave": false, 21 | "exclude": [ 22 | "node_modules" 23 | ], 24 | "ts-node": { 25 | "require": ["tsconfig-paths/register"] 26 | } 27 | } -------------------------------------------------------------------------------- /release/src/middlewares/cors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var cors_1 = require("../core/cors"); 4 | var _PROD_ = process.env.NODE_ENV === 'production'; 5 | exports.default = cors_1.default({ 6 | origin: function (ctx) { 7 | var origin = ctx.header.origin; 8 | if (_PROD_) { 9 | return false; 10 | } 11 | else { 12 | return origin; 13 | } 14 | }, 15 | credentials: true, 16 | allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], 17 | allowHeaders: ['Content-Type', 'Authorization-User', 'X-Requested-With', 'Accept', 'token', 'x-url', 'x-store'] 18 | }); 19 | //# sourceMappingURL=cors.js.map -------------------------------------------------------------------------------- /src/custom.d.ts: -------------------------------------------------------------------------------- 1 | import { DefaultState, DefaultContext } from 'koa' 2 | import { ResponseData, ReturnPage } from '@/models/ResponseData'; 3 | 4 | 5 | declare module "koa" { 6 | export interface Context { 7 | // state: any 8 | 9 | // post fields 10 | fields?: AnyObject 11 | 12 | body: any 13 | 14 | // session 15 | session?: object 16 | 17 | // request 18 | getParams?: { 19 | offset: number 20 | limit: number 21 | } 22 | 23 | params: AnyObject 24 | 25 | // response 26 | Json?: (res: T | ResponseData | (() => T)) => ResponseData 27 | Pages?: (res: ReturnPage) => ResponseData 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /release/src/entities/mongo/api.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/entities/mongo/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAuC;AACvC,yCAAwC;AAGxC;IAAyB,uBAAU;IAAnC;;IA8CA,CAAC;IA5CC;QADC,gBAAM,EAAE;;qCACG;IAGZ;QADC,gBAAM,EAAE;;qCACG;IAGZ;QADC,gBAAM,EAAE;;oCACE;IAGX;QADC,gBAAM,EAAE;;uCACE;IAGX;QADC,gBAAM,EAAE;;uCACK;IAGd;QADC,gBAAM,EAAE;;uCACK;IAGd;QADC,gBAAM,EAAE;;yCACO;IAGhB;QADC,gBAAM,EAAE;;wCACG;IAGZ;QADC,gBAAM,EAAE;;2CACM;IAGf;QADC,gBAAM,EAAE;;wCACG;IAGZ;QADC,gBAAM,EAAE;;qCACG;IAGZ;QADC,gBAAM,EAAE;;yCACO;IAGhB;QADC,gBAAM,EAAE;;uCACK;IAGd;QADC,gBAAM,EAAE;;oCACE;IAGX;QADC,gBAAM,EAAE;;uCACK;IA5CH,GAAG;QADf,gBAAM,CAAC,KAAK,CAAC;OACD,GAAG,CA8Cf;IAAD,UAAC;CAAA,AA9CD,CAAyB,sBAAU,GA8ClC;AA9CY,kBAAG"} -------------------------------------------------------------------------------- /release/src/entities/mongo/errors.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/entities/mongo/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAuC;AACvC,yCAAwC;AAGxC;IAA4B,0BAAU;IAAtC;;IAiDA,CAAC;IA/CC;QADC,gBAAM,EAAE;;wCACG;IAGZ;QADC,gBAAM,EAAE;;wCACG;IAGZ;QADC,gBAAM,EAAE;;uCACE;IAGX;QADC,gBAAM,EAAE;;0CACE;IAGX;QADC,gBAAM,EAAE;;0CACK;IAGd;QADC,gBAAM,EAAE;;0CACK;IAGd;QADC,gBAAM,EAAE;;4CACO;IAGhB;QADC,gBAAM,EAAE;;2CACM;IAGf;QADC,gBAAM,EAAE;;8CACM;IAGf;QADC,gBAAM,EAAE;;2CACG;IAGZ;QADC,gBAAM,EAAE;;wCACG;IAGZ;QADC,gBAAM,EAAE;;4CACO;IAGhB;QADC,gBAAM,EAAE;;0CACK;IAGd;QADC,gBAAM,EAAE;;uCACE;IAGX;QADC,gBAAM,EAAE;;0CACK;IAGd;QADC,gBAAM,EAAE;;0CACO;IA/CL,MAAM;QADlB,gBAAM,EAAE;OACI,MAAM,CAiDlB;IAAD,aAAC;CAAA,AAjDD,CAA4B,sBAAU,GAiDrC;AAjDY,wBAAM"} -------------------------------------------------------------------------------- /release/src/entities/mysql/balls.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"balls.js","sourceRoot":"","sources":["../../../../src/entities/mysql/balls.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AACzB,mCAAuC;AACvC,2CAAyC;AAGzC;IAA2B,yBAAU;IAArC;;IAiDA,CAAC;IA9CC;QADC,gBAAM,EAAE;;wCACK;IAGd;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;2CACQ;IAGjB;QADC,gBAAM,EAAE;;uCACI;IAGb;QADC,gBAAM,EAAE;;2CACQ;IAGjB;QADC,gBAAM,EAAE;;8CACW;IAGpB;QADC,gBAAM,EAAE;;2CACQ;IAGjB;QADC,gBAAM,EAAE;;8CACW;IAGpB;QADC,gBAAM,EAAE;;6CACU;IAGnB;QADC,gBAAM,EAAE;;2CACQ;IAhDN,KAAK;QADjB,gBAAM,CAAC,iBAAiB,CAAC;OACb,KAAK,CAiDjB;IAAD,YAAC;CAAA,AAjDD,CAA2B,uBAAU,GAiDpC;AAjDY,sBAAK"} -------------------------------------------------------------------------------- /release/src/utils/http.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var axios_1 = require("axios"); 4 | var $http = axios_1.default.create({ 5 | baseURL: "", 6 | // headers: { 'X-Requested-With': 'XMLHttpRequest' }, 7 | // withCredentials: true, 8 | responseType: 'json', 9 | timeout: 30000 10 | }); 11 | $http.interceptors.request.use(function (config) { 12 | // console.log('$http', config) 13 | return config; 14 | }, function (error) { 15 | return Promise.reject(error); 16 | }); 17 | $http.interceptors.response.use(function (response) { 18 | return Promise.resolve(response.data); 19 | }, function (error) { 20 | return Promise.reject(error.response); 21 | }); 22 | exports.default = $http; 23 | //# sourceMappingURL=http.js.map -------------------------------------------------------------------------------- /release/src/middlewares/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var auth_1 = require("./auth"); 4 | var postData_1 = require("../core/postData"); 5 | var cors_1 = require("./cors"); 6 | var request_1 = require("./request"); 7 | var response_1 = require("./response"); 8 | var routes_1 = require("../routes"); 9 | // import JWT from './jwt' 10 | var xJwt_1 = require("./xJwt"); 11 | var Middlewares = function (App) { 12 | App.use(postData_1.default); 13 | App.use(xJwt_1.default); 14 | App.use(auth_1.default); 15 | App.use(cors_1.default); 16 | App.use(request_1.default); 17 | App.use(response_1.default); 18 | App.use(routes_1.default.routes()); //inject routes 19 | }; 20 | exports.default = Middlewares; 21 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /src/schema/demo.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLObjectType, 3 | GraphQLSchema, 4 | GraphQLInt, 5 | GraphQLList, 6 | GraphQLString, 7 | GraphQLType, 8 | GraphQLScalarType 9 | } from 'graphql'; 10 | // import * as Koa from 'koa' 11 | import { toDate } from 'date-fns' 12 | 13 | let count = 0; 14 | 15 | let schema = new GraphQLSchema({ 16 | query: new GraphQLObjectType({ 17 | name: 'RootQueryType', 18 | fields: { 19 | count: { 20 | type: GraphQLInt, 21 | args: { 22 | id: { 23 | // name: 'id', 24 | type: GraphQLInt // 参数不为空 25 | } 26 | }, 27 | resolve: (a, b, c, d) => { 28 | ++count; 29 | return count; 30 | } 31 | } 32 | } 33 | }) 34 | }); 35 | 36 | export { 37 | schema 38 | }; 39 | -------------------------------------------------------------------------------- /src/entities/mongo/api.ts: -------------------------------------------------------------------------------- 1 | import {Entity, Column} from "typeorm"; 2 | import { BaseEntity } from './baseModel' 3 | 4 | @Entity('api') 5 | export class API extends BaseEntity{ 6 | @Column() 7 | host: string 8 | 9 | @Column() 10 | path: string 11 | 12 | @Column() 13 | url: string 14 | 15 | @Column() 16 | params: any 17 | 18 | @Column() 19 | method: string 20 | 21 | @Column() 22 | origin: string 23 | 24 | @Column() 25 | hostname: string 26 | 27 | @Column() 28 | headers: any 29 | 30 | @Column() 31 | resHeaders: any 32 | 33 | @Column() 34 | resData: any 35 | 36 | @Column() 37 | time: number 38 | 39 | @Column() 40 | protocol: string 41 | 42 | @Column() 43 | status: number 44 | 45 | @Column() 46 | msg: string 47 | 48 | @Column() 49 | client: string 50 | 51 | } 52 | -------------------------------------------------------------------------------- /release/src/schema/demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var graphql_1 = require("graphql"); 4 | var count = 0; 5 | var schema = new graphql_1.GraphQLSchema({ 6 | query: new graphql_1.GraphQLObjectType({ 7 | name: 'RootQueryType', 8 | fields: { 9 | count: { 10 | type: graphql_1.GraphQLInt, 11 | args: { 12 | id: { 13 | name: 'id', 14 | type: graphql_1.GraphQLInt // 参数不为空 15 | } 16 | }, 17 | resolve: function (a, b, c, d) { 18 | ++count; 19 | return count; 20 | } 21 | } 22 | } 23 | }) 24 | }); 25 | exports.schema = schema; 26 | //# sourceMappingURL=demo.js.map -------------------------------------------------------------------------------- /src/daos/LogsDao.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import M from '@/entities/mongo' 3 | import { 4 | useMongoRepository, 5 | } from '@/database/dbUtils'; 6 | 7 | const { API, Errors } = M 8 | 9 | 10 | class LogsDao { 11 | 12 | async getStatusCount(field = 'status') { 13 | const pipeline: any[] = [{ 14 | $group: { 15 | _id: `$${field}`, 16 | count: { $sum: 1 } 17 | } 18 | }, 19 | { 20 | $project: { 21 | _id: 0, // 排除原始的 _id 字段 22 | name: "$_id", // 将 _id 重命名为 name 23 | count: 1 // 保留 count 字段 24 | } 25 | }] 26 | const apiCnt = await useMongoRepository(API).aggregate(pipeline).toArray() 27 | const errCnt = await useMongoRepository(Errors).aggregate(pipeline).toArray() 28 | 29 | return { 30 | apiCnt, 31 | errCnt, 32 | } 33 | } 34 | } 35 | 36 | export default new LogsDao -------------------------------------------------------------------------------- /src/entities/mongo/errors.ts: -------------------------------------------------------------------------------- 1 | import {Entity, Column} from "typeorm"; 2 | import { BaseEntity } from './baseModel' 3 | 4 | @Entity() 5 | export class Errors extends BaseEntity{ 6 | @Column() 7 | host: string 8 | 9 | @Column() 10 | path: string 11 | 12 | @Column() 13 | url: string 14 | 15 | @Column() 16 | params: any 17 | 18 | @Column() 19 | method: string 20 | 21 | @Column() 22 | origin: string 23 | 24 | @Column() 25 | hostname: string 26 | 27 | @Column() 28 | headers: any 29 | 30 | @Column() 31 | resHeaders: any 32 | 33 | @Column() 34 | resData: any 35 | 36 | @Column() 37 | time: number 38 | 39 | @Column() 40 | protocol: string 41 | 42 | @Column() 43 | status: number 44 | 45 | @Column() 46 | msg: string 47 | 48 | @Column() 49 | client: string 50 | 51 | @Column() 52 | errors: string[] 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/controllers/DemoController.ts: -------------------------------------------------------------------------------- 1 | import {getMongoManager, getMongoRepository, Like, Between, FindManyOptions, Equal} from "typeorm"; 2 | import { Context } from 'koa' 3 | import { Baidu, Tmall } from "../constants"; 4 | import { Delay } from '@/utils/tools' 5 | 6 | 7 | 8 | class LogsController { 9 | 10 | 11 | async views(ctx: Context) { 12 | console.log(ctx.params) 13 | const { site } = ctx.params 14 | if(site === 'baidu') { 15 | ctx.body = Baidu 16 | } else if (site === 'tmall') { 17 | ctx.body = Tmall 18 | } else { 19 | ctx.body = '404, not found' 20 | } 21 | } 22 | 23 | async compose(ctx: Context) { 24 | console.log(ctx.params) 25 | // 26 | } 27 | 28 | async test(ctx: Context) { 29 | console.log('ctx.path: ', ctx.path.length, ctx.params) 30 | await Delay(5000) 31 | ctx.body = ctx.params.id.length 32 | } 33 | 34 | } 35 | 36 | export default new LogsController -------------------------------------------------------------------------------- /release/src/routes/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routes/index.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AACpC,2CAA4C;AAC5C,iDAAoD;AACpD,gEAAoD;AACpD,sEAA0D;AAC1D,gEAAoD;AACpD,gEAAoD;AACpD,0EAA0D;AAE1D,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,IAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAE5B,MAAM;KACH,IAAI,CAAC,YAAY,EAAE,2BAAW,CAAC,KAAK,CAAC;KACrC,IAAI,CAAC,aAAa,EAAE,2BAAW,CAAC,MAAM,CAAC;KACvC,GAAG,CAAC,aAAa,EAAE,wBAAQ,CAAC,KAAK,CAAC;KAClC,IAAI,CAAC,cAAc,EAAE,wBAAQ,CAAC,OAAO,CAAC;KACtC,IAAI,CAAC,aAAa,EAAE,6BAAS,CAAC,IAAI,CAAC;KACnC,GAAG,CAAC,cAAc,EAAE,wBAAQ,CAAC,QAAQ,CAAC;KACtC,GAAG,CAAC,iBAAiB,EAAE,wBAAQ,CAAC,WAAW,CAAC;KAC5C,IAAI,CAAC,aAAa,EAAE,wBAAQ,CAAC,MAAM,CAAC;KACpC,GAAG,CAAC,UAAU,EAAE,oBAAU,CAAC;IAC1B,MAAM,EAAE,kBAAU;IAClB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;CAC/B,CAAC,CAAC;KACF,IAAI,CAAC,UAAU,EAAE,oBAAU,CAAC;IAC3B,MAAM,EAAE,kBAAU;CACnB,CAAC,CAAC,CAAA;AAEL,kBAAe,MAAM,CAAA"} -------------------------------------------------------------------------------- /src/entities/mysql/balls.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column} from "typeorm"; 3 | import { BaseEntity } from './baseEntity' 4 | 5 | @Entity('doubleColorBall') 6 | export class Balls extends BaseEntity { 7 | 8 | @Column() 9 | issue: string; 10 | 11 | @Column() 12 | red1: number; 13 | 14 | @Column() 15 | red2: number; 16 | 17 | @Column() 18 | red3: number; 19 | 20 | @Column() 21 | red4: number; 22 | 23 | @Column() 24 | red5: number; 25 | 26 | @Column() 27 | red6: number; 28 | 29 | @Column() 30 | blue: number; 31 | 32 | @Column() 33 | happySun: string; 34 | 35 | @Column() 36 | pool: number; 37 | 38 | @Column() 39 | prizeOne: number; 40 | 41 | @Column() 42 | prizeOneNum: number; 43 | 44 | @Column() 45 | prizeTwo: number; 46 | 47 | @Column() 48 | prizeTwoNum: number; 49 | 50 | @Column() 51 | bettingNum: number; 52 | 53 | @Column() 54 | drawDate: number; 55 | } -------------------------------------------------------------------------------- /src/core/postData/index.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | 3 | // only post fields(not upload file stream) 4 | 5 | const getPostData = (ctx: Context): Promise<{[key: string]: any}> => { 6 | 7 | return new Promise((resolve, reject) => { 8 | try{ 9 | let postData = '' 10 | ctx.req.on('data', data => { 11 | // console.log(data, 'data') 12 | postData += data 13 | }) 14 | 15 | ctx.req.on('end', () => { 16 | if(postData === '') { 17 | resolve({}) 18 | } else { 19 | resolve(JSON.parse(postData)) 20 | } 21 | }) 22 | } catch(e) { 23 | reject({err: e.toString()}) 24 | } 25 | }) 26 | } 27 | 28 | const KoaBody = async (ctx: Context, next: () => Promise) => { 29 | if(/^(POST|PUT)$/.test(ctx.method) && !/\/api\/upload/.test(ctx.path)) { 30 | ctx.fields = await getPostData(ctx) 31 | } 32 | // console.log('ctx.fields,', ctx.fields) 33 | await next() 34 | } 35 | 36 | export default KoaBody -------------------------------------------------------------------------------- /release/src/models/BaseModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tools_1 = require("../utils/tools"); 4 | var BaseModel = /** @class */ (function () { 5 | function BaseModel() { 6 | this._id = tools_1.Guid(); 7 | this._created_at = Date.now(); 8 | this.version = 0; 9 | } 10 | Object.defineProperty(BaseModel.prototype, "id", { 11 | // id: string 12 | get: function () { return this._id; }, 13 | set: function (_id) { this._id = _id; }, 14 | enumerable: true, 15 | configurable: true 16 | }); 17 | Object.defineProperty(BaseModel.prototype, "created_at", { 18 | get: function () { return this._created_at; }, 19 | set: function (_created_at) { this._created_at = _created_at; }, 20 | enumerable: true, 21 | configurable: true 22 | }); 23 | return BaseModel; 24 | }()); 25 | exports.BaseModel = BaseModel; 26 | //# sourceMappingURL=BaseModel.js.map -------------------------------------------------------------------------------- /src/routes/graphql.ts: -------------------------------------------------------------------------------- 1 | import * as Koa from '..koa' 2 | import { 3 | graphql, 4 | parse, 5 | Source, 6 | validate 7 | } from 'graphql' 8 | import {schema} from '../schema/demo' 9 | import {Delay} from '../utils/tools/index' 10 | 11 | export const world = async (ctx: Koa.Context) => { 12 | await Delay(1000) 13 | ctx.Json('world') 14 | } 15 | 16 | export const MyGraphql = async (ctx: Koa.Context) => { 17 | const params = ctx.body 18 | console.log(ctx.body, ctx.params, ctx.query) 19 | const source = new Source(ctx.query, 'GraphQL request') 20 | console.log('source: ', source) 21 | const result = await graphql(schema, ctx.query.query) 22 | const err = result.errors || [] 23 | for(let i = 0; i < err.length; i ++){ 24 | console.log('err: ', i, err[i].message, err[i].locations, err[i].stack) 25 | } 26 | // console.log('graphql: ', result.data, Object.prototype.toString.call(err)) 27 | ctx.Json({data: result.data, errors: err.length > 0 ? err[0].stack.split('\n') : undefined}) 28 | } 29 | -------------------------------------------------------------------------------- /src/daos/UserDao.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Equal, 3 | Like, 4 | Between, 5 | FindManyOptions, 6 | FindOptions, 7 | In, 8 | } from "typeorm"; 9 | import { Guid, cryptoPwd } from "../utils/tools" 10 | import { User } from '@/entities/mysql/user' 11 | import { useBlogRepository } from '@/database/dbUtils'; 12 | 13 | 14 | 15 | class UserDao { 16 | 17 | async getById(id: string) { 18 | const user = await useBlogRepository(User).findOne({ 19 | where: { 20 | id 21 | }, 22 | // select: ['id', 'username', 'nickName', 'remark'] 23 | }) 24 | return user 25 | } 26 | 27 | async getByUsername(username: string) { 28 | const user = await useBlogRepository(User).findOne({ 29 | where: { 30 | username 31 | } 32 | }) 33 | return user 34 | } 35 | 36 | async getByIds(ids: string[]) { 37 | const users = await useBlogRepository(User).find({ 38 | where: { 39 | id: In(ids) 40 | } 41 | }) 42 | return users 43 | } 44 | } 45 | 46 | export default new UserDao -------------------------------------------------------------------------------- /src/utils/session/store.ts: -------------------------------------------------------------------------------- 1 | import { useRedis } from '@/database/dbUtils'; 2 | import { randomBytes } from 'crypto'; 3 | 4 | // const { Guid } = TOOLS; 5 | 6 | export class RedisStore { 7 | private get redis() { 8 | return useRedis() 9 | } 10 | 11 | private getID(length: number): string { 12 | return randomBytes(length).toString('hex'); 13 | } 14 | 15 | public async get(sid: string): Promise { 16 | let data = await this.redis.get(sid); 17 | return JSON.parse(data); 18 | } 19 | 20 | public async set(obj: any, { sid = this.getID(32), maxAge }: any = {}): Promise { 21 | try { 22 | await this.redis.set(sid, JSON.stringify(obj), 'PX', maxAge) 23 | } catch (e) {} 24 | return sid; 25 | } 26 | 27 | public async destroy(sid: string): Promise { 28 | await this.redis.del(sid); 29 | } 30 | 31 | public async checkLogin(userId: string): Promise { 32 | const sid = await this.redis.get(userId); 33 | if (sid) await this.destroy(sid); 34 | return sid; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /release/src/schema/graphql/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/schema/graphql/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mCAOiB;AAEjB,qCAA+B;AAC/B,6CAAuC;AACvC,qCAA+B;AAC/B,6BAAuB;AACvB,+BAAyB;AACzB,+CAAqC;AACrC,iCAA2B;AAE3B,IAAI,KAAK,GAAG,CAAC,CAAA;AACb,IAAM,IAAI,GAAkD;IAC1D,KAAK,EAAE;QACL,IAAI,EAAE,oBAAU;QAChB,IAAI,EAAE;YACJ,EAAE,EAAE;gBACF,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,oBAAU,CAAC,QAAQ;aAC1B;SACF;QACD,OAAO,EAAE,UAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;YAC5B,EAAE,KAAK,CAAC;YACR,OAAO,KAAK,CAAC;QACf,CAAC;KACF;CACF,CAAA;AAED,IAAM,UAAU,GAAG,IAAI,uBAAa,CAAC;IACnC,KAAK,EAAE,IAAI,2BAAiB,CAAC;QAC3B,IAAI,EAAE,WAAW;QACjB,MAAM,eACD,IAAI,EACJ,iBAAO,CAAC,KAAK,EACb,qBAAW,CAAC,KAAK,EACjB,iBAAO,CAAC,KAAK,EACb,aAAG,CAAC,KAAK,EACT,cAAI,CAAC,KAAK,EACV,sBAAQ,CAAC,KAAK,EACd,eAAK,CAAC,KAAK,CACf;KACF,CAAC;IAEF,QAAQ,EAAE,IAAI,2BAAiB,CAAC;QAC9B,IAAI,EAAE,cAAc;QACpB,MAAM,eACD,iBAAO,CAAC,QAAQ,EAChB,qBAAW,CAAC,QAAQ,EACpB,iBAAO,CAAC,QAAQ,EAChB,aAAG,CAAC,QAAQ,EACZ,cAAI,CAAC,QAAQ,EACb,sBAAQ,CAAC,QAAQ,EACjB,eAAK,CAAC,QAAQ,CAClB;KACF,CAAC;CACH,CAAC,CAAA;AAIA,gCAAU"} -------------------------------------------------------------------------------- /src/entities/mysql/shares/stock.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import {Entity, Column, PrimaryColumn} from "typeorm"; 3 | 4 | @Entity('stocks') 5 | export class Stock { 6 | @PrimaryColumn({ unique: true }) 7 | id: number 8 | 9 | @Column() 10 | uuid: string 11 | 12 | @Column() 13 | name: string 14 | 15 | @Column() 16 | code: string 17 | 18 | @Column() 19 | market: number 20 | 21 | @Column() 22 | block: number 23 | 24 | @Column() 25 | amount: number // 单手成交数量 26 | 27 | } 28 | 29 | 30 | export class StockDetail extends Stock { 31 | constructor(arg: Stock) { 32 | super() 33 | this.id = arg.id 34 | this.name = arg.name 35 | this.code = arg.code 36 | this.market = arg.market 37 | this.block = arg.block 38 | this.amount = arg.amount 39 | // this.lastestTradeAt = 0 40 | } 41 | 42 | lastestTradeAt = 0 43 | 44 | // private _lastestTradeAt = 0 45 | 46 | // get lastestTradeAt() { 47 | // return this._lastestTradeAt 48 | // } 49 | // set lastestTradeAt(val) { 50 | // this._lastestTradeAt = +val 51 | // } 52 | } -------------------------------------------------------------------------------- /release/src/core/postData/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/postData/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAmCsB;;AAjCtB,2CAA2C;AAE3C,IAAM,WAAW,GAAG,UAAC,GAAY;IAE/B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAG;YACD,IAAI,UAAQ,GAAG,EAAE,CAAA;YACjB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAA,IAAI;gBACrB,4BAA4B;gBAC5B,UAAQ,IAAI,IAAI,CAAA;YAClB,CAAC,CAAC,CAAA;YAEF,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;gBAChB,IAAG,UAAQ,KAAK,EAAE,EAAE;oBAClB,OAAO,CAAC,EAAE,CAAC,CAAA;iBACZ;qBAAM;oBACL,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,UAAQ,CAAC,CAAC,CAAA;iBAC9B;YACH,CAAC,CAAC,CAAA;SACH;QAAC,OAAM,CAAC,EAAE;YACT,MAAM,CAAC,EAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAC,CAAC,CAAA;SAC5B;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,IAAM,OAAO,GAAG,UAAO,GAAY,EAAE,IAAwB;;;;;qBACxD,CAAA,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA,EAAlE,wBAAkE;gBACnE,KAAA,GAAG,CAAA;gBAAU,qBAAM,WAAW,CAAC,GAAG,CAAC,EAAA;;gBAAnC,GAAI,MAAM,GAAG,SAAsB,CAAA;;;YAErC,yCAAyC;YACzC,qBAAM,IAAI,EAAE,EAAA;;gBADZ,yCAAyC;gBACzC,SAAY,CAAA;;;;KACb,CAAA;AAED,kBAAe,OAAO,CAAA"} -------------------------------------------------------------------------------- /src/controllers/FileController.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from 'buffer'; 2 | import { Context } from 'koa' 3 | 4 | const getFile = (ctx: Context) => { 5 | 6 | return new Promise((resolve, reject) => { 7 | try{ 8 | let buf: Buffer 9 | let arr: Buffer[] = [] 10 | ctx.req.on('data', (data: Buffer) => { 11 | try{ 12 | arr.push(data) 13 | } catch(e) { 14 | reject(e) 15 | } 16 | }) 17 | 18 | ctx.req.on('end', () => { 19 | try{ 20 | buf = Buffer.concat(arr) 21 | if(buf.length <= 0) { 22 | resolve({}) 23 | } else { 24 | resolve(buf) 25 | } 26 | } catch(e) { 27 | reject(e) 28 | } 29 | 30 | }) 31 | } catch(e) { 32 | reject(e) 33 | } 34 | }) 35 | } 36 | 37 | class FileController { 38 | 39 | async upload (ctx: Context) { 40 | const file: any = await getFile(ctx) 41 | console.log(file, 'file') 42 | ctx.Json({ 43 | data:{ 44 | path: '/a/b/c/d.jpg', 45 | name: 'heheda' 46 | }, 47 | msg: file.length 48 | }) 49 | } 50 | 51 | } 52 | 53 | export default new FileController -------------------------------------------------------------------------------- /release/src/utils/session/store.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/utils/session/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAqC;AACrC,+BAAiC;AACjC,iDAAiD;AAEjD,0BAA0B;AAE1B;IAGE;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,mBAAS,CAAC,CAAC;IACpC,CAAC;IAEO,0BAAK,GAAb,UAAc,MAAc;QAC1B,OAAO,oBAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAEY,wBAAG,GAAhB,UAAiB,GAAW;;;;;4BACf,qBAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAA;;wBAAhC,IAAI,GAAG,SAAyB;wBACpC,sBAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAC;;;;KACzB;IAEY,wBAAG,GAAhB,UAAiB,GAAQ,EAAE,EAA2C;YAA3C,4BAA2C,EAAzC,WAAqB,EAArB,yCAAqB,EAAE,kBAAM;;;;;;;wBAEtD,qBAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAA;;wBAA5D,SAA4D,CAAA;;;;;4BAE9D,sBAAO,GAAG,EAAC;;;;KACZ;IAEY,4BAAO,GAApB,UAAqB,GAAW;;;;4BAC9B,qBAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;;;;;KAC3B;IAEY,+BAAU,GAAvB,UAAwB,MAAc;;;;;4BACxB,qBAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAA;;wBAAlC,GAAG,GAAG,SAA4B;6BACpC,GAAG,EAAH,wBAAG;wBAAE,qBAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;wBAAvB,SAAuB,CAAC;;4BACjC,sBAAO,GAAG,EAAC;;;;KACZ;IACH,iBAAC;AAAD,CAAC,AAhCD,IAgCC;AAED,kBAAe,UAAU,CAAC"} -------------------------------------------------------------------------------- /release/src/routes/graphql.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/routes/graphql.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA4BA;;AA3BA,mCAKgB;AAChB,uCAAqC;AACrC,8CAA0C;AAE7B,QAAA,KAAK,GAAG,UAAO,GAAgB;;;oBAC1C,qBAAM,aAAK,CAAC,IAAI,CAAC,EAAA;;gBAAjB,SAAiB,CAAA;gBACjB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;;;;KAClB,CAAA;AAEY,QAAA,SAAS,GAAG,UAAO,GAAgB;;;;;gBACxC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAA;gBACvB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;gBACtC,MAAM,GAAG,IAAI,gBAAM,CAAC,GAAG,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;gBACvD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;gBAChB,qBAAM,iBAAO,CAAC,aAAM,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;gBAA/C,MAAM,GAAG,SAAsC;gBAC/C,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAA;gBAC/B,KAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAG,EAAC;oBAClC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;iBACxE;gBACD,6EAA6E;gBAC7E,GAAG,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,EAAC,CAAC,CAAA;;;;KAC7F,CAAA"} -------------------------------------------------------------------------------- /release/src/database/conectDB.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"conectDB.js","sourceRoot":"","sources":["../../../src/database/conectDB.ts"],"names":[],"mappings":";;AAAA,4BAAyB;AACzB,mCAA2C;AAC3C,8CAAyD;AACzD,2CAA4C;AAC5C,2CAAiD;AAEjD,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,IAAM,SAAS,GAAG;IAChB,0BAAgB,CAAC;QACf,IAAI,EAAO,OAAO;QAClB,IAAI,EAAO,mBAAS,CAAC,IAAI;QACzB,IAAI,EAAO,mBAAS,CAAC,IAAI;QACzB,QAAQ,EAAG,mBAAS,CAAC,QAAQ;QAC7B,QAAQ,EAAG,mBAAS,CAAC,QAAQ;QAC7B,QAAQ,EAAG,mBAAS,CAAC,QAAQ;QAC7B,QAAQ,EAAG,gBAAQ;QACnB,OAAO,EAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;KAEjC,CAAC,CAAC,IAAI,CAAC,UAAC,OAAO;QACd,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;IACvC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAC,GAAG;QACX,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAqBC,8BAAS;AAnBX,IAAM,YAAY,GAAG;IACnB,0BAAgB,CAAC;QACf,IAAI,EAAO,OAAO;QAClB,IAAI,EAAO,SAAS;QACpB,IAAI,EAAO,mBAAS,CAAC,IAAI;QACzB,IAAI,EAAO,mBAAS,CAAC,IAAI;QACzB,iCAAiC;QACjC,iCAAiC;QACjC,QAAQ,EAAG,mBAAS,CAAC,QAAQ;QAC7B,QAAQ,EAAG,qBAAa;QACxB,OAAO,EAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;KACjC,CAAC,CAAC,IAAI,CAAC,UAAC,OAAO;QACd,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;IACvC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAC,GAAG;QACX,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAIC,oCAAY"} -------------------------------------------------------------------------------- /release/src/controllers/FileController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"FileController.js","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AE,cAAc;gCACpB,IAAI,EAAE,QAAQ;6BACf;4BACD,GAAG,EAAE,IAAI,CAAC,MAAM;yBACjB,CAAC,CAAA;;;;;KACH;IAEH,qBAAC;AAAD,CAAC,AAdD,IAcC"} -------------------------------------------------------------------------------- /release/src/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM;AACN,yBAA0B;AAC1B,sCAAuC;AAEvC,6CAAuC;AACvC,6CAA6C;AAC7C,gDAA2D;AAE3D,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAA;AAEpD;IAGC;QACC,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;QACpB,IAAI,CAAC,IAAI,EAAE,CAAA;IACZ,CAAC;IAED,mBAAmB;IACX,0BAAI,GAAZ;QAAA,iBAiBC;QAhBA,IAAG,KAAK,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAA;SACzB;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,eAAK,CAAC,CAAA,CAAC,kBAAkB;QACtC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,eAAe;QAC7C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAO,GAAY,EAAE,IAAwB;;;;;wBACnD,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAA;wBAC7B,OAAO,CAAC,GAAG,CAAC,WAAS,IAAM,CAAC,CAAA;wBAC5B,IAAG,IAAI,KAAK,GAAG,EAAE;4BAChB,GAAG,CAAC,IAAI,GAAG,gCAAgC,CAAA;yBAC3C;wBACD,qBAAM,IAAI,EAAE,EAAA;;wBAAZ,SAAY,CAAA;wBACZ,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;;;;aACjC,CAAC,CAAA;QAEF,eAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,YAAY;IACL,2BAAK,GAAZ,UAAa,IAAY;QACxB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE;YACrB,OAAO,CAAC,GAAG,CAAC,4DAA0D,IAAI,OAAI,CAAC,CAAA;YAC/E,oBAAS,EAAE,CAAA,CAAC,gCAAgC;YAC5C,uBAAY,EAAE,CAAA,CAAC,kBAAkB;QAClC,CAAC,CAAC,CAAA;IACH,CAAC;IACF,kBAAC;AAAD,CAAC,AApCD,IAoCC;AAED,kBAAe,IAAI,WAAW,EAAE,CAAA"} -------------------------------------------------------------------------------- /src/middlewares/auth.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import { store } from "@/utils/session"; 3 | import { JWT_KEY, NO_AUTH_URLS } from '../constants' 4 | 5 | // const store = new Store 6 | 7 | export default async(ctx: Context, next: () => Promise) => { 8 | const method = ctx.method 9 | const path = ctx.path 10 | if(NO_AUTH_URLS.some(urlReg => urlReg[0].test(path) && urlReg[1].test(method))) { 11 | await next() 12 | } else { 13 | const token: string = ctx.header['authorization'].split(' ')[1] || '' // after jwt, token must exist 14 | const authorized = await store.get(token) 15 | if(authorized) { // redis exist jwt token 16 | const fields: any = ctx.fields 17 | const USER_TYPE = ctx.state[JWT_KEY].userType 18 | if( 19 | method === 'GET' || // all get, pass 20 | USER_TYPE !== 9 || // not demo user, pass 21 | (USER_TYPE === 9 && NO_AUTH_URLS.some(urlReg => urlReg[0].test(path) && urlReg[1].test(method))) || // demo user, but not auth urls, pass 22 | (path === '/graphql' && !/^\smutation\s/.test(fields.query)) || // grahpql not mutation, pass 23 | (USER_TYPE === 9 && path === '/api/logout') // demo use logout, pass 24 | ) { 25 | await next() 26 | } else { 27 | ctx.throw(403, '测试用户禁止访问!') 28 | } 29 | } else { 30 | ctx.throw(401) 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/controllers/ServerAPIController.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import $http from '../utils/http' 3 | 4 | 5 | export default class ServerAPIController { 6 | 7 | static async KDJZ (ctx: Context) { 8 | const HOST = '' 9 | const token = ctx.header['token'] 10 | const UA = ctx.header['user-agent'] 11 | let path = ctx.path 12 | const input = ctx.fields 13 | 14 | if(/^\/platform/.test(path)) { 15 | const result = await $http.post(HOST + path, input, { 16 | headers: { 17 | 'token': token, 18 | 'User-Agent': UA 19 | } 20 | }) 21 | // console.log(result) 22 | ctx.body = result 23 | } else { 24 | ctx.body = { data: {}, msg: 'empty' } 25 | } 26 | } 27 | 28 | static async compose (ctx: Context) { 29 | const HOST = 'https://www.google.com' 30 | console.log('--react--') 31 | const token = ctx.header['token'] 32 | const UA = ctx.header['user-agent'] 33 | let path = ctx.path 34 | const input = ctx.fields 35 | if(/^\/platform/.test(path)) { 36 | const result = await $http.post(HOST + path, input, { 37 | headers: { 38 | 'token': token, 39 | 'User-Agent': UA 40 | } 41 | }) 42 | ctx.body = result.data 43 | } else { 44 | ctx.body = { data: {}, msg: 'empty' } 45 | } 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /release/src/middlewares/auth.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/middlewares/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAgCC;;AA/BD,gDAA2C;AAC3C,0CAAoD;AAEpD,IAAM,KAAK,GAAG,IAAI,eAAK,CAAA;AAEvB,mBAAe,UAAM,GAAY,EAAE,IAAwB;;;;;gBACnD,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;gBACnB,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;qBAClB,wBAAY,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,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A;;;;gBAG7B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;;;;;KAGnB,EAAA"} -------------------------------------------------------------------------------- /release/src/controllers/ServerAPIController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ServerAPIController.js","sourceRoot":"","sources":["../../../src/controllers/ServerAPIController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sCAAiC;AAGjC;IAAA;IA4CA,CAAC;IA1Cc,wBAAI,GAAjB,UAAmB,GAAY;;;;;;wBACvB,IAAI,GAAG,EAAE,CAAA;wBACT,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;wBAC3B,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;wBAC/B,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;wBACb,KAAK,GAAI,GAAG,CAAC,MAAM,CAAA;6BAEtB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAxB,wBAAwB;wBACV,qBAAM,cAAK,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE;gCAClD,OAAO,EAAE;oCACP,OAAO,EAAE,KAAK;oCACd,YAAY,EAAE,EAAE;iCACjB;6BACF,CAAC;4BACF,sBAAsB;0BADpB;;wBALI,MAAM,GAAG,SAKb;wBACF,sBAAsB;wBACtB,GAAG,CAAC,IAAI,GAAG,MAAM,CAAA;;;wBAEjB,GAAG,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;;;;;;KAExC;IAEY,2BAAO,GAApB,UAAsB,GAAY;;;;;;wBAC1B,IAAI,GAAG,wBAAwB,CAAA;wBACrC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;wBAClB,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;wBAC3B,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;wBAC/B,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;wBACb,KAAK,GAAI,GAAG,CAAC,MAAM,CAAA;6BACtB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAxB,wBAAwB;wBACV,qBAAM,cAAK,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE;gCAClD,OAAO,EAAE;oCACP,OAAO,EAAE,KAAK;oCACd,YAAY,EAAE,EAAE;iCACjB;6BACF,CAAC,EAAA;;wBALI,MAAM,GAAG,SAKb;wBACF,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;;;wBAEtB,GAAG,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;;;;;;KAGxC;IAEH,0BAAC;AAAD,CAAC,AA5CD,IA4CC"} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "koa-ts-graphql", 3 | "version": "1.0.0", 4 | "description": "A Koa2 project with TypeScript/GraphQL", 5 | "author": "xpioneer", 6 | "license": "MIT", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/xpioneer/koa-graphql-typescript.git" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/xpioneer/koa-graphql-typescript/issues" 13 | }, 14 | "scripts": { 15 | "start": "npm run dev", 16 | "build": "tsc", 17 | "build-server": "tslint --project . && tsc", 18 | "dev": "NODE_ENV=development nodemon --config nodemon.json", 19 | "test": "NODE_ENV=development node ./release/conf/server.js" 20 | }, 21 | "dependencies": { 22 | "axios": "^0.21.1", 23 | "dataloader": "^2.0.0", 24 | "date-fns": "^2.23.0", 25 | "graphql": "^15.5.1", 26 | "ioredis": "^5.4.1", 27 | "koa": "^2.15.3", 28 | "koa-jwt": "^3.5.1", 29 | "koa-router": "^7.4.0", 30 | "mongodb": "^6.8.0", 31 | "mysql2": "^3.11.0", 32 | "reflect-metadata": "^0.2.2", 33 | "remove": "^0.1.5", 34 | "typeorm": "^0.3.20" 35 | }, 36 | "devDependencies": { 37 | "@types/graphql": "^14.5.0", 38 | "@types/koa": "^2.15.0", 39 | "@types/koa-logger": "^3.1.1", 40 | "@types/koa-router": "^7.0.32", 41 | "@types/node": "^16.6.0", 42 | "koa-logger": "^3.2.0", 43 | "nodemon": "^3.1.4", 44 | "ts-node": "^10.2.0", 45 | "tsconfig-paths": "^4.1.2", 46 | "typescript": "^5.5.4" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /release/src/routes/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Router = require("koa-router"); 4 | var graphql_1 = require("../core/graphql"); 5 | var index_1 = require("../schema/graphql/index"); 6 | var DemoController_1 = require("../controllers/DemoController"); 7 | var AccountController_1 = require("../controllers/AccountController"); 8 | var FileController_1 = require("../controllers/FileController"); 9 | var LogsController_1 = require("../controllers/LogsController"); 10 | var ServerAPIController_1 = require("../controllers/ServerAPIController"); 11 | var _PROD_ = process.env.NODE_ENV === 'production'; 12 | var router = new Router(); 13 | router 14 | .post('/api/login', AccountController_1.default.login) 15 | .post('/api/logout', AccountController_1.default.logout) 16 | .get('/view/:site', DemoController_1.default.views) 17 | .post('/api/compose', DemoController_1.default.compose) 18 | .post('/platform/*', ServerAPIController_1.default.KDJZ) 19 | .get('/api/log-api', LogsController_1.default.apiPages) 20 | .get('/api/log-errors', LogsController_1.default.errorsPages) 21 | .post('/api/upload', FileController_1.default.upload) 22 | .get('/graphql', graphql_1.KoaGraphql({ 23 | schema: index_1.RootSchema, 24 | graphql: _PROD_ ? false : true 25 | })) 26 | .post('/graphql', graphql_1.KoaGraphql({ 27 | schema: index_1.RootSchema, 28 | })); 29 | exports.default = router; 30 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /release/src/utils/session/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","s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AE,CAAC;yBAEb,EAAE,EAAF,wBAAE;oBACJ,qBAAM,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAA;;oBAAvB,SAAuB,CAAC;oBACxB,sBAAO;wBAWC,qBAAM,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,EAAA;;oBAAxE,GAAG,GAAG,SAAkE;oBAC9E,mBAAmB;oBACnB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;;;;SAEjC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"} -------------------------------------------------------------------------------- /release/src/controllers/CommentController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"CommentController.js","sourceRoot":"","sources":["../../../src/controllers/CommentController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAkF;AAElF,qDAAmD;AAEnD,+BAAgC;AAEhC;IAAA;IAmCA,CAAC;IAjCc,wBAAM,GAAnB,UAAoB,IAAS;;;;4BACpB,qBAAM,oBAAU,EAAE,CAAC,IAAI,CAAC,iBAAO,CAAC,EAAA;4BAAvC,sBAAO,SAAgC,EAAC;;;;KACzC;IAGY,yBAAO,GAApB,UAAqB,EAAe;QAAf,mBAAA,EAAA,OAAe;;;;;4BAClB,qBAAM,uBAAa,CAAC,iBAAO,CAAC,CAAC,OAAO,CAAC,EAAC,EAAE,IAAA,EAAC,CAAC,EAAA;;wBAApD,OAAO,GAAG,SAA0C;wBAC1D,sBAAO,OAAO,EAAA;;;;KACf;IAEY,uBAAK,GAAlB,UAAmB,IAAS;;;;;;wBACpB,OAAO,GAA6B;4BACxC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ;4BACzD,IAAI,EAAE,IAAI,CAAC,QAAQ;4BACnB,KAAK,EAAE,EAAE;4BACT,KAAK,EAAE;gCACL,SAAS,EAAE,IAAI;6BAChB;yBACF,CAAA;wBACD,IAAG,IAAI,CAAC,WAAW,EAAE;4BACnB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,cAAI,CAAC,MAAI,IAAI,CAAC,WAAW,MAAG,CAAC,CAAA;yBAC7D;wBACD,IAAG,IAAI,CAAC,SAAS,EAAE;4BACX,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAC,CAAS,IAAK,OAAA,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAArB,CAAqB,CAAC,CAAA;4BACrE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;yBACvD;wBACD,IAAG,IAAI,CAAC,KAAK,EAAE;4BACb,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;yBACzD;wBACa,qBAAM,uBAAa,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,EAAA;;wBAA5D,KAAK,GAAG,SAAoD;wBAClE,sBAAO,KAAK,EAAA;;;;KACb;IAEH,wBAAC;AAAD,CAAC,AAnCD,IAmCC"} -------------------------------------------------------------------------------- /release/src/controllers/LeaveMessageController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"LeaveMessageController.js","sourceRoot":"","sources":["../../../src/controllers/LeaveMessageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAkF;AAElF,+DAA6D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vD;wBACD,IAAG,IAAI,CAAC,KAAK,EAAE;4BACb,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;yBACzD;wBACa,qBAAM,uBAAa,CAAC,2BAAY,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,EAAA;;wBAA/D,KAAK,GAAG,SAAuD;wBACrE,sBAAO,KAAK,EAAA;;;;KACb;IAEH,6BAAC;AAAD,CAAC,AApCD,IAoCC"} -------------------------------------------------------------------------------- /release/src/core/jwt/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/jwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAwDE;;AAvDF,mCAAiC;AAYjC,6BAA6B;AAE7B,mBAAe,UAAC,IAAa;IACnB,IAAA,kBAAK,EAAE,aAAgB,EAAhB,qCAAgB,EAAE,oBAAM,EAAE,8BAAW,EAAE,wBAAQ,CAAU;IAExE,OAAO,UAAO,GAAY,EAAE,IAAwB;;;;;oBAC5C,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;yBACtB,MAAM,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAlD,CAAkD,CAAC,EAAzE,wBAAyE;oBAC1E,qBAAM,IAAI,EAAE,EAAA;;oBAAZ,SAAY,CAAA;;;oBAER,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;oBAEvC,IAAG,CAAC,KAAK,EAAE;wBACT,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAA;qBACnE;oBAEc,KAA2B,GAAG,aAAV,EAApB,MAAM,mBAAG,IAAI,CAAC,MAAM,KAAA,CAAW;oBAE9C,IAAI;wBACF,IAAI,CAAC,MAAM,EAAE;4BACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;yBACxC;wBAEK,MAAM,GAAG,eAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;wBAClC,IAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;4BACb,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAA;yBAC3D;wBAED,OAAO;wBACP,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;wBAC3B,IAAG,QAAQ,EAAE;4BACX,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;yBACvB;qBAEF;oBAAC,OAAM,CAAC,EAAE;wBACH,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC;wBACvD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;qBAC3C;oBAED,qBAAM,IAAI,EAAE,EAAA,CAAC,qBAAqB;;oBAAlC,SAAY,CAAA,CAAC,qBAAqB;;;;;SAGrC,CAAA;AACH,CAAC,EAAA"} -------------------------------------------------------------------------------- /src/schema/graphql/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLObjectType, 3 | GraphQLSchema, 4 | GraphQLInt, 5 | Thunk, 6 | GraphQLFieldConfigMap, 7 | Source 8 | } from 'graphql'; 9 | import {Context} from 'koa' 10 | import Article from './Article' 11 | import ArticleType from './ArticleType' 12 | import Comment from './Comment' 13 | import Tag from './Tag' 14 | import User from './User' 15 | import LeaveMsg from './LeaveMessage' 16 | import Balls from './Balls' 17 | 18 | let count = 0 19 | const demo: Thunk> = { 20 | count: { 21 | type: GraphQLInt, 22 | args: { 23 | id: { 24 | // name: 'id', 25 | type: GraphQLInt // 参数不为空 26 | } 27 | }, 28 | resolve: (obj, args, ctx, info) => { 29 | ++count; 30 | return count; 31 | } 32 | }, 33 | } 34 | 35 | const RootSchema = new GraphQLSchema({ 36 | query: new GraphQLObjectType({ 37 | name: 'RootQuery', 38 | fields: { 39 | ...demo, 40 | ...Article.query, 41 | ...ArticleType.query, 42 | ...Comment.query, 43 | ...Tag.query, 44 | ...User.query, 45 | ...LeaveMsg.query, 46 | ...Balls.query 47 | } 48 | }), 49 | 50 | mutation: new GraphQLObjectType({ 51 | name: 'RootMutation', 52 | fields: { 53 | ...Article.mutation, 54 | ...ArticleType.mutation, 55 | ...Comment.mutation, 56 | ...Tag.mutation, 57 | ...User.mutation, 58 | ...LeaveMsg.mutation, 59 | ...Balls.mutation 60 | } 61 | }) 62 | }) 63 | 64 | 65 | export { 66 | RootSchema 67 | }; 68 | -------------------------------------------------------------------------------- /release/src/controllers/AccountController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AccountController.js","sourceRoot":"","sources":["../../../src/controllers/AccountController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA+D;AAE/D,+CAA6C;AAC7C,gDAA2C;AAC3C,0CAAmD;AACnD,yCAAuC;AACvC,wCAA0C;AAE1C,IAAM,KAAK,GAAG,IAAI,eAAK,CAAA;AAEvB;IAAA;IAsCA,CAAC;IApCC,MAAM;IACO,uBAAK,GAAlB,UAAmB,GAAY;;;;;;wBACvB,MAAM,GAAQ,GAAG,CAAC,MAAM,CAAC;wBAC3B,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;wBAC3B,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;6BAC3B,C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,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;;;;;KACrC;IAEH,wBAAC;AAAD,CAAC,AAtCD,IAsCC"} -------------------------------------------------------------------------------- /src/entities/mysql/shares/stockHistory.ts: -------------------------------------------------------------------------------- 1 | import 'reflect-metadata' 2 | import { Entity, Column, PrimaryColumn} from "typeorm"; 3 | import { Stock } from './stock'; 4 | 5 | export type KeyofHistory = keyof History 6 | 7 | @Entity('stock_history_new') 8 | export class History { 9 | @PrimaryColumn({ unique: true }) 10 | id: number 11 | 12 | @Column() 13 | stockId: number 14 | 15 | @Column() 16 | timestamp: number 17 | 18 | @Column() 19 | volume: number 20 | 21 | @Column() 22 | open: number 23 | 24 | @Column() 25 | high: number 26 | 27 | @Column() 28 | low: number 29 | 30 | @Column() 31 | close: number 32 | 33 | @Column() 34 | chg: number 35 | 36 | @Column() 37 | percent: number 38 | 39 | @Column() 40 | turnoverrate: number 41 | 42 | @Column() 43 | amount: number 44 | 45 | @Column() 46 | volume_post: number 47 | 48 | @Column() 49 | amount_post: number 50 | 51 | @Column() 52 | pe: number 53 | 54 | @Column() 55 | pb: number 56 | 57 | @Column() 58 | ps: number 59 | 60 | @Column() 61 | pcf: number 62 | 63 | @Column() 64 | market_capital: number 65 | 66 | @Column() 67 | balance: number 68 | 69 | @Column() 70 | hold_volume_cn: number 71 | 72 | @Column() 73 | hold_ratio_cn: number 74 | 75 | @Column() 76 | net_volume_cn: number 77 | 78 | @Column() 79 | hold_volume_hk: number 80 | 81 | @Column() 82 | hold_ratio_hk: number 83 | 84 | @Column() 85 | net_volume_hk: number 86 | } 87 | 88 | 89 | export type StockHistory = History & Stock & { 90 | tradeAt: string 91 | } -------------------------------------------------------------------------------- /src/utils/session/index.ts: -------------------------------------------------------------------------------- 1 | // import * as Koa from 'core/koa' 2 | // import * as Cookies from "cookies"; 3 | import { Context } from "koa"; 4 | import { RedisStore } from "./store"; 5 | 6 | export const store = new RedisStore; 7 | 8 | class SessionOptions { 9 | key: string = 'SESSION_ID' 10 | store = store 11 | signed: boolean 12 | maxAge: number 13 | } 14 | 15 | 16 | const Session = (opts: SessionOptions = new SessionOptions) => { 17 | const { key, store } = opts; 18 | 19 | return async (ctx: Context, next: () => Promise) => { 20 | let id = ctx.cookies.get(key, opts); 21 | if (id) { 22 | ctx.session = await store.get(id); 23 | if (typeof ctx.session !== "object" || ctx.session == null) { 24 | ctx.session = {}; 25 | id = undefined; // clear old id 26 | } 27 | } else { 28 | ctx.session = {}; 29 | } 30 | 31 | const old = JSON.stringify(ctx.session); 32 | 33 | await next(); // any calc 34 | 35 | // if is an empty object 36 | if (ctx.session instanceof Object && !Object.keys(ctx.session).length) { 37 | ctx.session = {}; 38 | // need clear old session 39 | if (id) { 40 | await store.destroy(id); 41 | return; 42 | } 43 | } 44 | 45 | // need clear old session 46 | // if (id && !ctx.session) { 47 | // await store.destroy(id); 48 | // return; 49 | // } 50 | 51 | // set/update session 52 | const sid = await store.set(ctx.session, Object.assign({}, opts, { sid: id })); 53 | // need to optimize 54 | ctx.cookies.set(key, sid, opts); 55 | 56 | }; 57 | }; 58 | 59 | export default Session; 60 | -------------------------------------------------------------------------------- /src/services/StockService.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Equal, 3 | Like, 4 | Between, 5 | FindManyOptions 6 | } from "typeorm"; 7 | import { Stock, StockDetail } from '../entities/mysql/shares/stock' 8 | import { EMarket, EBLock } from '../models/Stocks' 9 | import StockDao from '../daos/StockDao' 10 | import StockHistoryDao from '../daos/StockHistoryDao' 11 | 12 | 13 | class StockService { 14 | 15 | async getById(id: number) { 16 | const stock = await StockDao.getById(id); 17 | return stock 18 | } 19 | 20 | async getByIds(ids: number[]) { 21 | const stocks = await StockDao.getByIds(ids); 22 | return stocks 23 | } 24 | 25 | async getCode(id: number) { 26 | const stock = await StockDao.getCode(id); 27 | const lastestTrade = await StockHistoryDao.getLastestTrade(stock.id) 28 | const detail = new StockDetail(stock) 29 | console.log(detail, '---------') 30 | detail.lastestTradeAt = lastestTrade ? lastestTrade.timestamp : null 31 | return detail 32 | } 33 | 34 | async getByCode(code: string) { 35 | const stock = await StockDao.getByCode(code); 36 | return stock 37 | } 38 | 39 | async getStockList(value: string, pageSize = 10) { 40 | const list = await StockDao.getStockList(value) 41 | return list 42 | } 43 | 44 | async pages(offset = 1, size = 10, code?: string, name?: string, market?: EMarket, block?: EBLock) { 45 | const pages = await StockDao.pages(offset, size, code, name, market, block); 46 | return pages 47 | } 48 | 49 | async getBlocksCount() { 50 | const counts = await StockDao.getBlocksCount() 51 | return counts 52 | } 53 | } 54 | 55 | export default new StockService -------------------------------------------------------------------------------- /src/core/jwt/index.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import { verify } from './verify' 3 | 4 | export interface Options { 5 | secret: string | Buffer 6 | key?: string 7 | debug?: boolean 8 | encoding?: BufferEncoding 9 | passthrough?: boolean 10 | tokenKey?: string 11 | unless?: RegExp[][] 12 | } 13 | 14 | // verify jwt, koa middleware 15 | 16 | export default (opts: Options) => { 17 | const { debug, key = 'jwt-user', unless, passthrough, tokenKey } = opts; 18 | 19 | return async (ctx: Context, next: () => Promise) => { 20 | const method = ctx.method 21 | if(unless.some(urlReg => urlReg[0].test(ctx.path) && urlReg[1].test(method))) { 22 | await next() 23 | } else { 24 | let token = ctx.header['authorization'] 25 | // console.log(ctx.header, 'ctx.header>>>>') 26 | 27 | if(!token) { 28 | ctx.throw(401, debug ? 'Token not found' : 'Authentication Error') 29 | } 30 | 31 | let { state: { secret = opts.secret } } = ctx; 32 | 33 | try { 34 | if (!secret) { 35 | throw new Error('Secret not provided'); 36 | } 37 | 38 | const result = verify(token, opts) 39 | if(!result[0]) { 40 | ctx.throw(401, debug ? result[1] : 'Authentication Error') 41 | } 42 | 43 | // pass 44 | ctx.state[key] = result[1]; 45 | if(tokenKey) { 46 | ctx.state[key] = token 47 | } 48 | 49 | } catch(e) { 50 | const msg = debug ? e.message : 'Authentication Error'; 51 | ctx.throw(401, msg, { originalError: e }); 52 | } 53 | 54 | await next() // authorized, next() 55 | } 56 | 57 | } 58 | } -------------------------------------------------------------------------------- /src/controllers/CommentController.ts: -------------------------------------------------------------------------------- 1 | import { Like, Between, FindManyOptions, Equal} from "typeorm"; 2 | import { Context } from 'koa' 3 | import { Comment } from '../entities/mysql/comment' 4 | import { Guid } from "../utils/tools"; 5 | import { endOfDay, startOfDay } from 'date-fns' 6 | import { useBlogRepository } from '../database/dbUtils'; 7 | 8 | class CommentController { 9 | 10 | getAll(args: any) { 11 | return useBlogRepository(Comment).findAndCount(); 12 | } 13 | 14 | 15 | getById(id = '') { 16 | const article = useBlogRepository(Comment).findOne({ 17 | where: { 18 | id: Equal(id) 19 | } 20 | }) 21 | return article 22 | } 23 | 24 | pages(args: any) { 25 | const options: FindManyOptions = { 26 | skip: args.page < 2 ? 0 : (args.page - 1) * args.pageSize, 27 | take: args.pageSize, 28 | order: {}, 29 | where: { 30 | deletedAt: null 31 | }, 32 | select: ['id', 'description', 'articleId', 'client', 'createdAt', 'createdBy', 'updatedAt'] 33 | } 34 | if(args.description) { 35 | options.where['description'] = Like(`%${args.description}%`) 36 | } 37 | if(args.createdAt) { 38 | const date = (args.createdAt as string[]).map( 39 | (d, i) => i > 0 ? +endOfDay(new Date(d)) : +startOfDay(new Date(d)) 40 | ) 41 | options.where['createdAt'] = Between(date[0], date[1]) 42 | } 43 | if(args.order) { 44 | options.order = Object.assign(options.order, args.order) 45 | } 46 | const pages = useBlogRepository(Comment).findAndCount(options) 47 | return pages 48 | } 49 | 50 | } 51 | 52 | export default new CommentController 53 | -------------------------------------------------------------------------------- /src/controllers/LeaveMessageController.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Like, 3 | Between, 4 | FindManyOptions, 5 | Equal 6 | } from "typeorm"; 7 | import { Context } from 'koa' 8 | import { LeaveMessage } from '../entities/mysql/leaveMessage' 9 | import { Guid } from "../utils/tools"; 10 | import { endOfDay, startOfDay } from 'date-fns' 11 | import { useBlogRepository } from '../database/dbUtils'; 12 | 13 | 14 | class LeaveMessageController { 15 | 16 | getAll(args: any) { 17 | return useBlogRepository(LeaveMessage).findAndCount(); 18 | } 19 | 20 | 21 | getById(id = '') { 22 | const leaveMsg = useBlogRepository(LeaveMessage).findOne({ 23 | where: { 24 | id: Equal(id) 25 | } 26 | }) 27 | return leaveMsg 28 | } 29 | 30 | pages(args: any) { 31 | const options: FindManyOptions = { 32 | skip: args.page < 2 ? 0 : (args.page - 1) * args.pageSize, 33 | take: args.pageSize, 34 | order: {}, 35 | where: { 36 | deletedAt: null 37 | }, 38 | select: ['id', 'description', 'createdAt', 'createdBy', 'updatedAt'], 39 | } 40 | if(args.description) { 41 | options.where['description'] = Like(`%${args.description}%`) 42 | } 43 | if(args.createdAt) { 44 | const date = (args.createdAt as string[]).map( 45 | (d, i) => i > 0 ? +endOfDay(new Date(d)) : +startOfDay(new Date(d)) 46 | ) 47 | options.where['createdAt'] = Between(date[0], date[1]) 48 | } 49 | if(args.order) { 50 | options.order = Object.assign(options.order, args.order) 51 | } 52 | const pages = useBlogRepository(LeaveMessage).findAndCount(options) 53 | return pages 54 | } 55 | 56 | } 57 | 58 | export default new LeaveMessageController -------------------------------------------------------------------------------- /release/src/database/conectDB.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("reflect-metadata"); 4 | var typeorm_1 = require("typeorm"); 5 | var db_conf_1 = require("../../conf/db.conf"); 6 | var mysql_1 = require("../entities/mysql"); 7 | var mongo_1 = require("../entities/mongo"); 8 | var _PROD_ = process.env.NODE_ENV === 'production'; 9 | var connectDB = function () { 10 | typeorm_1.createConnection({ 11 | type: 'mysql', 12 | host: db_conf_1.MySqlConf.host, 13 | port: db_conf_1.MySqlConf.port, 14 | username: db_conf_1.MySqlConf.username, 15 | password: db_conf_1.MySqlConf.password, 16 | database: db_conf_1.MySqlConf.database, 17 | entities: mysql_1.Entities, 18 | logging: _PROD_ ? false : true, 19 | }).then(function (connect) { 20 | console.log('mysql connect success!'); 21 | }).catch(function (err) { 22 | console.log('mysql connect fail!', err); 23 | }); 24 | }; 25 | exports.connectDB = connectDB; 26 | var connectMongo = function () { 27 | typeorm_1.createConnection({ 28 | name: 'mongo', 29 | type: 'mongodb', 30 | host: db_conf_1.MongoConf.host, 31 | port: db_conf_1.MongoConf.port, 32 | // username : MongoConf.username, 33 | // password : MongoConf.password, 34 | database: db_conf_1.MongoConf.database, 35 | entities: mongo_1.MongoEntities, 36 | logging: _PROD_ ? false : true, 37 | }).then(function (connect) { 38 | console.log('mongo connect success!'); 39 | }).catch(function (err) { 40 | console.log('mongo connect fail!', err); 41 | }); 42 | }; 43 | exports.connectMongo = connectMongo; 44 | //# sourceMappingURL=conectDB.js.map -------------------------------------------------------------------------------- /release/src/models/Chat.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | Object.defineProperty(exports, "__esModule", { value: true }); 22 | var BaseModel_1 = require("./BaseModel"); 23 | var typeorm_1 = require("typeorm"); 24 | var Chat = /** @class */ (function (_super) { 25 | __extends(Chat, _super); 26 | function Chat() { 27 | return _super !== null && _super.apply(this, arguments) || this; 28 | } 29 | Chat = __decorate([ 30 | typeorm_1.Entity() 31 | ], Chat); 32 | return Chat; 33 | }(BaseModel_1.BaseModel)); 34 | exports.Chat = Chat; 35 | //# sourceMappingURL=Chat.js.map -------------------------------------------------------------------------------- /src/database/dbUtils.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DataSource, 3 | EntityTarget, 4 | } from "typeorm"; 5 | import { format } from 'date-fns' 6 | import Redis from 'ioredis' 7 | 8 | const checkSrouce = (source: any, name: string) => { 9 | if(!source) { 10 | throw new Error(`[${name}] must be used after database connected. throw at ${format(new Date, 'yyyy-MM-dd HH:mm:ss:SSS')}`) 11 | } 12 | } 13 | 14 | let DataSources: DataSource[] = [] 15 | let MongoSource: DataSource = null 16 | let RedisSource: Redis = null 17 | 18 | export const setDataSource = (dataSources: DataSource[]) => { 19 | DataSources = dataSources 20 | } 21 | 22 | export const setMongoDataSource = (dataSource: DataSource) => { 23 | MongoSource = dataSource 24 | } 25 | 26 | export const setRedisSource = (dataSource: Redis) => { 27 | RedisSource = dataSource 28 | } 29 | export const useBlogRepository = (target: EntityTarget) => { 30 | const BlogDataSource = DataSources[0] 31 | checkSrouce(BlogDataSource, useBlogRepository.name) 32 | return BlogDataSource.getRepository(target) 33 | } 34 | 35 | export const useSharesRepository = (target: EntityTarget) => { 36 | const SharesDataSource = DataSources[1] 37 | checkSrouce(SharesDataSource, useSharesRepository.name) 38 | return SharesDataSource.getRepository(target) 39 | } 40 | 41 | export const useMongoRepository = (target: EntityTarget) => { 42 | checkSrouce(MongoSource, useMongoRepository.name) 43 | return MongoSource.getMongoRepository(target) 44 | } 45 | 46 | export const useRedis = () => { 47 | checkSrouce(RedisSource, useRedis.name) 48 | return RedisSource 49 | } 50 | 51 | /** 52 | * blog 53 | */ 54 | export const CONNECT_BLOG = 'Blog' 55 | 56 | /** 57 | * shares 58 | */ 59 | export const CONNECT_SHARES = 'Shares' 60 | 61 | /** 62 | * mongo 63 | */ 64 | export const CONNECT_MONGO = 'Mongo' 65 | -------------------------------------------------------------------------------- /src/middlewares/catch.ts: -------------------------------------------------------------------------------- 1 | import { Context } from 'koa' 2 | import LogCtrl from '../controllers/LogsController' 3 | // import * as Koa from 'koa' 4 | 5 | export default async (ctx: Context, next: () => Promise) => { 6 | // console.log('ctx-----------', ctx.header) 7 | const start = Date.now() 8 | try { 9 | await next(); 10 | const status: number = ctx.status || 404; 11 | if (status === 404) { 12 | ctx.throw(404); 13 | } 14 | const f = ctx.fields 15 | const errors =(ctx.body as any).errors 16 | if(ctx.path === '/graphql' && errors) { 17 | LogCtrl.ERRlogger(ctx, { 18 | status: status, 19 | time: Date.now() - start, 20 | errors: errors, 21 | msg: errors[0].message 22 | }); // error log 23 | } else { 24 | LogCtrl.APIlogger(ctx, { time: Date.now() - start }) // api log 25 | } 26 | } catch (err) { 27 | let stack = (err || {}).stack 28 | try { 29 | console.log('catch', err, err.status, err.message); 30 | let status: number = err.status || 500; 31 | LogCtrl.ERRlogger(ctx, { 32 | status: status, 33 | time: Date.now() - start, 34 | errors: stack.split('\n'), 35 | msg: err.toString() 36 | }); // error log 37 | ctx.status = status; 38 | if (status === 404) { 39 | ctx.body = {status: 404, data: null, msg: 'Not Found'}; 40 | } else { 41 | let msg: string = err.message || err.toString(); 42 | let errors: string = stack ? stack.split('\n') : err.toString(); 43 | ctx.body = {status, data: null, msg, errors}; 44 | } 45 | } catch (e) { 46 | let msg: string = e.message || e.toString(); 47 | let errors: string = e.stack ? e.stack.split('\n') : e.toString(); 48 | ctx.status = 500; 49 | ctx.body = {status: 500, data: null, msg, errors}; 50 | } 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /src/app.ts: -------------------------------------------------------------------------------- 1 | // koa 2 | import * as Koa from 'koa' 3 | import * as KoaLogger from 'koa-logger' 4 | import { Context } from 'koa' 5 | import Catch from './middlewares/catch' 6 | import Middlewares from './middlewares/index' 7 | import { 8 | connectDB, 9 | connectMongo, 10 | connectRedis, 11 | } from './database/conectDB' 12 | 13 | const _DEV_ = process.env.NODE_ENV === 'development' 14 | 15 | export class Application { 16 | private app: Koa 17 | 18 | constructor(port = 8200){ 19 | this.app = new Koa() 20 | this.connectDBs().then(() => { 21 | this.init() 22 | }).then(() => { 23 | this.start(port) 24 | }).catch(e => { 25 | console.error('Server setup failed!', e) 26 | }) 27 | } 28 | 29 | private connectDBs() { 30 | return Promise.all([connectDB(), connectMongo(), connectRedis()]).then(r => { 31 | console.log('All databases are connected.') 32 | }) 33 | } 34 | 35 | // init middlewares 36 | private init(){ 37 | if(_DEV_) { 38 | this.app.use(KoaLogger()) 39 | } 40 | this.app.use(Catch) //catch middldware 41 | this.app.keys = ['APP_Keys']; // set app keys 42 | this.app.use(async (ctx: Context, next: () => Promise) => { 43 | const path = ctx.request.path 44 | console.log(`path: ${path}`) 45 | if(path === '/') { 46 | ctx.body = 'Welcome to koa-graphql server.' 47 | } 48 | await next() 49 | ctx.set('X-Powered-By', 'Keefe'); 50 | }) 51 | 52 | Middlewares(this.app) 53 | } 54 | 55 | // start app 56 | public start(port: number) { 57 | // change to the databases priority startup 58 | this.app.listen(port, () => { 59 | console.log(`Koa server has started, running with: http://127.0.0.1:${port}. `) 60 | }) 61 | // this.app.listen(port, (): void => { 62 | // console.log(`Koa server has started, running with: http://127.0.0.1:${port}. `) 63 | // connectDB() // db start after server running 64 | // connectMongo() // connect mongodb 65 | // }) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /release/src/core/jwt/sign.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../../../src/core/jwt/sign.ts"],"names":[],"mappings":";;AAAA,+BAAgC;AAOhC;IAAA;QACE,QAAG,GAAY,OAAO,CAAA;QACtB,QAAG,GAAY,KAAK,CAAA;IAGtB,CAAC;IAAD,cAAC;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,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC5D,OAAU,aAAa,SAAI,cAAgB,CAAA;AAC7C,CAAC;AAED,WAAW;AAEE,QAAA,IAAI,GAAG,UAAC,OAAwB,EAAE,MAAuB,EAAE,IAA2B;IAA3B,qBAAA,EAAA,WAAoB,OAAO;IAEjG,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,IAAG,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;KAC1D;IAED,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA,CAAC,YAAY;IACrC,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA,CAAC,iCAAiC;IAEzE,IAAI,WAAW,GAAG,MAAM,CAAC;IACzB,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC7B,IAAI,YAAY,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9D,IAAI,SAAS,GAAG,gBAAgB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5D,IAAM,OAAO,GAAM,YAAY,SAAI,SAAW,CAAA;IAC9C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"} -------------------------------------------------------------------------------- /release/src/schema/graphql/common.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/schema/graphql/common.ts"],"names":[],"mappings":";;AAAA,mCAaiB;AAGJ,QAAA,YAAY,GAAG,IAAI,2BAAiB,CAAC;IAChD,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE;QACN,OAAO,EAAE;YACP,IAAI,EAAE,oBAAU;YAChB,OAAO,YAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;gBAC1B,OAAO,GAAG,C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,QAAQ,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAA;YACtC,OAAO,QAAQ,CAAA;QACjB,CAAC;KACF;CACF,CAAA;AAED,WAAW;AACE,QAAA,aAAa,GAAG,IAAI,gCAAsB,CAAC;IACtD,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE;QACN,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,uBAAa;SACpB;QACD,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;KACF;CACF,CAAC,CAAA;AAGF,OAAO;AACM,QAAA,cAAc,GAAkC;IAC3D,IAAI,EAAE;QACJ,IAAI,EAAE,oBAAU;QAChB,YAAY,EAAE,CAAC;KAChB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,oBAAU;QAChB,YAAY,EAAE,EAAE;KACjB;IACD,KAAK,EAAE;QACL,IAAI,EAAE,qBAAa;QACnB,YAAY,EAAE,EAAC,WAAW,EAAE,MAAM,EAAC;KACpC;IACD,SAAS,EAAE;QACT,IAAI,EAAE,IAAI,qBAAW,CAAC,uBAAa,CAAC;KACrC;CACF,CAAA"} -------------------------------------------------------------------------------- /release/src/schema/graphql/LeaveMessage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"LeaveMessage.js","sourceRoot":"","sources":["../../../../src/schema/graphql/LeaveMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA+GE;;AA/GF,mCAaiB;AAEjB,+BAAgC;AAChC,mFAAmE;AACnE,mCAAqD;AAErD,eAAe;AACF,QAAA,sBAAsB,GAAG,IAAI,2BAAiB,CAAC;IAC1D,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE;QACN,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;QACD,WAAW,EAAE;YACX,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAA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,OAAO,EAAE,UAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;;;;4BACpB,qBAAM,gCAAY,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;wBAAtC,KAAK,GAAG,SAA8B;wBAC5C,sBAAO,MAAM,CAAC,MAAM,YAClB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IACZ,IAAI,EACP,EAAC;;;aACJ;KACF;CACF,CAAA;AAED,IAAM,QAAQ,GAAkD;IAC9D,YAAY,EAAE;QACZ,IAAI,EAAE,8BAAsB;QAC5B,IAAI,EAAE;YACJ,WAAW,EAAE;gBACX,IAAI,EAAE,uBAAa;aACpB;SACF;QACD,OAAO,EAAE,UAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;;gBAClC,sBAAO,EAAE,EAAA;;aACV;KACF;CACF,CAAA;AAED,kBAAe;IACb,KAAK,OAAA;IACL,QAAQ,UAAA;CACT,CAAC"} -------------------------------------------------------------------------------- /release/src/schema/graphql/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __assign = (this && this.__assign) || function () { 3 | __assign = Object.assign || function(t) { 4 | for (var s, i = 1, n = arguments.length; i < n; i++) { 5 | s = arguments[i]; 6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) 7 | t[p] = s[p]; 8 | } 9 | return t; 10 | }; 11 | return __assign.apply(this, arguments); 12 | }; 13 | Object.defineProperty(exports, "__esModule", { value: true }); 14 | var graphql_1 = require("graphql"); 15 | var Article_1 = require("./Article"); 16 | var ArticleType_1 = require("./ArticleType"); 17 | var Comment_1 = require("./Comment"); 18 | var Tag_1 = require("./Tag"); 19 | var User_1 = require("./User"); 20 | var LeaveMessage_1 = require("./LeaveMessage"); 21 | var Balls_1 = require("./Balls"); 22 | var count = 0; 23 | var demo = { 24 | count: { 25 | type: graphql_1.GraphQLInt, 26 | args: { 27 | id: { 28 | name: 'id', 29 | type: graphql_1.GraphQLInt // 参数不为空 30 | } 31 | }, 32 | resolve: function (obj, args, ctx, info) { 33 | ++count; 34 | return count; 35 | } 36 | }, 37 | }; 38 | var RootSchema = new graphql_1.GraphQLSchema({ 39 | query: new graphql_1.GraphQLObjectType({ 40 | name: 'RootQuery', 41 | fields: __assign({}, demo, Article_1.default.query, ArticleType_1.default.query, Comment_1.default.query, Tag_1.default.query, User_1.default.query, LeaveMessage_1.default.query, Balls_1.default.query) 42 | }), 43 | mutation: new graphql_1.GraphQLObjectType({ 44 | name: 'RootMutation', 45 | fields: __assign({}, Article_1.default.mutation, ArticleType_1.default.mutation, Comment_1.default.mutation, Tag_1.default.mutation, User_1.default.mutation, LeaveMessage_1.default.mutation, Balls_1.default.mutation) 46 | }) 47 | }); 48 | exports.RootSchema = RootSchema; 49 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /release/src/core/jwt/verify.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../../src/core/jwt/verify.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+BAAyC;AAEzC;IAAgC,qCAAK;IACnC,2BAAY,GAAW;QAAvB,YACE,iBAAO,SAGR;QAFC,KAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAC/B,KAAI,CAAC,OAAO,GAAG,GAAG,CAAA;;IACpB,CAAC;IACH,wBAAC;AAAD,CAAC,AAND,CAAgC,KAAK,GAMpC;AAED,kBAAkB;AAClB,SAAS,WAAW,CAAE,KAAa,EAAE,GAAW,EAAE,OAAwB;IACxE,IAAM,UAAU,GAAG,uBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACnD,oDAAoD;IACpD,OAAO,UAAU,KAAK,GAAG,CAAA;AAC3B,CAAC;AAEY,QAAA,MAAM,GAAG,UAAC,MAAc,EAAE,IAAa;IAElD,IAAI,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,C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AAA;SACpC;QAED,uBAAuB;QACvB,IAAM,OAAO,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAC1F,IAAG,CAAC,OAAO,EAAE;YACX,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAA;SACnC;QAED,aAAa;QACb,IAAG,IAAI,CAAC,GAAG,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE;YAC5B,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;SAC9B;QAED,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;KACvB;IAAC,OAAM,CAAC,EAAE;QACT,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAAC,OAAO,IAAI,kBAAkB,CAAC,CAAA;KAC7D;AAEH,CAAC,CAAA"} -------------------------------------------------------------------------------- /release/src/middlewares/catch.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/middlewares/catch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAiDA;;AAhDA,gEAAmD;AAEnD,mBAAe,UAAO,GAAgB,EAAE,IAAwB;;;;;gBAExD,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;;;;gBAEtB,qBAAM,IAAI,EAAE,EAAA;;gBAAZ,SAAY,CAAC;gBACP,MAAM,GAAW,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;gBACzC,IAAI,MAAM,KAAK,GAAG,EAAE;oBAClB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBAChB;gBACD,IAAG,GAAG,CAAC,IAAI,KAAK,UAAU,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;oBAC7C,wBAAO,CAAC,SAAS,CAAC,GAAG,EAAE;wBACrB,MAAM,EAAE,MAAM;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AAC,QAAQ,EAAE,CAAC;wBAChE,GAAG,CAAC,IAAI,GAAG,EAAC,MAAM,QAAA,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,KAAA,EAAE,MAAM,QAAA,EAAC,CAAC;qBAC9C;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACN,GAAG,GAAW,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;oBACxC,MAAM,GAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;oBAClE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;oBACjB,GAAG,CAAC,IAAI,GAAG,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,KAAA,EAAE,MAAM,QAAA,EAAC,CAAC;iBACnD;;;;;KAEJ,EAAC"} -------------------------------------------------------------------------------- /src/core/jwt/sign.ts: -------------------------------------------------------------------------------- 1 | import * as Crypto from 'crypto' 2 | 3 | interface IPayloadOptions { 4 | exp: number // delta time 5 | [key: string]: any 6 | } 7 | 8 | class Options { 9 | alg?: string = 'HS256' 10 | typ?: string = 'JWT' 11 | expiresIn?: number 12 | encoding?: 'utf-8' 13 | } 14 | 15 | export function createHmacSigner (thing: string, secret: string | Buffer): string { 16 | let sig = Crypto.createHmac('sha256', secret).update(thing).digest('base64') 17 | return sig.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_') 18 | } 19 | 20 | function toString(obj: any) { 21 | if (typeof obj === 'string') { 22 | return obj; 23 | } 24 | if (typeof obj === 'number') { 25 | return obj.toString(); 26 | } 27 | if (Buffer.isBuffer(obj)) { 28 | return obj.toString(); 29 | } 30 | return JSON.stringify(obj); 31 | } 32 | 33 | function base64url(string: string, encoding: BufferEncoding): string { 34 | return Buffer 35 | .from(string, encoding) 36 | .toString('base64') 37 | .replace(/=/g, '') 38 | .replace(/\+/g, '-') 39 | .replace(/\//g, '_'); 40 | } 41 | 42 | function jwtSecuredInput(header: any, payload: any, encoding: BufferEncoding) { 43 | encoding = encoding || 'utf8'; 44 | let encodedHeader = base64url(toString(header), 'binary'); 45 | let encodedPayload = base64url(toString(payload), encoding); 46 | return `${encodedHeader}.${encodedPayload}` 47 | } 48 | 49 | // sign jwt 50 | 51 | export const sign = (payload: IPayloadOptions, secret: string | Buffer, opts: Options = new Options) => { 52 | 53 | let header = opts; 54 | 55 | if(payload.exp <= 0) { 56 | throw new Error('the payload.exp must be greater than 0') 57 | } 58 | 59 | payload.iat = Date.now() // sign time 60 | payload.exp = payload.iat + payload.exp // expire time, become time stamp 61 | 62 | let secretOrKey = secret; 63 | let encoding = opts.encoding; 64 | let securedInput = jwtSecuredInput(header, payload, encoding); 65 | let signature = createHmacSigner(securedInput, secretOrKey); 66 | const signStr = `${securedInput}.${signature}` 67 | return signStr 68 | } -------------------------------------------------------------------------------- /release/src/schema/graphql/Comment.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Comment.js","sourceRoot":"","sources":["../../../../src/schema/graphql/Comment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAwHE;;AAxHF,mCAaiB;AAEjB,+BAAgC;AAChC,yEAA6D;AAC7D,mCAAqD;AAErD,UAAU;AACG,QAAA,iBAAiB,GAAG,IAAI,2BAAiB,CAAC;IACrD,IAAI,EAAE,SAAS;IACf,MAAM,EAAE;QACN,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;QACD,WAAW,EAAE;YACX,IAAI,EAAE,uBAAa;SACpB;QACD,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,uBAAa;SACpB;QACD,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;QACD,MAAM,EAAE;YACN,IAAI,EAA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,qBAAM,2BAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;wBAArC,KAAK,GAAG,SAA6B;wBAC3C,sBAAO,MAAM,CAAC,MAAM,YAClB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IACZ,IAAI,EACP,EAAC;;;aACJ;KACF;CACF,CAAA;AAED,IAAM,QAAQ,GAAkD;IAC9D,OAAO,EAAE;QACP,IAAI,EAAE,yBAAiB;QACvB,IAAI,EAAE;YACJ,IAAI,EAAE;gBACJ,IAAI,EAAE,uBAAa;aACpB;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,uBAAa;aACpB;SACF;QACD,OAAO,EAAE,UAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;;gBAClC,sBAAO,EAAE,EAAA;;aACV;KACF;CACF,CAAA;AAED,kBAAe;IACb,KAAK,OAAA;IACL,QAAQ,UAAA;CACT,CAAC"} -------------------------------------------------------------------------------- /release/src/core/jwt/sign.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Crypto = require("crypto"); 4 | var Options = /** @class */ (function () { 5 | function Options() { 6 | this.alg = 'HS256'; 7 | this.typ = 'JWT'; 8 | } 9 | return Options; 10 | }()); 11 | function createHmacSigner(thing, secret) { 12 | var sig = Crypto.createHmac('sha256', secret).update(thing).digest('base64'); 13 | return sig.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); 14 | } 15 | exports.createHmacSigner = createHmacSigner; 16 | function toString(obj) { 17 | if (typeof obj === 'string') { 18 | return obj; 19 | } 20 | if (typeof obj === 'number') { 21 | return obj.toString(); 22 | } 23 | if (Buffer.isBuffer(obj)) { 24 | return obj.toString(); 25 | } 26 | return JSON.stringify(obj); 27 | } 28 | function base64url(string, encoding) { 29 | return Buffer 30 | .from(string, encoding) 31 | .toString('base64') 32 | .replace(/=/g, '') 33 | .replace(/\+/g, '-') 34 | .replace(/\//g, '_'); 35 | } 36 | function jwtSecuredInput(header, payload, encoding) { 37 | encoding = encoding || 'utf8'; 38 | var encodedHeader = base64url(toString(header), 'binary'); 39 | var encodedPayload = base64url(toString(payload), encoding); 40 | return encodedHeader + "." + encodedPayload; 41 | } 42 | // sign jwt 43 | exports.sign = function (payload, secret, opts) { 44 | if (opts === void 0) { opts = new Options; } 45 | var header = opts; 46 | if (payload.exp <= 0) { 47 | throw new Error('the payload.exp must be greater than 0'); 48 | } 49 | payload.iat = Date.now(); // sign time 50 | payload.exp = payload.iat + payload.exp; // expire time, become time stamp 51 | var secretOrKey = secret; 52 | var encoding = opts.encoding; 53 | var securedInput = jwtSecuredInput(header, payload, encoding); 54 | var signature = createHmacSigner(securedInput, secretOrKey); 55 | var signStr = securedInput + "." + signature; 56 | return signStr; 57 | }; 58 | //# sourceMappingURL=sign.js.map -------------------------------------------------------------------------------- /release/src/entities/mongo/baseModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | var typeorm_1 = require("typeorm"); 13 | var Moment = require("moment"); 14 | var BaseEntity = /** @class */ (function () { 15 | function BaseEntity() { 16 | } 17 | __decorate([ 18 | typeorm_1.ObjectIdColumn({ unique: true }), 19 | __metadata("design:type", String) 20 | ], BaseEntity.prototype, "id", void 0); 21 | __decorate([ 22 | typeorm_1.Column(), 23 | __metadata("design:type", String) 24 | ], BaseEntity.prototype, "createdBy", void 0); 25 | __decorate([ 26 | typeorm_1.Column({ 27 | default: Moment().format('YYYY/MM/DD hh:mm:ss.SSS') 28 | }), 29 | __metadata("design:type", String) 30 | ], BaseEntity.prototype, "createdAt", void 0); 31 | __decorate([ 32 | typeorm_1.VersionColumn({ 33 | default: 0 34 | }), 35 | __metadata("design:type", Number) 36 | ], BaseEntity.prototype, "version", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], BaseEntity.prototype, "ip", void 0); 41 | BaseEntity = __decorate([ 42 | typeorm_1.Entity() 43 | ], BaseEntity); 44 | return BaseEntity; 45 | }()); 46 | exports.BaseEntity = BaseEntity; 47 | //# sourceMappingURL=baseModel.js.map -------------------------------------------------------------------------------- /release/src/core/cors/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/cors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAsFA;;AApFA;IAAA;QAGE,iBAAY,GAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAI/E,CAAC;IAAD,sBAAC;AAAD,CAAC,AAPD,IAOC;AAED,IAAM,IAAI,GAAG,UAAC,OAAgD;IAAhD,wBAAA,EAAA,cAA+B,eAAe,EAAE;IAE5D,OAAO,UAAO,GAAgB,EAAE,IAAwB;;;;;oBAEtD,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE;wBACxC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,kBAAkB;qBACjD;yBAAM;wBACL,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAA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G,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,8BAA8B;oBAChD,GAAG,CAAC,IAAI,GAAG,EAAE,CAAA;;;oBAEb,UAAU;oBACV,mCAAmC;oBACnC,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI,EAAE;wBAChC,IAAI,MAAM,KAAK,GAAG,EAAE;4BAClB,8DAA8D;4BAC9D,GAAG,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC;yBAChD;6BAAM;4BACL,GAAG,CAAC,GAAG,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;yBACrD;qBACF;oBAED,gCAAgC;oBAChC,IAAI,OAAO,CAAC,aAAa,EAAE;wBACzB,GAAG,CAAC,GAAG,CAAC,+BAA+B,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;qBAC3E;;;;oBAGC,qBAAM,IAAI,EAAE,EAAA;;oBAAZ,SAAY,CAAC;;;;oBAEb,MAAM,KAAG,CAAC;;;;SAGf,CAAA;AACH,CAAC,CAAA;AAED,kBAAe,IAAI,CAAA"} -------------------------------------------------------------------------------- /src/services/StockHistoryService.ts: -------------------------------------------------------------------------------- 1 | import { StockHistory } from '../entities/mysql/shares/stockHistory' 2 | import { Stock } from '../entities/mysql/shares/stock' 3 | import StockService from './StockService' 4 | import StockHistoryDao from '../daos/StockHistoryDao' 5 | import { formatDate } from "../utils/tools"; 6 | import { DateFormat } from "../types/base"; 7 | 8 | 9 | 10 | class StockHistoryService { 11 | 12 | async getLastestTrade(stockId: number) { 13 | const lastestTrade = await StockHistoryDao.getLastestTrade(stockId) 14 | return lastestTrade 15 | } 16 | 17 | async pages(offset = 1, size = 10, stockId: number): Promise<[StockHistory[], number]> { 18 | if(stockId) { 19 | const stock = await StockService.getById(stockId) 20 | const [list, total] = await StockHistoryDao.pages(offset, size, stockId) 21 | return [ 22 | list.map(item => { 23 | item.tradeAt = formatDate(+item.timestamp, DateFormat.Date) 24 | item.name = stock.name 25 | item.code = stock.code 26 | return item 27 | }), 28 | total 29 | ] 30 | } else { 31 | const [list, total] = await StockHistoryDao.pages(offset, size) 32 | // set code,name; format timestamp 33 | const ids = list.map(item => item.stockId).reduce((pre, cur) => { 34 | if(!pre.includes(cur)) { 35 | pre.push(cur) 36 | } 37 | return pre 38 | }, []) 39 | const stocks = await StockService.getByIds(ids) 40 | const stockNameObj = stocks.reduce>((pre, cur) => { 41 | return {...pre, ...{[cur.id]: cur}} 42 | }, {}) 43 | return [ 44 | list.map(item => { 45 | item.tradeAt = formatDate(+item.timestamp, DateFormat.Date) 46 | const stock = stockNameObj[item.stockId] 47 | item.name = stock.name 48 | item.code = stock.code 49 | return item 50 | }), 51 | total 52 | ] 53 | } 54 | } 55 | 56 | async getTotal() { 57 | return await StockHistoryDao.getTotal() 58 | } 59 | 60 | async getAllTrade(stockId: number, pageSize: number) { 61 | return await StockHistoryDao.getAllTrade(stockId, pageSize) 62 | } 63 | } 64 | 65 | export default new StockHistoryService -------------------------------------------------------------------------------- /src/core/jwt/verify.ts: -------------------------------------------------------------------------------- 1 | import { Options } from './index' 2 | import { createHmacSigner } from './sign' 3 | 4 | class JsonWebTokenError extends Error { 5 | constructor(msg: string) { 6 | super() 7 | this.name = 'JsonWebTokenError' 8 | this.message = msg 9 | } 10 | } 11 | 12 | // verify is equal 13 | function verifyEqual (thing: string, sig: string, secrect: string | Buffer): boolean { 14 | const computeSig = createHmacSigner(thing, secrect) 15 | // console.log('verifyEqual--', computeSig, secrect) 16 | return computeSig === sig 17 | } 18 | 19 | export const verify = (jwtStr: string, opts: Options): [boolean, any] => { 20 | 21 | let jwtToken = jwtStr.split(' ')[1] // "Bearer jwtToken" 22 | // console.log(jwtStr, '-------',jwtToken) 23 | if(!/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+){1}$/.test(jwtToken)) { 24 | throw new JsonWebTokenError('jwt js error format') 25 | } 26 | 27 | try { 28 | const jwtTokenArr = jwtToken.split('.') 29 | 30 | let header = JSON.parse(Buffer.from(jwtTokenArr[0], 'base64').toString('binary')) 31 | let payload = JSON.parse(Buffer.from(jwtTokenArr[1], 'base64').toString(opts.encoding || 'utf-8')); 32 | let signature = jwtTokenArr[2] 33 | 34 | // check header 35 | if(header && header.alg !== 'HS256') { 36 | return [false, 'invalid algorithm'] 37 | } 38 | if(header && header.typ !== 'JWT') { 39 | return [false, 'invalid type'] 40 | } 41 | 42 | // check payload 43 | if(payload && typeof payload.exp !== 'number') { 44 | return [false, 'invalid exp'] 45 | } 46 | if(payload && typeof payload.iat !== 'number') { 47 | return [false, 'invalid iat'] 48 | } 49 | 50 | // check signature 51 | if(!signature) { 52 | return [false, 'invalid signature'] 53 | } 54 | 55 | // verify jwtString sig 56 | const isEqual = verifyEqual(jwtTokenArr[0] + '.' + jwtTokenArr[1], signature, opts.secret) 57 | if(!isEqual) { 58 | return [false, 'sig verify error'] 59 | } 60 | 61 | // verify exp 62 | if(Date.now() >= payload.exp) { 63 | return [false, 'jwt expired'] 64 | } 65 | 66 | return [true, payload] 67 | } catch(e) { 68 | throw new JsonWebTokenError(e.message || 'jwt verify error') 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /release/src/entities/mysql/tag.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var Tag = /** @class */ (function (_super) { 29 | __extends(Tag, _super); 30 | function Tag() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], Tag.prototype, "name", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], Tag.prototype, "remark", void 0); 41 | Tag = __decorate([ 42 | typeorm_1.Entity('tag') 43 | ], Tag); 44 | return Tag; 45 | }(baseEntity_1.BaseEntity)); 46 | exports.Tag = Tag; 47 | //# sourceMappingURL=tag.js.map -------------------------------------------------------------------------------- /src/routes/index.ts: -------------------------------------------------------------------------------- 1 | import * as Router from 'koa-router' 2 | import { KoaGraphql } from '../core/graphql' 3 | import { RootSchema } from '../schema/graphql/index' 4 | import DemoCtrl from '../controllers/DemoController' 5 | import AccountCtrl from '../controllers/AccountController' 6 | import FileCtrl from '../controllers/FileController' 7 | import LogsCtrl from '../controllers/LogsController' 8 | import GeoLogCtrl from '../controllers/GeoLogController' 9 | import ServerAPI from '../controllers/ServerAPIController' 10 | import DoubleColorBallController from '../controllers/DoubleColorBallController' 11 | import SharesCtrl from '../controllers/SharesController' 12 | import StockCtrl from '../controllers/StockController' 13 | import StockHistoryCtrl from '../controllers/StockHistoryController' 14 | 15 | const _PROD_ = process.env.NODE_ENV === 'production' 16 | 17 | const router = new Router(); 18 | 19 | router 20 | .post('/api/testInsert', DoubleColorBallController.batchInsert) 21 | .post('/api/login', AccountCtrl.login) 22 | .post('/api/logout', AccountCtrl.logout) 23 | .post('/api/register', AccountCtrl.register) 24 | .get('/view/:site', DemoCtrl.views) 25 | .post('/api/compose', DemoCtrl.compose) 26 | .get('/api/test/:id', DemoCtrl.test) 27 | .post('/platform/*', ServerAPI.KDJZ) 28 | .get('/api/log-api', LogsCtrl.apiPages) 29 | .get('/api/log-errors', LogsCtrl.errorsPages) 30 | .get('/api/log/stats', LogsCtrl.stats) 31 | .get('/api/log/geos', GeoLogCtrl.pages) 32 | .get('/api/log/geo/day', GeoLogCtrl.dayStats) 33 | .get('/api/log/geo/stats', GeoLogCtrl.getCityStats) 34 | .get('/api/log/geo/china', GeoLogCtrl.getChinaStats) 35 | .get('/api/log/geo/visit', GeoLogCtrl.getVisitMapStats) 36 | .post('/api/batchShares', SharesCtrl.batchInsert) 37 | .post('/api/upload', FileCtrl.upload) 38 | .get('/api/stocks', StockCtrl.pages1) 39 | .get('/api/stocks/:id', StockCtrl.getStock) 40 | .get('/api/stockhistory', StockHistoryCtrl.pages) 41 | .get('/api/stockline', StockHistoryCtrl.pages1) 42 | .get('/api/stockhistory/total', StockHistoryCtrl.getTotal) 43 | .get('/api/stock/chartCount', StockCtrl.getBlocksCount) 44 | .get('/graphql', KoaGraphql({ 45 | schema: RootSchema, 46 | graphql: _PROD_ ? false : true 47 | })) 48 | .post('/graphql', KoaGraphql({ 49 | schema: RootSchema, 50 | })) 51 | 52 | export default router -------------------------------------------------------------------------------- /release/src/entities/mongo/test_mongo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseModel_1 = require("./baseModel"); 28 | var TestMongo = /** @class */ (function (_super) { 29 | __extends(TestMongo, _super); 30 | function TestMongo() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], TestMongo.prototype, "name", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], TestMongo.prototype, "ip", void 0); 41 | TestMongo = __decorate([ 42 | typeorm_1.Entity() 43 | ], TestMongo); 44 | return TestMongo; 45 | }(baseModel_1.BaseEntity)); 46 | exports.TestMongo = TestMongo; 47 | //# sourceMappingURL=test_mongo.js.map -------------------------------------------------------------------------------- /release/src/entities/mysql/articleType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var ArticleType = /** @class */ (function (_super) { 29 | __extends(ArticleType, _super); 30 | function ArticleType() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], ArticleType.prototype, "name", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], ArticleType.prototype, "remark", void 0); 41 | ArticleType = __decorate([ 42 | typeorm_1.Entity('articleType') 43 | ], ArticleType); 44 | return ArticleType; 45 | }(baseEntity_1.BaseEntity)); 46 | exports.ArticleType = ArticleType; 47 | //# sourceMappingURL=articleType.js.map -------------------------------------------------------------------------------- /release/src/schema/graphql/Tag.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"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,uBAAa,CAAC;aACxC;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,uBAAa;aACpB;SACF;QACD,OAAO,EAAE,UAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;;;;4BACnB,qBAAM,uBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAA;;wBAAxC,MAAM,GAAG,SAA+B;wBAC9C,sBAAO,MAAM,EAAA;;;aACd;KACF;CACF,CAAA;AAED,kBAAe;IACb,KAAK,OAAA;IACL,QAAQ,UAAA;CACT,CAAC"} -------------------------------------------------------------------------------- /src/middlewares/response.ts: -------------------------------------------------------------------------------- 1 | import * as Koa from 'koa' 2 | import { ResponseData, ReturnPage } from '@/models/ResponseData' 3 | 4 | 5 | const json = (ctx: Koa.Context) => (res?: T | ResponseData | (() => T)): ResponseData => { 6 | let resData = new ResponseData(); 7 | const type = typeof res; 8 | if(type === 'undefined') { 9 | resData = {data: undefined, msg: 'return data is undefined', status: 200} 10 | } else if (type === 'object' && res.hasOwnProperty('data')) { // data is the key property 11 | Object.assign(resData, res) 12 | resData.msg = (res as ResponseData).msg||""; 13 | resData.errors = (res as ResponseData).errors; 14 | } else if(type === 'function') { 15 | resData.msg = `data's type is ${typeof res}`; 16 | resData.data = (res as Function)(); 17 | } else { // T 18 | resData.data = res as T; 19 | } 20 | resData.status = (res as ResponseData).status || 200; // resData status code 21 | let status = resData.status; // http status code 22 | // if (status == 200 && ctx.method === 'POST' || ctx.method === 'PUT' || ctx.method === 'DELETE') { 23 | // status = 201; 24 | // } 25 | ctx.status = status; 26 | return ctx.body = resData; 27 | }; 28 | 29 | const page = (ctx: Koa.Context) => (data: ReturnPage): ResponseData => { 30 | let resData = new ResponseData(); 31 | if (typeof data === 'object' && data !== null) { 32 | const { list, total = 0 } = data 33 | const count = list.length || 0 34 | const _pageSize = +ctx.query.pageSize, page = +ctx.query.page 35 | resData.data = list; 36 | let pageSize = _pageSize ? _pageSize : 10; 37 | resData.meta = { 38 | total: total, 39 | count: count, 40 | page: page ? page * 1 : 1, 41 | pageSize: pageSize, 42 | totalPage: Math.ceil(total/pageSize) 43 | }; 44 | resData.msg = data.msg||`查询到${resData.meta.count}记录`; 45 | } 46 | resData.status = data.status || 200; 47 | ctx.status = resData.status; 48 | return ctx.body = resData; 49 | }; 50 | 51 | const returnData = async (ctx: Koa.Context, next: () => Promise) => { 52 | if (!ctx.Json){ 53 | ctx.Json = json(ctx); 54 | } 55 | if (!ctx.Pages){ 56 | ctx.Pages = page(ctx); 57 | } 58 | await next(); 59 | }; 60 | 61 | export default returnData; 62 | 63 | 64 | // const returnData = async (ctx: any, next: any) => { 65 | // await next(); 66 | // } 67 | // export default returnData; 68 | -------------------------------------------------------------------------------- /release/src/entities/mysql/baseEntity.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | var typeorm_1 = require("typeorm"); 13 | // @Entity() 14 | var BaseEntity = /** @class */ (function () { 15 | function BaseEntity() { 16 | } 17 | __decorate([ 18 | typeorm_1.PrimaryColumn({ unique: true }), 19 | __metadata("design:type", String) 20 | ], BaseEntity.prototype, "id", void 0); 21 | __decorate([ 22 | typeorm_1.Column(), 23 | __metadata("design:type", String) 24 | ], BaseEntity.prototype, "createdBy", void 0); 25 | __decorate([ 26 | typeorm_1.Column(), 27 | __metadata("design:type", Number) 28 | ], BaseEntity.prototype, "createdAt", void 0); 29 | __decorate([ 30 | typeorm_1.Column({ select: false }), 31 | __metadata("design:type", String) 32 | ], BaseEntity.prototype, "updatedBy", void 0); 33 | __decorate([ 34 | typeorm_1.Column({ select: false }), 35 | __metadata("design:type", Number) 36 | ], BaseEntity.prototype, "updatedAt", void 0); 37 | __decorate([ 38 | typeorm_1.Column({ select: false }), 39 | __metadata("design:type", String) 40 | ], BaseEntity.prototype, "deletedBy", void 0); 41 | __decorate([ 42 | typeorm_1.Column({ select: false }), 43 | __metadata("design:type", Number) 44 | ], BaseEntity.prototype, "deletedAt", void 0); 45 | __decorate([ 46 | typeorm_1.Column({ 47 | select: false, 48 | default: 0 49 | }), 50 | __metadata("design:type", Number) 51 | ], BaseEntity.prototype, "version", void 0); 52 | return BaseEntity; 53 | }()); 54 | exports.BaseEntity = BaseEntity; 55 | //# sourceMappingURL=baseEntity.js.map -------------------------------------------------------------------------------- /release/src/middlewares/response.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/middlewares/response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAuEA;;AAtEA,uDAAqD;AAErD,IAAM,IAAI,GAAG,UAAC,GAAgB,IAAK,OAAA,UAAC,GAAQ;IAC1C,IAAI,OAAO,GAAG,IAAI,2BAAY,EAAE,CAAC;IACjC,IAAM,IAAI,GAAG,OAAO,GAAG,CAAC;IACxB,IAAG,IAAI,KAAK,WAAW,EAAE;QACvB,OAAO,GAAG,EAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,0BAA0B,EAAE,MAAM,EAAE,GAAG,EAAC,CAAA;KAC1E;SAAM,IAAI,IAAI,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE;QAC5C,IAAG,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,2BA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AG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,CAAC,IAAI,GAAG;YACb,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAC,QAAQ,CAAC;SACrC,CAAC;QACF,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAE,uBAAM,OAAO,CAAC,IAAI,CAAC,KAAK,iBAAI,CAAC;KACtD;IACD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC;IACpC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC5B,OAAO,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;AAC9B,CAAC,EAnBkC,CAmBlC,CAAC;AAEF,IAAM,UAAU,GAAG,UAAO,GAAgB,EAAE,IAAwB;;;;gBAClE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAC;oBACZ,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;iBACtB;gBACD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAC;oBACb,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;iBACvB;gBACD,qBAAM,IAAI,EAAE,EAAA;;gBAAZ,SAAY,CAAC;;;;KACd,CAAC;AAEF,kBAAe,UAAU,CAAC;AAG1B,sDAAsD;AACtD,kBAAkB;AAClB,IAAI;AACJ,6BAA6B"} -------------------------------------------------------------------------------- /release/src/schema/graphql/ArticleType.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ArticleType.js","sourceRoot":"","sources":["../../../../src/schema/graphql/ArticleType.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAoIE;;AApIF,mCAaiB;AAEjB,+BAAgC;AAChC,iFAAqE;AACrE,mCAAqD;AAErD,cAAc;AACD,QAAA,qBAAqB,GAAG,IAAI,2BAAiB,CAAC;IACzD,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE;QACN,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,uBAAa;SACpB;QACD,MAAM,EAAE;YACN,IAAI,EAAE,uBAAa;SACpB;QACD,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;YACnB,OAAO,YAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;gBAC1B,IAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;gBACrD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAA;YACxD,CAAC;SACF;QACD,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;SACpB;KACF;CACF,CAAC,CAAA;AAEF,qBAAqB;AACrB,IAAM,oBAAoB,GAAG,IAAI,2BAAiB,CAAC;IACjD,IAAI,EAAE,qBAAqB;IAC3B,MAAM,eACD,mBAAU,IACb,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,qBAAW,CAAC,6BAAqB,CAAC;SAC7C,GACF;CACF,CAAC,CAAA;AAEF,IAAM,KAAK,GAAkD;IAC3D,WAAW,EAAE;QACX,IAAI,EAAE,6BAAqB;QAC3B,IAAI,EAAE;YACJ,EAAE,EAAE;gBACF,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,IAAI,wBAAc,CAAC,uBAAa,CAAC;aACxC;SACF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AC/B,IAAI,EAAE;YACJ,EAAE,EAAE;gBACF,IAAI,EAAE,IAAI,wBAAc,CAAC,uBAAa,CAAC;aACxC;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,wBAAc,CAAC,uBAAa,CAAC;aACxC;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,uBAAa;aACpB;SACF;QACD,OAAO,EAAE,UAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;;;;4BACnB,qBAAM,+BAAe,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAA;;wBAAhD,MAAM,GAAG,SAAuC;wBACtD,sBAAO,MAAM,EAAA;;;aACd;KACF;CACF,CAAA;AAED,kBAAe;IACb,KAAK,OAAA;IACL,QAAQ,UAAA;CACT,CAAC"} -------------------------------------------------------------------------------- /release/src/entities/mysql/leaveMessage.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var LeaveMessage = /** @class */ (function (_super) { 29 | __extends(LeaveMessage, _super); 30 | function LeaveMessage() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], LeaveMessage.prototype, "description", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], LeaveMessage.prototype, "parentId", void 0); 41 | __decorate([ 42 | typeorm_1.Column(), 43 | __metadata("design:type", String) 44 | ], LeaveMessage.prototype, "ip", void 0); 45 | LeaveMessage = __decorate([ 46 | typeorm_1.Entity('leaveMessage') 47 | ], LeaveMessage); 48 | return LeaveMessage; 49 | }(baseEntity_1.BaseEntity)); 50 | exports.LeaveMessage = LeaveMessage; 51 | //# sourceMappingURL=leaveMessage.js.map -------------------------------------------------------------------------------- /src/daos/GeoLogDao.ts: -------------------------------------------------------------------------------- 1 | import { SystemLog } from '@/entities/mysql/systemLog' 2 | import { 3 | useBlogRepository, 4 | } from '@/database/dbUtils'; 5 | 6 | // const { API, Errors } = M 7 | 8 | 9 | class GeoLogDao { 10 | 11 | async getEveryDay() { 12 | // const sql = ` 13 | // SELECT DATE(FROM_UNIXTIME(s.created_at/1000)) as d, count(s.id) total 14 | // FROM system_log s 15 | // GROUP BY d;` 16 | const result = await useBlogRepository(SystemLog) 17 | .createQueryBuilder('s') 18 | .select('DATE(FROM_UNIXTIME(s.created_at/1000))', 'd') 19 | .addSelect('count(s.id)', 'total') 20 | .groupBy('d') 21 | .orderBy('d', 'ASC') 22 | .getRawMany() 23 | return result 24 | } 25 | 26 | 27 | async getGeographicStatsByCity() { 28 | const result = await useBlogRepository(SystemLog) 29 | .createQueryBuilder('s') 30 | .select('city_name_en', 'name_en') 31 | .addSelect('latitude') 32 | .addSelect('longitude') 33 | .addSelect('count(*)', 'total') 34 | .andWhere('s.latitude IS NOT NULL') 35 | .andWhere('s.source = :source', { source: 'v2' }) 36 | .groupBy('name_en') 37 | .addGroupBy('latitude') 38 | .addGroupBy('longitude') 39 | .getRawMany() 40 | return result 41 | } 42 | 43 | async getGeographicStatsByChina() { 44 | const result = await useBlogRepository(SystemLog) 45 | .createQueryBuilder('s') 46 | .select('city_name_en', 'name_en') 47 | .addSelect('latitude') 48 | .addSelect('longitude') 49 | .addSelect('count(*)', 'total') 50 | .andWhere('s.source = :source', { source: 'v2' }) 51 | .andWhere('s.country_name_en = :country', { country: 'China' }) 52 | .groupBy('name_en') 53 | .addGroupBy('latitude') 54 | .addGroupBy('longitude') 55 | .getRawMany() 56 | return result 57 | } 58 | 59 | 60 | async getVisitMapStats() { 61 | const result = await useBlogRepository(SystemLog) 62 | .createQueryBuilder('s') 63 | .select('city_name_en', 'name_en') 64 | .addSelect('request_ip', 'ip') 65 | .addSelect('subdivisions_name_en', 'sub_name_en') 66 | .addSelect('count(*)', 'total') 67 | .addSelect(['latitude', 'longitude']) 68 | .andWhere('s.source = :source', { source: 'v2' }) 69 | .andWhere('s.latitude IS NOT NULL') 70 | .groupBy('name_en') 71 | .addGroupBy('ip') 72 | .addGroupBy('sub_name_en') 73 | .addGroupBy('latitude') 74 | .addGroupBy('longitude') 75 | .getRawMany() 76 | return result 77 | } 78 | } 79 | 80 | export default new GeoLogDao -------------------------------------------------------------------------------- /release/src/schema/graphql/common.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var graphql_1 = require("graphql"); 4 | exports.PageDataType = new graphql_1.GraphQLObjectType({ 5 | name: 'pageData', 6 | fields: { 7 | current: { 8 | type: graphql_1.GraphQLInt, 9 | resolve: function (obj, args, ctx, info) { 10 | return obj['page'] || 1; 11 | } 12 | }, 13 | page: { 14 | type: graphql_1.GraphQLInt, 15 | resolve: function (obj, args, ctx, info) { 16 | return obj['page'] || 1; 17 | } 18 | }, 19 | pageSize: { 20 | type: graphql_1.GraphQLInt, 21 | resolve: function (obj, args, ctx, info) { 22 | return obj['pageSize']; 23 | } 24 | }, 25 | total: { 26 | type: graphql_1.GraphQLInt, 27 | resolve: function (obj, args, ctx, info) { 28 | return obj['total']; 29 | } 30 | }, 31 | totalPage: { 32 | type: graphql_1.GraphQLInt, 33 | resolve: function (obj, args, ctx, info) { 34 | return Math.ceil((obj['total'] || 0) / (obj['pageSize'])); 35 | } 36 | } 37 | } 38 | }); 39 | // 计算返回分页数据 40 | exports.metaFields = { 41 | meta: { 42 | type: exports.PageDataType, 43 | resolve: function (obj, args, ctx, info) { 44 | var pageInfo = {}; 45 | pageInfo['total'] = obj['total']; 46 | pageInfo['curSize'] = obj['list'].length; 47 | pageInfo['page'] = obj['page']; 48 | pageInfo['pageSize'] = obj['pageSize']; 49 | return pageInfo; 50 | } 51 | }, 52 | }; 53 | // 分页排序默认参数 54 | exports.PageOrderType = new graphql_1.GraphQLInputObjectType({ 55 | name: 'pageOrder', 56 | fields: { 57 | createdAt: { 58 | type: graphql_1.GraphQLString 59 | }, 60 | drawDate: { 61 | type: graphql_1.GraphQLString 62 | }, 63 | id: { 64 | type: graphql_1.GraphQLString 65 | }, 66 | } 67 | }); 68 | // 获取参数 69 | exports.pageArgsFields = { 70 | page: { 71 | type: graphql_1.GraphQLInt, 72 | defaultValue: 1, 73 | }, 74 | pageSize: { 75 | type: graphql_1.GraphQLInt, 76 | defaultValue: 10 77 | }, 78 | order: { 79 | type: exports.PageOrderType, 80 | defaultValue: { 'createdAt': 'DESC' } 81 | }, 82 | createdAt: { 83 | type: new graphql_1.GraphQLList(graphql_1.GraphQLString) 84 | } 85 | }; 86 | //# sourceMappingURL=common.js.map -------------------------------------------------------------------------------- /src/controllers/GeoLogController.ts: -------------------------------------------------------------------------------- 1 | import * as Koa from 'koa' 2 | import { 3 | Like, 4 | Between, 5 | FindManyOptions, 6 | Equal, 7 | FindOptionsWhere, 8 | } from 'typeorm'; 9 | // import { Context } from 'koa' 10 | import { SystemLog } from '../entities/mysql/systemLog' 11 | // import { Errors } from '../entities/mongo/errors' 12 | // import { Guid } from '../utils/tools'; 13 | import { useBlogRepository } from '../database/dbUtils' 14 | import { formatDate } from '../utils/tools'; 15 | import { DateFormat } from '../types/base'; 16 | import GeoLogService from '@/services/GeoLogService' 17 | import { endOfDay, startOfDay } from 'date-fns' 18 | 19 | class GeoLogController { 20 | 21 | async pages(ctx: Koa.Context) { 22 | const params = ctx.getParams 23 | const query = ctx.query 24 | 25 | const options: FindManyOptions = { 26 | skip: params.offset, 27 | take: params.limit, 28 | order: { 29 | created_at: 'DESC' 30 | }, 31 | where: {} 32 | } 33 | const whereConditions: FindOptionsWhere = {} 34 | if(query.path) { 35 | whereConditions.path = Like(`%${query.path}%`) 36 | } 37 | if(query.continent_code) { 38 | whereConditions.continent_code = Like(`%${query.continent_code}%`) 39 | } 40 | if(query.msg) { 41 | whereConditions.msg = Like(`%${query.msg}%`) 42 | } 43 | if(query['createdAt[]']) { 44 | const date = (query['createdAt[]'] as string[]).map( 45 | (d, i) => i > 0 ? endOfDay(new Date(d)) : startOfDay(new Date(d)) 46 | ); 47 | (whereConditions as any).created_at = Between(date[0], date[1]) 48 | // (whereConditions as any).created_at = { 49 | // $gte: date[0], // 大于等于开始日期 50 | // $lte: date[1] // 小于等于结束日期 51 | // } 52 | } 53 | options.where = whereConditions 54 | console.log(options.where.created_at, '----options') 55 | const pages = await useBlogRepository(SystemLog).findAndCount(options) 56 | const list = pages[0], total = pages[1] 57 | ctx.Pages({list, total}) 58 | } 59 | 60 | async dayStats (ctx: Koa.Context) { 61 | const data = await GeoLogService.getEveryDay() 62 | return ctx.Json(data) 63 | } 64 | 65 | 66 | async getCityStats(ctx: Koa.Context) { 67 | const data = await GeoLogService.getGeographicStatsByCity() 68 | return ctx.Json(data) 69 | } 70 | 71 | async getChinaStats(ctx: Koa.Context) { 72 | const data = await GeoLogService.getGeographicStatsByChina() 73 | return ctx.Json(data) 74 | } 75 | 76 | async getVisitMapStats(ctx: Koa.Context) { 77 | const data = await GeoLogService.getVisitMapStats() 78 | return ctx.Json(data) 79 | } 80 | } 81 | 82 | export default new GeoLogController() 83 | -------------------------------------------------------------------------------- /release/src/controllers/ArticleTypeController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ArticleTypeController.js","sourceRoot":"","sources":["../../../src/controllers/ArticleTypeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAkF;AAElF,6DAA2D;AAC3D,wCAAsC;AACtC,+BAAgC;AAGhC;IAAA;IAoEA,CAAC;IAlEc,wBAAM,GAAnB,UAAoB,IAAS;;;;4BACpB,qBAAM,oBAAU,EAAE,CAAC,IAAI,CAAC,yBAAW,CAAC,EAAA;4BAA3C,sBAAO,SAAoC,EAAC;;;;KAC7C;IAGY,yBAAO,GAApB,UAAqB,EAAe;QAAf,mBAAA,EAAA,OAAe;;;;;4BAEd,qBAAM,uBAAa,CAAC,yBAAW,CAAC,CAAC,OAAO,CAAC,EAAC,EAAE,IAAA,EAAC,CAAC,EAAA;;wBAA5D,WAAW,GAAG,SAA8C;wBAClE,sBAAO,WAAW,EAAA;;;;KACnB;IAEY,uBAAK,GAAlB,UAAmB,IAAS;;;;;;wBACpB,OAAO,GAAiC;4BAC5C,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ;4BACzD,IAAI,EAAE,IAAI,CAAC,QAAQ;4BACnB,KAAK,EAAE,EAAE;4BACT,KAAK,EAAE;gCACL,SAAS,EAAE,IAAI;6BAChB;yBACF,CAAA;wBACD,IAAG,IAAI,CAAC,IAAI,E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AC,MAAM,CAAA;wBAC1B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;wBAC5B,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAA;wBAC1C,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;wBAC5B,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAA;wBAC3B,qBAAM,uBAAa,CAAC,yBAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;;wBAArD,MAAM,GAAG,SAA4C;wBAC3D,sBAAO,MAAM,EAAA;;;;KACd;IAEY,wBAAM,GAAnB,UAAoB,IAAS,EAAE,GAAY;;;;;;wBACrC,KAAK,GAAG,IAAI,yBAAW,EAAE,CAAA;wBAC7B,qBAAqB;wBACrB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;wBACtB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;wBAC1B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;wBAC5B,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAA;wBAC3B,qBAAM,uBAAa,CAAC,yBAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,EAAA;;wBAAhE,MAAM,GAAG,SAAuD;wBACtE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;wBAC9B,sBAAO,MAAM,EAAA;;;;KACd;IAEH,wBAAC;AAAD,CAAC,AApED,IAoEC"} -------------------------------------------------------------------------------- /release/src/controllers/TagController.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TagController.js","sourceRoot":"","sources":["../../../src/controllers/TagController.ts"],"names":[],"mappings":";;;;;;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AM,GAAG,SAAoC;wBACnD,sBAAO,MAAM,EAAA;;;;KACd;IAEY,oBAAM,GAAnB,UAAoB,IAAS,EAAE,GAAY;;;;;;wBACzC,IAAG,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;4BACrC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;yBAC9B;wBACG,KAAK,GAAG,IAAI,SAAG,EAAE,CAAA;wBACrB,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;wBAClB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;wBACtB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;wBAC1B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;wBAC5B,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,mBAAO,CAAC,CAAC,EAAE,CAAA;wBACxB,qBAAM,uBAAa,CAAC,SAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;;wBAA7C,MAAM,GAAG,SAAoC;wBACnD,sBAAO,MAAM,EAAA;;;;KACd;IAEH,oBAAC;AAAD,CAAC,AAlED,IAkEC"} -------------------------------------------------------------------------------- /release/src/entities/mysql/user.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var User = /** @class */ (function (_super) { 29 | __extends(User, _super); 30 | function User() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], User.prototype, "username", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], User.prototype, "password", void 0); 41 | __decorate([ 42 | typeorm_1.Column(), 43 | __metadata("design:type", String) 44 | ], User.prototype, "nickName", void 0); 45 | __decorate([ 46 | typeorm_1.Column(), 47 | __metadata("design:type", Number) 48 | ], User.prototype, "userType", void 0); 49 | __decorate([ 50 | typeorm_1.Column(), 51 | __metadata("design:type", Number) 52 | ], User.prototype, "sex", void 0); 53 | __decorate([ 54 | typeorm_1.Column(), 55 | __metadata("design:type", String) 56 | ], User.prototype, "remark", void 0); 57 | User = __decorate([ 58 | typeorm_1.Entity('user') 59 | ], User); 60 | return User; 61 | }(baseEntity_1.BaseEntity)); 62 | exports.User = User; 63 | //# sourceMappingURL=user.js.map -------------------------------------------------------------------------------- /src/core/cors/index.ts: -------------------------------------------------------------------------------- 1 | import * as Koa from 'koa' 2 | 3 | class CORSOptionsData { 4 | origin: string | Function 5 | credentials?: boolean 6 | allowMethods?: string[] = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] 7 | allowHeaders?: Array 8 | maxAge?: number 9 | exposeHeaders?: [string] 10 | } 11 | 12 | const Cors = (options: CORSOptionsData = new CORSOptionsData()) => { 13 | 14 | return async (ctx: Koa.Context, next: () => Promise): Promise => { 15 | let origin; 16 | if (typeof options.origin === 'function') { 17 | origin = options.origin(ctx); // frequently-used 18 | } else { 19 | origin = options.origin || ctx.get('Origin') || '*'; 20 | } 21 | if (!origin || origin === ctx.origin) { 22 | return await next(); 23 | } 24 | 25 | // Access-Control-Allow-Origin 26 | ctx.set('Access-Control-Allow-Origin', origin); 27 | 28 | if (ctx.method === 'OPTIONS') { 29 | // Preflight Request 30 | if (!ctx.get('Access-Control-Request-Method')) { 31 | return await next(); 32 | } 33 | 34 | // Access-Control-Max-Age 35 | if (options.maxAge) { 36 | ctx.set('Access-Control-Max-Age', String(options.maxAge)); 37 | } 38 | 39 | // Access-Control-Allow-Credentials 40 | if (options.credentials === true) { 41 | // When used as part of a response to a preflight request, 42 | // this indicates whether or not the actual request can be made using credentials. 43 | ctx.set('Access-Control-Allow-Credentials', 'true'); 44 | } 45 | 46 | // Access-Control-Allow-Methods 47 | if (options.allowMethods) { 48 | ctx.set('Access-Control-Allow-Methods', options.allowMethods.join(',')); 49 | } 50 | 51 | // Access-Control-Allow-Headers 52 | if (options.allowHeaders) { 53 | ctx.set('Access-Control-Allow-Headers', options.allowHeaders.join(',')); 54 | } else { 55 | ctx.set('Access-Control-Allow-Headers', ctx.get('Access-Control-Request-Headers')); 56 | } 57 | 58 | ctx.status = 204; // No Content(Recommended Use) 59 | ctx.body = '' 60 | } else { 61 | // Request 62 | // Access-Control-Allow-Credentials 63 | if (options.credentials === true) { 64 | if (origin === '*') { 65 | // `credentials` can't be true when the `origin` is set to `*` 66 | ctx.remove('Access-Control-Allow-Credentials'); 67 | } else { 68 | ctx.set('Access-Control-Allow-Credentials', 'true'); 69 | } 70 | } 71 | 72 | // Access-Control-Expose-Headers 73 | if (options.exposeHeaders) { 74 | ctx.set('Access-Control-Expose-Headers', options.exposeHeaders.join(',')); 75 | } 76 | 77 | try { 78 | await next(); 79 | } catch (err) { 80 | throw err; 81 | } 82 | } 83 | } 84 | } 85 | 86 | export default Cors 87 | -------------------------------------------------------------------------------- /src/daos/StockHistoryDao.ts: -------------------------------------------------------------------------------- 1 | import { Equal, Like, Between, LessThanOrEqual, FindManyOptions} from "typeorm"; 2 | import { StockHistory, History } from '@/entities/mysql/shares/stockHistory' 3 | import { useSharesRepository } from '@/database/dbUtils'; 4 | 5 | class StockHistoryDao { 6 | 7 | private maxCount = -1 8 | 9 | async getLastestTrade(stockId: number) { 10 | const lastestTrade = await useSharesRepository(History).findOne({ 11 | select: ['timestamp'], 12 | where: { 13 | stockId: Equal(stockId) 14 | }, 15 | order: { 16 | timestamp: 'DESC' 17 | } 18 | }) 19 | return lastestTrade 20 | } 21 | 22 | async pages(offset = 1, size = 10, stockId?: number): Promise<[StockHistory[], number]> { 23 | const [list, total] = await useSharesRepository(History).findAndCount({ 24 | select: [ 25 | 'id', 26 | 'stockId', 27 | 'volume', 28 | 'open', 29 | 'high', 30 | 'low', 31 | 'close', 32 | 'chg', 33 | 'percent', 34 | 'turnoverrate', 35 | 'amount', 36 | 'pe', 37 | 'pb', 38 | 'ps', 39 | 'pcf', 40 | 'market_capital', 41 | 'timestamp' 42 | ], 43 | where: { 44 | stockId: Equal(stockId) 45 | }, 46 | order: { 47 | timestamp: 'DESC' 48 | }, 49 | skip: (offset > 0 ? (offset - 1) : 0) * size, 50 | take: size 51 | }) 52 | return [list as StockHistory[], total] 53 | } 54 | 55 | private async _getTotal() { 56 | const start = Date.now() 57 | const count = await useSharesRepository(History).count().then(count => { 58 | console.log('get total: ', count) 59 | this.maxCount = count 60 | return this.maxCount 61 | }) 62 | console.log(`time:${Date.now() - start}ms`) 63 | return count 64 | } 65 | 66 | async getTotal() { 67 | if(this.maxCount > 0) { 68 | return this.maxCount 69 | } else { 70 | return await this._getTotal() 71 | } 72 | } 73 | 74 | async getAllTrade(stockId: number, pageSize = 100) { 75 | const list = await useSharesRepository(History).find({ 76 | select: [ 77 | 'id', 78 | 'stockId', 79 | 'volume', 80 | 'open', 81 | 'high', 82 | 'low', 83 | 'close', 84 | 'chg', 85 | 'percent', 86 | 'turnoverrate', 87 | 'amount', 88 | 'pe', 89 | 'pb', 90 | 'ps', 91 | 'pcf', 92 | 'market_capital', 93 | 'timestamp' 94 | ], 95 | where: { 96 | stockId: Equal(stockId) 97 | }, 98 | order: { 99 | timestamp: 'ASC' 100 | }, 101 | take: pageSize 102 | }) 103 | return list 104 | } 105 | } 106 | 107 | export default new StockHistoryDao -------------------------------------------------------------------------------- /release/src/entities/mysql/comment.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var Comment = /** @class */ (function (_super) { 29 | __extends(Comment, _super); 30 | function Comment() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], Comment.prototype, "description", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], Comment.prototype, "articleId", void 0); 41 | __decorate([ 42 | typeorm_1.Column(), 43 | __metadata("design:type", String) 44 | ], Comment.prototype, "parentId", void 0); 45 | __decorate([ 46 | typeorm_1.Column(), 47 | __metadata("design:type", String) 48 | ], Comment.prototype, "ip", void 0); 49 | __decorate([ 50 | typeorm_1.Column(), 51 | __metadata("design:type", String) 52 | ], Comment.prototype, "client", void 0); 53 | __decorate([ 54 | typeorm_1.Column(), 55 | __metadata("design:type", String) 56 | ], Comment.prototype, "url", void 0); 57 | Comment = __decorate([ 58 | typeorm_1.Entity('comment') 59 | ], Comment); 60 | return Comment; 61 | }(baseEntity_1.BaseEntity)); 62 | exports.Comment = Comment; 63 | //# sourceMappingURL=comment.js.map -------------------------------------------------------------------------------- /src/schema/graphql/LeaveMessage.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLObjectType, 3 | GraphQLSchema, 4 | GraphQLInt, 5 | GraphQLNullableType, 6 | GraphQLList, 7 | GraphQLString, 8 | GraphQLType, 9 | GraphQLNonNull, 10 | GraphQLScalarType, 11 | Thunk, 12 | GraphQLFieldConfigMap, 13 | Source, 14 | } from 'graphql'; 15 | import {Context} from 'koa' 16 | import { toDate } from 'date-fns' 17 | import LeaveMsgCtrl from '../../controllers/LeaveMessageController' 18 | import { metaFields, pageArgsFields } from './common' 19 | import { formatDate } from '../../utils/tools/formatDate'; 20 | 21 | // leaveMessage 22 | export const leaveMessageObjectType = new GraphQLObjectType({ 23 | name: 'leaveMessage', 24 | fields: { 25 | id: { 26 | type: GraphQLString 27 | }, 28 | description: { 29 | type: GraphQLString 30 | }, 31 | parentId: { 32 | type: GraphQLString 33 | }, 34 | ip: { 35 | type: GraphQLString 36 | }, 37 | createdAt: { 38 | type: GraphQLString, 39 | resolve(obj, args, ctx, info){ 40 | const createdAt = Number(obj.createdAt) || Date.now() 41 | return formatDate(createdAt) 42 | } 43 | }, 44 | createdBy: { 45 | type: GraphQLString 46 | } 47 | } 48 | }) 49 | 50 | // leaveMessage pages type 51 | const LeaveMsgPagesType = new GraphQLObjectType({ 52 | name: 'leaveMsgPageType', 53 | fields: { 54 | ...metaFields, 55 | list: { 56 | type: new GraphQLList(leaveMessageObjectType) 57 | } 58 | } 59 | }) 60 | 61 | const query: Thunk> = { 62 | leaveMsg: { 63 | type: leaveMessageObjectType, 64 | args: { 65 | id: { 66 | // name: 'id', 67 | type: new GraphQLNonNull(GraphQLString) 68 | } 69 | }, 70 | resolve: async (obj, args, ctx, info) => { 71 | const {id} = args; 72 | const leaveMsg = await LeaveMsgCtrl.getById(id) 73 | return leaveMsg 74 | } 75 | }, 76 | leaveMsgs: { 77 | type: LeaveMsgPagesType, 78 | args: { 79 | ...pageArgsFields, 80 | description: { 81 | // name: 'description', 82 | type: GraphQLString 83 | } 84 | }, 85 | resolve: async (obj, args, ctx, info): Promise => { 86 | const pages = await LeaveMsgCtrl.pages(args) 87 | return Object.assign({ 88 | list: pages[0], 89 | total: pages[1], 90 | ...args 91 | }); 92 | } 93 | } 94 | } 95 | 96 | const mutation: Thunk> = { 97 | leaveMessage: { 98 | type: leaveMessageObjectType, 99 | args: { 100 | description: { 101 | type: GraphQLString 102 | } 103 | }, 104 | resolve: async (obj, args, ctx, info) => { 105 | return {} 106 | } 107 | } 108 | } 109 | 110 | export default { 111 | query, 112 | mutation 113 | }; -------------------------------------------------------------------------------- /src/database/conectDB.ts: -------------------------------------------------------------------------------- 1 | import Redis from 'ioredis'; 2 | import { DataSource, DataSourceOptions } from "typeorm"; 3 | import { format } from 'date-fns' 4 | import { MysqlConf, MongoConf, RedisConf } from 'conf/db.conf' 5 | import { Entities, ShareEntities } from '../entities/mysql' 6 | import { MongoEntities } from '../entities/mongo' 7 | import { 8 | CONNECT_BLOG, 9 | CONNECT_MONGO, 10 | CONNECT_SHARES, 11 | setDataSource, 12 | setMongoDataSource, 13 | setRedisSource, 14 | } from './dbUtils'; 15 | import stockHistoryDao from '../daos/StockHistoryDao' 16 | 17 | const _PROD_ = process.env.NODE_ENV === 'production' 18 | 19 | const connectDB = () => { 20 | const connectOptions = [ 21 | {name: CONNECT_BLOG, entities: Entities, database: CONNECT_BLOG}, 22 | {name: CONNECT_SHARES, entities: ShareEntities, database: CONNECT_SHARES} 23 | ].map(db => { 24 | return { 25 | ...db, 26 | type : 'mysql', 27 | host : '127.0.0.1', 28 | port : MysqlConf.port, 29 | username : MysqlConf.username, 30 | password : MysqlConf.password, 31 | logging : _PROD_ ? false : true, 32 | // driver : require('mysql2/promise'), 33 | } 34 | }) 35 | const connectDBs = connectOptions.map(c => new DataSource(c).initialize()) 36 | return Promise.all(connectDBs).then((datasource) => { 37 | console.log(`${connectOptions.map(c => c.name).join()} ${connectOptions.length} mysql connected successfully!`) 38 | console.log(`connencted at ${format(new Date, 'yyyy-MM-dd HH:mm:ss:SSS')}`) 39 | // stockHistoryDao._getTotal() 40 | setDataSource(datasource) 41 | return datasource 42 | }).catch((err) => { 43 | console.log('mysql failed to connect!', err) 44 | return Promise.reject(err) 45 | }) 46 | } 47 | 48 | const connectMongo = () => { 49 | return new DataSource({ 50 | name : CONNECT_MONGO, 51 | type : 'mongodb', 52 | host : MongoConf.host, 53 | port : MongoConf.port, 54 | username : MongoConf.username, 55 | password : MongoConf.password, 56 | database : MongoConf.database, 57 | entities : MongoEntities, 58 | authSource: MongoConf.username, 59 | logging : _PROD_ ? false : true, 60 | }).initialize().then((datasource) => { 61 | console.log('mongo connected successfully!') 62 | setMongoDataSource(datasource) 63 | return datasource 64 | }).catch((err) => { 65 | console.log('mongo connect fail!', err) 66 | return Promise.reject(err) 67 | }) 68 | } 69 | 70 | const connectRedis = () => { 71 | const store = new Redis(RedisConf) 72 | // if(['close', 'end'].includes(store.status)) 73 | return store.connect().then(r => { 74 | console.log('redis connected!') 75 | return setRedisSource(store) 76 | }).catch(e => { 77 | console.log('redis connect fail!', e) 78 | return Promise.reject(e) 79 | }) 80 | // return Promise.resolve(1) 81 | } 82 | 83 | export { 84 | connectDB, 85 | connectRedis, 86 | connectMongo 87 | } 88 | -------------------------------------------------------------------------------- /src/controllers/AccountController.ts: -------------------------------------------------------------------------------- 1 | import * as Crypto from 'crypto'; 2 | import {getManager, getRepository, Like, Equal} from "typeorm"; 3 | // import { Context } from 'koa' 4 | import { Context } from 'koa' 5 | import { User } from '@/entities/mysql/user' 6 | import { store as Store } from "@/utils/session"; 7 | import { JWT_SECRET, EXP_TIME } from '../constants' 8 | import { sign } from '../core/jwt/sign' 9 | import { cryptoPwd, formatDate, Guid } from "../utils/tools" 10 | import { useBlogRepository } from '../database/dbUtils'; 11 | import { UserType } from '@/types/base' 12 | import { UserLogin } from '@/types/user'; 13 | 14 | class AccountController { 15 | 16 | private verifyNameAndPwd(username: string, password: string) { 17 | if(!username || !password || password?.length < 6) 18 | throw 'Incorrect username or password' 19 | } 20 | 21 | //POST 22 | async login(ctx: Context) { 23 | console.log(ctx.state, ctx.query, ctx.fields, ctx.params, ctx.session) 24 | const inputs: any = ctx.fields; 25 | let username = inputs.username; 26 | let password = inputs.password; 27 | if ((username && username.length > 0) && (password && password.length > 5)) { 28 | const result = await useBlogRepository(User).findOne({ 29 | select: ['id', 'username', 'nickName', 'sex', 'userType'], 30 | where: { 31 | username: username, 32 | password: cryptoPwd(password, username) 33 | } 34 | }); 35 | if(result) { 36 | const token = sign({ ...result, exp: EXP_TIME }, JWT_SECRET) 37 | await Store.set('true', { 38 | sid: token, 39 | maxAge: EXP_TIME // millisecond 40 | }) 41 | ctx.Json({ data: token }); 42 | } else { 43 | ctx.throw(400, '用户名或密码错误!'); 44 | } 45 | } else { 46 | ctx.throw(400, '用户名或密码错误!'); 47 | } 48 | } 49 | 50 | //POST 51 | async logout(ctx: Context) { 52 | const tokens = ctx.header['authorization'] 53 | const token = tokens.split(' ')[1] 54 | await Store.destroy(token) 55 | ctx.Json({ data: 1, msg: '退出成功!' }); 56 | } 57 | 58 | 59 | //POST 60 | async register(ctx: Context) { 61 | const inputs = ctx.fields; 62 | let username = inputs.username; 63 | let password = inputs.password; 64 | if ((username && username.length > 0) && (password && password.length > 5)) { 65 | const model = new User 66 | model.id = Guid() 67 | model.username = username 68 | model.password = cryptoPwd(password, username) 69 | model.userType = UserType.normal 70 | model.createdAt = Date.now() 71 | model.createdBy = model.id 72 | model.updatedAt = Date.now() 73 | model.updatedBy = model.id 74 | const result = await useBlogRepository(User).save(model) 75 | if(result) { 76 | ctx.Json({ data: 1 }); 77 | } else { 78 | ctx.throw(400, '注册失败!'); 79 | } 80 | } else { 81 | ctx.throw(400, '用户名或密码格式错误!'); 82 | } 83 | } 84 | 85 | } 86 | 87 | export default new AccountController -------------------------------------------------------------------------------- /src/daos/StockDao.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Equal, 3 | Like, 4 | Between, 5 | FindManyOptions, 6 | FindOptions, 7 | In, 8 | } from "typeorm"; 9 | import { Context } from 'koa' 10 | import { Stock } from '@/entities/mysql/shares/stock' 11 | import { EMarket, EBLock } from '@/models/Stocks' 12 | import { 13 | useSharesRepository, 14 | } from '@/database/dbUtils'; 15 | 16 | 17 | 18 | class StockDao { 19 | 20 | 21 | async getCode(id: number) { 22 | const stock = await useSharesRepository(Stock).findOne({ 23 | where: { 24 | id 25 | } 26 | }) 27 | return stock 28 | } 29 | 30 | async getById(id: number) { 31 | const stock = await useSharesRepository(Stock).findOne({ 32 | where: { 33 | id 34 | }, 35 | select: ['id', 'code', 'name'] 36 | }) 37 | return stock 38 | } 39 | 40 | async getByIds(ids: number[]) { 41 | const stocks = await useSharesRepository(Stock).find({ 42 | where: { 43 | id: In(ids) 44 | } 45 | }) 46 | // const stocks = await useSharesRepository(Stock).findByIds(ids, { 47 | // select: ['id', 'code', 'name'] 48 | // }) 49 | return stocks 50 | } 51 | 52 | async getByCode(code: string) { 53 | const stock = await useSharesRepository(Stock).findOneBy({code: Equal(code)}) 54 | return stock 55 | } 56 | 57 | async getStockList(value: string, pageSize = 10) { 58 | const list = await useSharesRepository(Stock).find({ 59 | where: [ 60 | { code: Like(`%${value}%`) }, 61 | { name: Like(`%${value}%`) } 62 | ], 63 | order: { 64 | code: 'DESC' 65 | }, 66 | take: pageSize 67 | }) 68 | return list 69 | } 70 | 71 | async pages(offset = 1, size = 10, code?: string, name?: string, market?: EMarket, block?: EBLock) { 72 | const where: FindManyOptions['where'] = {} 73 | if(code) { 74 | where.code = Like(`%${code}%`) 75 | } 76 | if(name) { 77 | where.name = Like(`%${name}%`) 78 | } 79 | if(market) { 80 | where.market = Equal(market) 81 | } 82 | if(block) { 83 | where.block = Equal(block) 84 | } 85 | const options: FindManyOptions = { 86 | skip: (offset > 0 ? (offset - 1) : 0) * size, 87 | take: size, 88 | order: { id: 'ASC'}, 89 | where: {} 90 | } 91 | const pages = await useSharesRepository(Stock).findAndCount(options) 92 | return pages 93 | } 94 | 95 | async getBlocksCount(): Promise<{total: number, block: EBLock}> { 96 | const counts = await useSharesRepository(Stock) 97 | .createQueryBuilder('groupByBlocks') 98 | .select('count(*) as total, block') 99 | .groupBy('block').execute() 100 | // const counts = await createSharesQueryBuilder(Stock, 'groupByBlocks') 101 | // .select('count(*) as total, block').groupBy('block').execute() 102 | return counts 103 | } 104 | } 105 | 106 | export default new StockDao -------------------------------------------------------------------------------- /src/controllers/ArticleTypeController.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Like, 3 | Between, 4 | FindManyOptions, 5 | Equal, 6 | LessThan, 7 | MoreThan, 8 | IsNull, 9 | FindOptionsWhere 10 | } from "typeorm"; 11 | import { Context } from 'koa' 12 | import { ArticleType } from '../entities/mysql/articleType' 13 | import { Guid } from "../utils/tools"; 14 | import { endOfDay, startOfDay } from 'date-fns' 15 | import { useBlogRepository } from '../database/dbUtils'; 16 | 17 | 18 | class ArticleTypeController { 19 | 20 | async getAll(args: any) { 21 | return await useBlogRepository(ArticleType).findAndCount(); 22 | } 23 | 24 | 25 | async getById(id: string = '') { 26 | const articleType = await useBlogRepository(ArticleType).findOne({ 27 | where: { 28 | id: Equal(id) 29 | }, 30 | select: ['id', 'name', 'remark', 'createdAt', 'updatedAt'] 31 | }) 32 | return articleType 33 | } 34 | 35 | async pages(args: any) { 36 | const options: FindManyOptions = { 37 | skip: args.page < 2 ? 0 : (args.page - 1) * args.pageSize, 38 | take: args.pageSize, 39 | order: {}, 40 | where: { 41 | deletedAt: null 42 | } 43 | } 44 | const whereConditions: FindOptionsWhere = { 45 | deletedAt: IsNull(), 46 | } 47 | if(args.name) { 48 | whereConditions.name = Like(`%${args.name}%`) 49 | } 50 | if(args.createdAt) { 51 | const date = (args.createdAt as string[]).map( 52 | (d, i) => i > 0 ? +endOfDay(new Date(d)) : +startOfDay(new Date(d)) 53 | ) 54 | whereConditions.createdAt = Between(date[0], date[1]) 55 | } 56 | if(args.order) { 57 | options.order = Object.assign(options.order, args.order) 58 | } 59 | options.where = whereConditions 60 | console.log(args, '----options') 61 | const pages = await useBlogRepository(ArticleType).findAndCount(options) 62 | return pages 63 | } 64 | 65 | async insert(args: any, ctx: Context) { 66 | let model = new ArticleType() 67 | model.id = Guid() 68 | model.name = args.name 69 | model.remark = args.remark 70 | model.createdAt = Date.now() 71 | model.createdBy = ctx.state['CUR_USER'].id 72 | model.updatedAt = Date.now() 73 | model.updatedBy = ctx.state['CUR_USER'].id 74 | const result = await useBlogRepository(ArticleType).save(model) 75 | return result 76 | } 77 | 78 | async save(args: any, ctx: Context) { 79 | let model = new ArticleType() 80 | model.id = Guid() 81 | if(args.id) { 82 | model.id = args.id 83 | } else { 84 | model.createdAt = Date.now() 85 | model.createdBy = ctx.state['CUR_USER'].id 86 | } 87 | model.name = args.name 88 | model.remark = args.remark 89 | model.updatedAt = Date.now() 90 | model.updatedBy = ctx.state['CUR_USER'].id 91 | const result = await useBlogRepository(ArticleType).save(model) 92 | console.log('result:', result) 93 | return result 94 | } 95 | 96 | } 97 | 98 | export default new ArticleTypeController -------------------------------------------------------------------------------- /release/src/schema/graphql/User.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../../src/schema/graphql/User.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAwKE;;AAxKF,mCAaiB;AAEjB,+BAAgC;AAChC,mEAAuD;AACvD,mCAAqD;AAErD,OAAO;AACM,QAAA,cAAc,GAAG,IAAI,2BAAiB,CAAC;IAClD,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE;QACN,EAAE,EAAE;YACF,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,uBAAa;SACpB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,oBAAU;SACjB;QACD,GAAG,EAAE;YACH,IAAI,EAAE,oBAAU;SACjB;QACD,MAAM,EAAE;YACN,IAAI,EAAE,uBAAa;SACpB;QACD,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;YACnB,OAAO,YAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;gBAC1B,IAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;gBACrD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAA;YACxD,CAAC;SACF;QACD,SAAS,EAAE;YACT,IAAI,EAAE,uBAAa;SACpB;KACF;CAC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C,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAA;;wBAAzC,MAAM,GAAG,SAAgC;wBAC/C,sBAAO,MAAM,EAAA;;;aACd;KACF;CACF,CAAA;AAED,kBAAe;IACb,KAAK,OAAA;IACL,QAAQ,UAAA;CACT,CAAC"} -------------------------------------------------------------------------------- /release/src/entities/mysql/article.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 16 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 17 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 18 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 19 | return c > 3 && r && Object.defineProperty(target, key, r), r; 20 | }; 21 | var __metadata = (this && this.__metadata) || function (k, v) { 22 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | require("reflect-metadata"); 26 | var typeorm_1 = require("typeorm"); 27 | var baseEntity_1 = require("./baseEntity"); 28 | var Article = /** @class */ (function (_super) { 29 | __extends(Article, _super); 30 | function Article() { 31 | return _super !== null && _super.apply(this, arguments) || this; 32 | } 33 | __decorate([ 34 | typeorm_1.Column(), 35 | __metadata("design:type", String) 36 | ], Article.prototype, "title", void 0); 37 | __decorate([ 38 | typeorm_1.Column(), 39 | __metadata("design:type", String) 40 | ], Article.prototype, "abstract", void 0); 41 | __decorate([ 42 | typeorm_1.Column({ 43 | type: 'longtext' 44 | }), 45 | __metadata("design:type", String) 46 | ], Article.prototype, "description", void 0); 47 | __decorate([ 48 | typeorm_1.Column({ length: 32 }), 49 | __metadata("design:type", String) 50 | ], Article.prototype, "typeId", void 0); 51 | __decorate([ 52 | typeorm_1.Column({ 53 | default: 0 54 | }), 55 | __metadata("design:type", Number) 56 | ], Article.prototype, "isTop", void 0); 57 | __decorate([ 58 | typeorm_1.Column(), 59 | __metadata("design:type", String) 60 | ], Article.prototype, "pics", void 0); 61 | __decorate([ 62 | typeorm_1.Column(), 63 | __metadata("design:type", String) 64 | ], Article.prototype, "tag", void 0); 65 | Article = __decorate([ 66 | typeorm_1.Entity('article') 67 | ], Article); 68 | return Article; 69 | }(baseEntity_1.BaseEntity)); 70 | exports.Article = Article; 71 | //# sourceMappingURL=article.js.map -------------------------------------------------------------------------------- /release/src/core/jwt/verify.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | Object.defineProperty(exports, "__esModule", { value: true }); 16 | var sign_1 = require("./sign"); 17 | var JsonWebTokenError = /** @class */ (function (_super) { 18 | __extends(JsonWebTokenError, _super); 19 | function JsonWebTokenError(msg) { 20 | var _this = _super.call(this) || this; 21 | _this.name = 'JsonWebTokenError'; 22 | _this.message = msg; 23 | return _this; 24 | } 25 | return JsonWebTokenError; 26 | }(Error)); 27 | // verify is equal 28 | function verifyEqual(thing, sig, secrect) { 29 | var computeSig = sign_1.createHmacSigner(thing, secrect); 30 | // console.log('verifyEqual--', computeSig, secrect) 31 | return computeSig === sig; 32 | } 33 | exports.verify = function (jwtStr, opts) { 34 | var jwtToken = jwtStr.split(' ')[1]; // "Bearer jwtToken" 35 | // console.log(jwtStr, '-------',jwtToken) 36 | if (!/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+){1}$/.test(jwtToken)) { 37 | throw new JsonWebTokenError('jwt js error format'); 38 | } 39 | try { 40 | var jwtTokenArr = jwtToken.split('.'); 41 | var header = JSON.parse(Buffer.from(jwtTokenArr[0], 'base64').toString('binary')); 42 | var payload = JSON.parse(Buffer.from(jwtTokenArr[1], 'base64').toString(opts.encoding || 'utf-8')); 43 | var signature = jwtTokenArr[2]; 44 | // check header 45 | if (header && header.alg !== 'HS256') { 46 | return [false, 'invalid algorithm']; 47 | } 48 | if (header && header.typ !== 'JWT') { 49 | return [false, 'invalid type']; 50 | } 51 | // check payload 52 | if (payload && typeof payload.exp !== 'number') { 53 | return [false, 'invalid exp']; 54 | } 55 | if (payload && typeof payload.iat !== 'number') { 56 | return [false, 'invalid iat']; 57 | } 58 | // check signature 59 | if (!signature) { 60 | return [false, 'invalid signature']; 61 | } 62 | // verify jwtString sig 63 | var isEqual = verifyEqual(jwtTokenArr[0] + '.' + jwtTokenArr[1], signature, opts.secret); 64 | if (!isEqual) { 65 | return [false, 'sig verify error']; 66 | } 67 | // verify exp 68 | if (Date.now() >= payload.exp) { 69 | return [false, 'jwt expired']; 70 | } 71 | return [true, payload]; 72 | } 73 | catch (e) { 74 | throw new JsonWebTokenError(e.message || 'jwt verify error'); 75 | } 76 | }; 77 | //# sourceMappingURL=verify.js.map -------------------------------------------------------------------------------- /release/src/middlewares/request.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"request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