生产环境默认引用本地的后台插件路径

This commit is contained in:
doramart 2020-02-04 16:29:05 +08:00
parent 6b42c747e0
commit 2ceb5c1ee7
37 changed files with 54 additions and 187 deletions

4
app/controller/api/admin.js Normal file → Executable file
View File

@ -2,7 +2,7 @@
* @Author: doramart
* @Date: 2019-06-27 17:16:32
* @Last Modified by: doramart
* @Last Modified time: 2020-02-03 13:23:29
* @Last Modified time: 2020-02-04 16:08:53
*/
const Controller = require('egg').Controller;
const jwt = require('jsonwebtoken')
@ -12,6 +12,7 @@ const {
adminUserRule
} = require('@validate')
class AdminController extends Controller {
@ -138,6 +139,7 @@ class AdminController extends Controller {
}
}
}
module.exports = AdminController;

View File

@ -1,144 +0,0 @@
/*
* @Author: doramart
* @Date: 2019-08-16 16:06:21
* @Last Modified by: doramart
* @Last Modified time: 2019-11-02 22:15:40
*/
const Controller = require('egg').Controller;
const awaitWriteStream = require('await-stream-ready').write
const sendToWormhole = require('stream-wormhole')
const fs = require('fs')
const path = require('path')
let confirmPath = (path) => {
return new Promise(function (resolve, reject) {
let waitCheck = () => {
setTimeout(() => {
if (!fs.existsSync(path)) {
if (checkPathNum == 3) {
resolve(fs.existsSync(path));
} else {
checkPathNum++;
waitCheck();
}
} else {
resolve(fs.existsSync(path));
}
}, 200);
}
waitCheck();
})
}
let checkFilePath = async function (path) {
checkPathNum = 0;
return await confirmPath(path);
};
let updateLogoPath = async (ctx, model, targetFiles = []) => {
let targetItemList = await ctx.service[model].find({
isPaging: '0'
})
for (const targetItem of targetItemList) {
for (const fileItem of targetFiles) {
if (targetItem[fileItem]) {
var reg = new RegExp('/upload/', "g");
let oldfile = targetItem[fileItem];
let newFile = oldfile.replace(reg, '/static/upload/');
let newObj = {};
newObj[fileItem] = newFile;
await ctx.service[model].update(ctx, targetItem._id, newObj);
}
}
}
}
class UploadController extends Controller {
// 上传单个文件
async create() {
const {
ctx,
service
} = this
//存放目录
let updatePath = `${this.app.config.upload_path}/upload/images/`;
let updateVideoPath = `${this.app.config.upload_path}/upload/videos/`;
let updateAudioPath = `${this.app.config.upload_path}/upload/audios/`;
let updateOtherPath = `${this.app.config.upload_path}/upload/others/`;
// 要通过 ctx.getFileStream 便捷的获取到用户上传的文件,需要满足两个条件:
// 只支持上传一个文件。
// 上传文件必须在所有其他的 fields 后面,否则在拿到文件流时可能还获取不到 fields。
const stream = await ctx.getFileStream();
let fileParams = stream.fields;
let askFileType = fileParams.type || 'image'; // 默认上传图片
// console.log('--askFileType--', askFileType);
// 文件类型校验
if (askFileType == 'image') {
} else if (askFileType == 'video') {
updatePath = updateVideoPath;
} else if (askFileType == 'audio') {
updatePath = updateAudioPath;
} else {
updatePath = updateOtherPath;
}
if (!fs.existsSync(updatePath)) {
fs.mkdirSync(updatePath);
}
// 所有表单字段都能通过 `stream.fields` 获取到
const filename = path.basename(stream.filename) // 文件名称
const extname = path.extname(stream.filename).toLowerCase() // 文件扩展名称
if (!extname) {
throw new Error(res.__('validate_error_params'));
}
// 生成文件名
let ms = (new Date()).getTime().toString() + extname;
const attachment = {};
attachment.extname = extname || 'hello'
attachment.filename = filename
const target = path.join(updatePath, `${ms}`)
const writeStream = fs.createWriteStream(target)
// 文件处理,上传到云存储等等
try {
await awaitWriteStream(stream.pipe(writeStream))
} catch (err) {
// 必须将上传的文件流消费掉,要不然浏览器响应会卡死
await sendToWormhole(stream)
throw err
}
// 设置响应内容和响应状态码
ctx.helper.renderSuccess(ctx, {
data: {
path: `${this.app.config.static.prefix}/upload/images/${ms}`
}
});
}
async updateImgs() {
let ctx = this.ctx
updateLogoPath(ctx, 'adminUser', ['logo']);
updateLogoPath(ctx, 'adsItem', ['sImg']);
updateLogoPath(ctx, 'content', ['sImg', 'comments', 'simpleComments']);
updateLogoPath(ctx, 'user', ['logo']);
ctx.helper.renderSuccess(ctx);
}
}
module.exports = UploadController;

