-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.7' of https://github.com/steedos/steedos-platform int…
…o 2.7
- Loading branch information
Showing
2 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
/* | ||
* @Author: [email protected] | ||
* @Date: 2022-03-28 09:35:34 | ||
* @LastEditors: baozhoutao@steedos.com | ||
* @LastEditTime: 2022-11-17 10:21:16 | ||
* @LastEditors: 孙浩林 sunhaolin@steedos.com | ||
* @LastEditTime: 2024-10-11 16:39:42 | ||
* @Description: | ||
*/ | ||
"use strict"; | ||
const project = require('./package.json'); | ||
const packageName = project.name; | ||
const packageLoader = require('@steedos/service-meteor-package-loader'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const { DbManager } = require('./lib/util/dbManager') | ||
const { jsonToDb } = require('./lib/metadata/deploy/jsonToDb') | ||
const { deleteFolderRecursive } = require('@steedos/metadata-core') | ||
const { loadFileToJson } = require('./lib/metadata/deploy/fileToJson') | ||
/** | ||
* @typedef {import('moleculer').Context} Context Moleculer's Context | ||
* 软件包服务启动后也需要抛出事件。 | ||
|
@@ -37,6 +43,14 @@ module.exports = { | |
*/ | ||
actions: { | ||
|
||
deploy: { | ||
async handler(ctx) { | ||
const { fileBase64 } = ctx.params | ||
const userSession = ctx.meta.user | ||
return await this.deploy(fileBase64, userSession) | ||
} | ||
} | ||
|
||
}, | ||
|
||
/** | ||
|
@@ -51,6 +65,63 @@ module.exports = { | |
*/ | ||
methods: { | ||
|
||
deploy: async function (fileBase64, userSession) { | ||
const dataBuffer = Buffer.from(fileBase64, 'base64'); | ||
|
||
var tempDFolder = path.join(os.tmpdir(), "steedos-dx"); | ||
|
||
if (!fs.existsSync(tempDFolder)) { | ||
fs.mkdirSync(tempDFolder); | ||
} | ||
|
||
var tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "steedos-dx", 'upload-')); | ||
|
||
var zipDir = path.join(tempDir, 'deploy.zip'); | ||
|
||
fs.writeFileSync(zipDir, dataBuffer); | ||
var resMsg = { | ||
status: 0, | ||
msg: '', | ||
}; | ||
|
||
var dbManager = new DbManager(userSession); | ||
try { | ||
let SteedosPackage = await loadFileToJson(tempDir); | ||
|
||
var isEmptyPackage = true; | ||
for (const metadataName in SteedosPackage) { | ||
const metadata = SteedosPackage[metadataName]; | ||
for (const key in metadata) { | ||
if (metadata[key]) { | ||
isEmptyPackage = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (isEmptyPackage) { | ||
throw new Error('data not found in package'); | ||
} | ||
|
||
await dbManager.connect(); | ||
var session = await dbManager.startSession(); | ||
await jsonToDb(SteedosPackage, dbManager, session); | ||
|
||
resMsg.status = 0; | ||
resMsg.msg = "deploy success!"; | ||
|
||
} catch (err) { | ||
resMsg.status = -1; | ||
resMsg.msg = err.message; | ||
} finally { | ||
await dbManager.endSession(); | ||
await dbManager.close(); | ||
} | ||
|
||
deleteFolderRecursive(tempDir); | ||
|
||
return resMsg; | ||
} | ||
|
||
}, | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters