Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lienren committed Feb 25, 2018
1 parent 9169dd4 commit 21699fa
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 23 deletions.
31 changes: 11 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Lienren
* @Date: 2018-01-02 14:28:21
* @Last Modified by: Lienren
* @Last Modified time: 2018-01-10 19:57:23
* @Last Modified time: 2018-01-24 14:44:59
*/
'use strict';
const http = require('http');
Expand All @@ -19,31 +19,22 @@ const sqlhelper = require('mysql-helper-simple')(mysql_config);
app.context.db = sqlhelper;

// redis初始化
const redis_config = require('./configs/redis_config');
const redis = require('ioredis');
const redishelper = new redis(redis_config);
app.context.redis = redishelper;
// const redis_config = require('./configs/redis_config');
// const redis = require('ioredis');
// const redishelper = new redis(redis_config);
// app.context.redis = redishelper;
// 启动redis服务
// redis-server /usr/local/etc/redis.conf

// mongodb初始化
// sudo mongod --config /usr/local/etc/mongod.conf --auth

// 静态存放地址
const staticPath = './static';
app.use(koastatic(path.join(__dirname, staticPath)));

// 配置跨域访问
app.use(
cors({
origin: function(ctx) {
if (ctx.url === '/test') {
return false;
}
return '*';
},
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
maxAge: 5,
credentials: true,
allowMethods: ['GET', 'POST', 'DELETE'],
allowHeaders: ['Content-Type', 'Authorization', 'Accept']
})
);
app.use(cors());

// 使用koa-bodyparser中间件
app.use(bodyParser());
Expand Down
Binary file added fonts/PingFang.ttc
Binary file not shown.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"dependencies": {
"async": "^2.6.0",
"axios": "^0.17.1",
"barcode": "^0.1.0",
"gm": "^1.23.1",
"ioredis": "^3.2.2",
"koa": "^2.4.1",
"koa-bodyparser": "^4.2.0",
Expand All @@ -14,7 +16,8 @@
"koa2-cors": "^2.0.5",
"md5": "^2.2.1",
"mysql-helper-simple": "^1.1.2",
"squel": "^5.12.0"
"squel": "^5.12.0",
"uuid": "^3.2.1"
},
"devDependencies": {},
"scripts": {
Expand Down
77 changes: 75 additions & 2 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,75 @@
* @Author: Lienren
* @Date: 2018-01-08 16:21:55
* @Last Modified by: Lienren
* @Last Modified time: 2018-01-10 20:18:48
* @Last Modified time: 2018-01-25 10:45:04
*/
'use strict';
('use strict');
const uuidv1 = require('uuid/v1');
const fs = require('fs');
const path = require('path');
const Router = require('koa-router');
const squel = require('squel');
const axios = require('axios');
const md5 = require('md5');
const gm = require('gm');
const barcode = require('barcode');
const router = new Router();

function makeimg() {
let uuid = uuidv1();
// let file_name = uuid + '.jpg';
let file_name = '123456.jpg';
let file_path = 'make_imgs';
let domain = '';
let phy_path = path.join(__dirname, './static', file_path);
let phy_file = path.join(phy_path, file_name);
let vir_path = path.join(domain, file_path);
let vir_file = path.join(vir_path, file_name);

if (!fs.existsSync(phy_path)) {
fs.mkdirSync(phy_path);
}

var code39 = barcode('code39', {
data: 'it works',
width: 400,
height: 100
});

return new Promise((resolve, reject) => {
code39.getStream(function(err, readStream) {
if (err) throw err;

gm(1181, 1771, '#ffffff')
.setFormat('JPEG')
.font('./fonts/PingFang.ttc')
.fontSize(48)
.drawText(10, 50, '李恩仁打印测试')
.append(readStream)
.quality(100)
.noProfile()
.strip()
.write(phy_file, err => {
if (err) {
reject(err);
} else {
if (fs.existsSync(phy_file)) {
resolve({
exists: true,
filepath: vir_file
});
} else {
resolve({
exists: false,
filepath: ''
});
}
}
});
});
});
}

router
.get('/', async (ctx, next) => {
ctx.body = `<h1>你好</h1>`;
Expand Down Expand Up @@ -65,6 +125,19 @@ router
...response.status
};
}
})
.get('/getimg', async (ctx, next) => {
await makeimg()
.then(data => {
ctx.body = {
...data
};
})
.catch(err => {
ctx.body = {
err: err
};
});
});

module.exports = router.routes();
Binary file added static/make_imgs/123456.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ any-promise@^1.0.0, any-promise@^1.1.0:
version "1.3.0"
resolved "http://registry.npm.taobao.org/any-promise/download/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"

array-parallel@~0.1.0, array-parallel@~0.1.3:
version "0.1.3"
resolved "http://registry.npm.taobao.org/array-parallel/download/array-parallel-0.1.3.tgz#8f785308926ed5aa478c47e64d1b334b6c0c947d"

array-series@~0.1.0, array-series@~0.1.5:
version "0.1.5"
resolved "http://registry.npm.taobao.org/array-series/download/array-series-0.1.5.tgz#df5d37bfc5c2ef0755e2aa4f92feae7d4b5a972f"

async@^2.6.0:
version "2.6.0"
resolved "http://registry.npm.taobao.org/async/download/async-2.6.0.tgz#61a29abb6fcc026fea77e56d1c6ec53a795951f4"
Expand All @@ -26,6 +34,12 @@ axios@^0.17.1:
follow-redirects "^1.2.5"
is-buffer "^1.1.5"

barcode@^0.1.0:
version "0.1.0"
resolved "http://registry.npm.taobao.org/barcode/download/barcode-0.1.0.tgz#49b163150814a3f3fb0fa0c0aa2874d28a0f38d7"
dependencies:
gm "1.16.0"

[email protected]:
version "4.0.4"
resolved "http://registry.npm.taobao.org/bignumber.js/download/bignumber.js-4.0.4.tgz#7c40f5abcd2d6623ab7b99682ee7db81b11889a4"
Expand Down Expand Up @@ -82,6 +96,13 @@ core-util-is@~1.0.0:
version "1.0.2"
resolved "http://registry.npm.taobao.org/core-util-is/download/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"

cross-spawn@^4.0.0:
version "4.0.2"
resolved "http://registry.npm.taobao.org/cross-spawn/download/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41"
dependencies:
lru-cache "^4.0.1"
which "^1.2.9"

crypt@~0.0.1:
version "0.0.2"
resolved "http://registry.npm.taobao.org/crypt/download/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
Expand All @@ -92,6 +113,10 @@ debug@*, debug@^3.1.0:
dependencies:
ms "2.0.0"

[email protected]:
version "0.7.0"
resolved "http://registry.npm.taobao.org/debug/download/debug-0.7.0.tgz#f5be05ec0434c992d79940e50b2695cfb2e01b08"

debug@^2.6.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -144,6 +169,25 @@ fresh@^0.5.2:
version "0.5.2"
resolved "http://registry.npm.taobao.org/fresh/download/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"

[email protected]:
version "1.16.0"
resolved "http://registry.npm.taobao.org/gm/download/gm-1.16.0.tgz#2b3d37b25fb349286e829bf1ccf097f4de4fba88"
dependencies:
array-parallel "~0.1.0"
array-series "~0.1.0"
debug "0.7.0"
stream-to-buffer "~0.0.1"
through "~2.3.1"

gm@^1.23.1:
version "1.23.1"
resolved "http://registry.npm.taobao.org/gm/download/gm-1.23.1.tgz#2edeeb958084d0f8ea7988e5d995b1c7dfc14777"
dependencies:
array-parallel "~0.1.3"
array-series "~0.1.5"
cross-spawn "^4.0.0"
debug "^3.1.0"

http-assert@^1.1.0:
version "1.3.0"
resolved "http://registry.npm.taobao.org/http-assert/download/http-assert-1.3.0.tgz#a31a5cf88c873ecbb5796907d4d6f132e8c01e4a"
Expand Down Expand Up @@ -224,6 +268,10 @@ isarray@~1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"

isexe@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"

keygrip@~1.0.2:
version "1.0.2"
resolved "http://registry.npm.taobao.org/keygrip/download/keygrip-1.0.2.tgz#ad3297c557069dea8bcfe7a4fa491b75c5ddeb91"
Expand Down Expand Up @@ -384,6 +432,13 @@ lodash@^4.14.0:
version "4.17.4"
resolved "http://registry.npm.taobao.org/lodash/download/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

lru-cache@^4.0.1:
version "4.1.1"
resolved "http://registry.npm.taobao.org/lru-cache/download/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"

md5@^2.2.1:
version "2.2.1"
resolved "http://registry.npm.taobao.org/md5/download/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
Expand Down Expand Up @@ -473,6 +528,10 @@ process-nextick-args@~1.0.6:
version "1.0.7"
resolved "http://registry.npm.taobao.org/process-nextick-args/download/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"

pseudomap@^1.0.2:
version "1.0.2"
resolved "http://registry.npm.taobao.org/pseudomap/download/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"

qs@^6.4.0:
version "6.5.1"
resolved "http://registry.npm.taobao.org/qs/download/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
Expand Down Expand Up @@ -537,6 +596,10 @@ squel@^5.12.0:
version "1.4.0"
resolved "http://registry.npm.taobao.org/statuses/download/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087"

stream-to-buffer@~0.0.1:
version "0.0.1"
resolved "http://registry.npm.taobao.org/stream-to-buffer/download/stream-to-buffer-0.0.1.tgz#ab483d59a1ca71832de379a255f465b665af45c1"

string_decoder@~1.0.3:
version "1.0.3"
resolved "http://registry.npm.taobao.org/string_decoder/download/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab"
Expand All @@ -555,6 +618,10 @@ thenify-all@^1.0.0:
dependencies:
any-promise "^1.0.0"

through@~2.3.1:
version "2.3.8"
resolved "http://registry.npm.taobao.org/through/download/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"

type-is@^1.5.5, type-is@^1.6.14:
version "1.6.15"
resolved "http://registry.npm.taobao.org/type-is/download/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
Expand All @@ -574,6 +641,20 @@ util-deprecate@~1.0.1:
version "1.0.2"
resolved "http://registry.npm.taobao.org/util-deprecate/download/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

uuid@^3.2.1:
version "3.2.1"
resolved "http://registry.npm.taobao.org/uuid/download/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14"

vary@^1.0.0:
version "1.1.2"
resolved "http://registry.npm.taobao.org/vary/download/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"

which@^1.2.9:
version "1.3.0"
resolved "http://registry.npm.taobao.org/which/download/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
dependencies:
isexe "^2.0.0"

yallist@^2.1.2:
version "2.1.2"
resolved "http://registry.npm.taobao.org/yallist/download/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"

0 comments on commit 21699fa

Please sign in to comment.