View File

@ -2,7 +2,7 @@
* @Author: doramart
* @Date: 2019-06-20 18:55:40
* @Last Modified by: doramart
* @Last Modified time: 2020-02-03 13:19:53
* @Last Modified time: 2020-02-04 12:24:12
*/
const Controller = require('egg').Controller;
const {
@ -489,7 +489,7 @@ class AdminUserController extends Controller {
let pluginStr = `dora${pathItem.charAt(0).toUpperCase() + pathItem.slice(1)}`;
if (plugins.indexOf(pluginStr) >= 0 && this.app.config[pluginStr].adminUrl) {
let adminUrlItem = this.app.config[pluginStr].adminUrl;
let adminUrlItem = this.app.config.admin_root_path + this.app.config[pluginStr].adminUrl;
if (adminUrlItem instanceof Array) {
for (const routerItem of adminUrlItem) {
renderMap.push({

View File

@ -29,7 +29,8 @@ module.exports = appInfo => {
// 'helpCenter',
// 'renderCms',
// 'cmsTemplate',
// 'plugin'
// 'plugin',
// 'uploadFile'
],
// DEV_CONFIG_MODULES_END
mongoose: {
@ -51,7 +52,7 @@ module.exports = appInfo => {
},
server_path: 'http://localhost:8080',
server_api: 'http://localhost:8080/api',
}
};

View File

@ -5,7 +5,7 @@ module.exports = appInfo => {
return {
// 插件路径
admin_root_path: 'https://cdn.html-js.cn/cms/plugins/static/admin',
admin_root_path: '/static',
// 数据库连接
mongoose: {
client: {
@ -19,7 +19,7 @@ module.exports = appInfo => {
// 静态目录
static: {
prefix: '/static',
dir: [path.join(appInfo.baseDir, 'app/public'), '/home/doraData/uploadFiles/static'],
dir: [path.join(appInfo.baseDir, 'app/public'), path.join(appInfo.baseDir, 'backstage/dist'), '/home/doraData/uploadFiles/static'],
maxAge: 31536000,
},
// 日志路径

View File

@ -159,7 +159,7 @@ exports.doraUploadFile = {
// doraUploadFilePluginEnd
// doraValidatePluginBegin
exports.doraValidate = {
exports.validate = {
enable: true,
package: 'egg-dora-validate',

View File

@ -17,7 +17,7 @@ exports.doraAds = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_shakehands_fill', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/ads/js/app.js',
adminUrl: '/ads/js/app.js',
adminApi: [{
url: 'ads/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-ads",
"version": "1.0.6",
"version": "1.0.7",
"description": "ads",
"eggPlugin": {
"name": "doraAds"

View File

@ -17,7 +17,7 @@ exports.doraAnnounce = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_inform_fill', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/announce/js/app.js',
adminUrl: '/announce/js/app.js',
adminApi: [{
url: 'systemAnnounce/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-announce",
"version": "1.0.5",
"version": "1.0.6",
"description": "announce",
"eggPlugin": {
"name": "doraAnnounce"

View File

@ -17,7 +17,7 @@ exports.doraBackUpData = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_cspace', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/backUpData/js/app.js',
adminUrl: '/backUpData/js/app.js',
adminApi: [{
url: 'backupDataManage/getBakList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-backupdata",
"version": "1.0.5",
"version": "1.0.6",
"description": "backUpData",
"eggPlugin": {
"name": "doraBackUpData"

View File

@ -413,11 +413,14 @@ let ContentController = {
filesType = 'stage1';
isSingerPage = true;
let ableCateList = await this.getEnableCateList(ctx, isSingerPage);
_.assign(queryObj, {
categories: {
$in: ableCateList
}
});
if (ableCateList.indexOf(typeId) < 0) {
_.assign(queryObj, {
categories: {
$in: ableCateList
}
});
}
}
} else {
// 只查询可见分类的文章

View File

@ -17,7 +17,7 @@ exports.doraContent = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_doc_fill', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/content/js/app.js',
adminUrl: '/content/js/app.js',
adminApi: [{
url: 'content/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-content",
"version": "1.0.7",
"version": "1.0.8",
"description": "content",
"eggPlugin": {
"name": "doraContent"

View File

@ -17,7 +17,7 @@ exports.doraContentCategory = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_category', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/contentCategory/js/app.js',
adminUrl: '/contentCategory/js/app.js',
adminApi: [{
url: 'contentCategory/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-contentcategory",
"version": "1.0.5",
"version": "1.0.6",
"description": "contentCategory",
"eggPlugin": {
"name": "doraContentCategory"

View File

@ -17,7 +17,7 @@ exports.doraContentMessage = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_service', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/contentMessage/js/app.js',
adminUrl: '/contentMessage/js/app.js',
adminApi: [{
url: 'contentMessage/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-contentmessage",
"version": "1.0.5",
"version": "1.0.6",
"description": "contentMessage",
"eggPlugin": {
"name": "doraContentMessage"

View File

@ -17,7 +17,7 @@ exports.doraContentTags = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_tags', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/contentTags/js/app.js',
adminUrl: '/contentTags/js/app.js',
adminApi: [{
url: 'contentTag/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-contenttags",
"version": "1.0.5",
"version": "1.0.6",
"description": "contentTag",
"eggPlugin": {
"name": "doraContentTags"

View File

@ -17,7 +17,7 @@ exports.doraContentTemp = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_compile', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/contentTemp/js/app.js',
adminUrl: '/contentTemp/js/app.js',
adminApi: [{
url: 'template/getTemplateForderList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-contenttemp",
"version": "1.0.7",
"version": "1.0.8",
"description": "contentTemplate",
"eggPlugin": {
"name": "doraContentTemp"

View File

@ -17,7 +17,7 @@ exports.doraHelpCenter = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_service', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/helpCenter/js/app.js',
adminUrl: '/helpCenter/js/app.js',
adminApi: [{
url: 'helpCenter/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-helpcenter",
"version": "1.0.7",
"version": "1.0.8",
"description": "helpCenter",
"eggPlugin": {
"name": "doraHelpCenter"

View File

@ -17,7 +17,7 @@ exports.doraRegUser = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_people_fill', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/regUser/js/app.js',
adminUrl: '/regUser/js/app.js',
adminApi: [{
url: 'regUser/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-reguser",
"version": "1.0.8",
"version": "1.0.9",
"description": "regUser",
"eggPlugin": {
"name": "doraRegUser"

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-sitemessage",
"version": "1.0.5",
"version": "1.0.6",
"description": "siteMessage",
"eggPlugin": {
"name": "doraSiteMessage"

View File

@ -17,7 +17,7 @@ exports.doraSystemNotify = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_system_notic', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/systemNotify/js/app.js',
adminUrl: '/systemNotify/js/app.js',
adminApi: [{
url: 'systemNotify/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-systemnotify",
"version": "1.0.6",
"version": "1.0.7",
"description": "systemNotify",
"eggPlugin": {
"name": "doraSystemNotify"

View File

@ -17,7 +17,7 @@ exports.doraSystemOptionLog = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_logs', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/systemOptionLog/js/app.js',
adminUrl: '/systemOptionLog/js/app.js',
adminApi: [{
url: 'systemOptionLog/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-systemoptionlog",
"version": "1.0.5",
"version": "1.0.6",
"description": "systemOptionLog",
"eggPlugin": {
"name": "doraSystemOptionLog"

View File

@ -17,7 +17,7 @@ exports.doraTemplateConfig = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_skin', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/templateConfig/js/app.js',
adminUrl: '/templateConfig/js/app.js',
adminApi: [{
url: 'template/getMyTemplateList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-templateconfig",
"version": "1.0.8",
"version": "1.0.9",
"description": "templateConfig",
"eggPlugin": {
"name": "doraTemplateConfig"

View File

@ -17,7 +17,7 @@ exports.doraVersionManage = {
isindex: 0, // 是否需要前台访问1需要0不需要,入口地址:'/ext/devteam/index/index'
version: pkgInfo.version, // 版本号
iconName: 'icon_app', // 主菜单图标名称
adminUrl: 'https://cdn.html-js.cn/cms/plugins/static/admin/versionManage/js/app.js',
adminUrl: '/versionManage/js/app.js',
adminApi: [{
url: 'versionManage/getList',
method: 'get',

View File

@ -1,6 +1,6 @@
{
"name": "egg-dora-versionmanage",
"version": "1.0.6",
"version": "1.0.7",
"description": "versionManage",
"eggPlugin": {
"name": "doraVersionManage"

View File

@ -57,6 +57,11 @@
"autod": "autod",
"pkgfiles": "egg-bin pkgfiles",
"init": "node ./build/restore",
"makePrdDoc": "apidoc -i lib/plugin -e node_modules -o app/public/apidoc/ && npm run modifyPrdDoc",
"modifyPrdDoc": "node ./build/renderApiDoc --docv prd",
"start": "egg-scripts start --daemon --title=doracms2",
@ -95,4 +100,4 @@
"@utils": "app/utils"
},
"license": "MIT"
}
}