Browse Source

七牛宣传文件上传

release_0.0.1
巴林闲侠 3 years ago
parent
commit
e879a4cadf
  1. 5
      api/.vscode/launch.json
  2. 77
      api/app/lib/controllers/data/publicity.js
  3. 52
      api/app/lib/models/publicity.js
  4. 12
      api/app/lib/routes/data/index.js
  5. 21
      api/config.js
  6. 1185
      api/log/development.log
  7. 2
      api/sequelize-automate.config.js

5
api/.vscode/launch.json

@ -16,6 +16,11 @@
"-p 14000", "-p 14000",
"-f http://localhost:14000", "-f http://localhost:14000",
"-g postgres://postgres:123@10.8.30.32:5432/highways4good", "-g postgres://postgres:123@10.8.30.32:5432/highways4good",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",
"--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa",
"--qnbkt dev-highways4good",
// "--qndmn http://resources.anxinyun.cn",
"--qndmn http://rfkimpwbb.hn-bkt.clouddn.com",
] ]
}, },
{ {

77
api/app/lib/controllers/data/publicity.js

@ -0,0 +1,77 @@
'use strict';
async function publicityGet (ctx) {
try {
const models = ctx.fs.dc.models;
const { enable } = ctx.query;
let findOption = {
where: {},
order: [['id', 'DESC']]
}
if (enable) {
findOption.where.enable = true
}
const roadRes = await models.Publicity.findAll(findOption)
ctx.status = 200;
ctx.body = roadRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function publicityEdit (ctx) {
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
if (!data.publicityId) {
await models.Publicity.create(data)
} else {
await models.Publicity.update(
data, {
where: {
id: data.publicityId
}
})
}
ctx.status = 204
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function publicityDel (ctx) {
try {
const models = ctx.fs.dc.models;
const { publicityId } = ctx.params;
await models.Publicity.destroy({
where: {
id: publicityId
}
})
ctx.status = 204
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
publicityGet, publicityEdit, publicityDel,
};

52
api/app/lib/models/publicity.js

@ -0,0 +1,52 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const Publicity = sequelize.define("publicity", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: true,
field: "id",
autoIncrement: true,
unique: "publicity_id_uindex"
},
name: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "name",
autoIncrement: false
},
video: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "video",
autoIncrement: false
},
enable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: null,
primaryKey: false,
field: "enable",
autoIncrement: false
}
}, {
tableName: "publicity",
comment: "",
indexes: []
});
dc.models.Publicity = Publicity;
return Publicity;
};

12
api/app/lib/routes/data/index.js

@ -6,6 +6,7 @@ const bridge = require('../../controllers/data/bridge');
const project = require('../../controllers/data/project'); const project = require('../../controllers/data/project');
const overspeed = require('../../controllers/data/overspeed'); const overspeed = require('../../controllers/data/overspeed');
const bus = require('../../controllers/data/bus'); const bus = require('../../controllers/data/bus');
const publicity = require('../../controllers/data/publicity');
module.exports = function (app, router, opts) { module.exports = function (app, router, opts) {
@ -131,4 +132,15 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/bus/car/:carId'] = { content: '删除公交车辆数据', visible: false }; app.fs.api.logAttr['DEL/bus/car/:carId'] = { content: '删除公交车辆数据', visible: false };
router.del('/bus/car/:carId', bus.carDel); router.del('/bus/car/:carId', bus.carDel);
//bus END //bus END
//publicity
app.fs.api.logAttr['GET/publicity'] = { content: '获取宣传数据', visible: true };
router.get('/publicity', publicity.publicityGet);
app.fs.api.logAttr['PUT/publicity'] = { content: '编辑宣传数据', visible: true };
router.put('/publicity', publicity.publicityEdit);
app.fs.api.logAttr['DEL/publicity/:publicityId'] = { content: '删除宣传数据', visible: false };
router.del('/publicity/:publicityId', publicity.publicityDel);
//publicity END
}; };

21
api/config.js

@ -11,11 +11,22 @@ const dev = process.env.NODE_ENV == 'development';
args.option(['p', 'port'], '启动端口'); args.option(['p', 'port'], '启动端口');
args.option(['g', 'pg'], 'postgre服务URL'); args.option(['g', 'pg'], 'postgre服务URL');
args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地址(必填), 该服务器提供文件上传Web服务'); args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地址(必填), 该服务器提供文件上传Web服务');
// 七牛云存储参数
args.option('qnak', 'qiniuAccessKey');
args.option('qnsk', 'qiniuSecretKey');
args.option('qnbkt', 'qiniuBucket');
args.option('qndmn', 'qiniuDomain');
//
const flags = args.parse(process.argv); const flags = args.parse(process.argv);
const FS_UNIAPP_DB = process.env.FS_UNIAPP_DB || flags.pg; const FS_UNIAPP_DB = process.env.FS_UNIAPP_DB || flags.pg;
const FS_UNIAPP_FC_LOCAL_SVR_ORIGIN = process.env.FS_UNIAPP_FC_LOCAL_SVR_ORIGIN || flags.fileHost; const LOCAL_SVR_ORIGIN = process.env.LOCAL_SVR_ORIGIN || flags.fileHost;
const QINIU_DOMAIN_QNDMN_RESOURCE = process.env.QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn;
const QINIU_BUCKET_RESOURCE = process.env.QINIU_BUCKET_RESOURCE || flags.qnbkt;
const QINIU_AK = process.env.QINIU_AK || flags.qnak;
const QINIU_SK = process.env.QINIU_SK || flags.qnsk;
if (!FS_UNIAPP_DB) { if (!FS_UNIAPP_DB) {
console.log('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
@ -31,10 +42,16 @@ const product = {
entry: require('@fs/attachment').entry, entry: require('@fs/attachment').entry,
opts: { opts: {
local: { local: {
origin: FS_UNIAPP_FC_LOCAL_SVR_ORIGIN || `http://localhost:${flags.port || 8080}`, origin: LOCAL_SVR_ORIGIN || `http://localhost:${flags.port || 8080}`,
rootPath: 'static', rootPath: 'static',
childPath: 'upload', childPath: 'upload',
}, },
qiniu: {
domain: QINIU_DOMAIN_QNDMN_RESOURCE,
bucket: QINIU_BUCKET_RESOURCE,
accessKey: QINIU_AK,
secretKey: QINIU_SK
},
maxSize: 104857600, // 100M maxSize: 104857600, // 100M
} }
}, { }, {

1185
api/log/development.log

File diff suppressed because it is too large

2
api/sequelize-automate.config.js

@ -27,7 +27,7 @@ module.exports = {
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: null, // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 tables: null, // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: ['report'], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 skipTables: ['report', 'publicity'], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面
attrLength: false, // 在生成模型的字段中 是否生成 如 var(128)这种格式,公司一般使用 String ,则配置为 false attrLength: false, // 在生成模型的字段中 是否生成 如 var(128)这种格式,公司一般使用 String ,则配置为 false

Loading…
Cancel
Save