Compare commits
116 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14f987a49d | |||
| 074e163c95 | |||
| 29325f2165 | |||
| 21ca818ab6 | |||
| 6d7f5d26ee | |||
| 68e4e6ffea | |||
| eeb08342f6 | |||
| 64988aa95a | |||
| e4816e9447 | |||
| b1c92721be | |||
| d27946ed88 | |||
| adc5686033 | |||
| 5f9c91e5e7 | |||
| e5ccd05903 | |||
| 358687c8dd | |||
| 283c3fbb57 | |||
| 8edfaf6224 | |||
| ed511992ea | |||
| 8ebae697b1 | |||
| 93a0888de5 | |||
| c0c23e77ee | |||
| 684a1fa44b | |||
| fb87eb90ca | |||
| 7b22866929 | |||
| aa5db953a8 | |||
| 4e1021acb9 | |||
| 3d763a3e36 | |||
| ad0f54775b | |||
| 251dcfb750 | |||
| 62b60d02e4 | |||
| 82587d7506 | |||
| 51d69d5a97 | |||
| 9319fa131b | |||
| 10cd8c2d1b | |||
| a93d784d16 | |||
| 54bccd0253 | |||
| 363d8aac11 | |||
| f49750a70a | |||
| fc29545948 | |||
| 000722d2d1 | |||
| 9e9dd22bdf | |||
| a6ec77c523 | |||
| 1f1795eb6c | |||
| 373fbafd6c | |||
| e1200a47a1 | |||
| 667469dd50 | |||
| 83816f16d4 | |||
| 92fdfefa30 | |||
| d7bfc9d7c2 | |||
| a0e74c61ee | |||
| 293db99a2e | |||
| a7bea5288c | |||
| 6e05fda2e3 | |||
| 1826a8618b | |||
| 97a3176bd9 | |||
| 2cd467b431 | |||
| 1574883381 | |||
| 78f29fe34c | |||
| 6882cd320f | |||
| b74bbe083d | |||
| cef86f27c2 | |||
| 3b2114b95f | |||
| 3164add2c0 | |||
| 9b5d237928 | |||
| 54be774fe8 | |||
| 52a4dac990 | |||
| 9a3d9689fd | |||
| 46b6918031 | |||
| df09a4c92b | |||
| f4ac57c8f8 | |||
| 64c6b20a8f | |||
| 8a65f20142 | |||
| 632d65c057 | |||
| e013b9dd63 | |||
| 5605bcbe68 | |||
| 6a85c88fb7 | |||
| bc687cc2de | |||
| 6bb37fd48d | |||
| 4cbc3873f7 | |||
| 64a6698611 | |||
| 70a4f448e9 | |||
| ddd4524407 | |||
| 92a2fc8a26 | |||
| af999c8b33 | |||
| 5a1577db80 | |||
| f62c99c73a | |||
| ac8c52b75b | |||
| e240ff24b2 | |||
| 9fa0fd5322 | |||
| 567855b7e5 | |||
| 8613369885 | |||
| 88e5f0c155 | |||
| d7a3a06039 | |||
| 6a3c35e594 | |||
| a9f030e95f | |||
| 71f84cb25b | |||
| 13996acf5a | |||
| dd3328b96c | |||
| 47fd4d26b0 | |||
| 685e7d2f15 | |||
| edc3859ba7 | |||
| 9848de900b | |||
| b09d39f18f | |||
| 7283498e26 | |||
| 00c508fd78 | |||
| f02be97497 | |||
| 6845d78716 | |||
| 1c8c26ff25 | |||
| d4f9a6f5f4 | |||
| 7ddc9d8220 | |||
| a9114cc05f | |||
| 9cde625d0c | |||
| 9fa91fcd63 | |||
| 27a140df3d | |||
| 20a2b74e9f | |||
| 11e90e1685 |
@@ -23,6 +23,26 @@ createuser biopro -P --interactive
|
|||||||
|
|
||||||
### Run apiServer on device
|
### Run apiServer on device
|
||||||
|
|
||||||
|
##### Install node.js
|
||||||
|
```
|
||||||
|
sudo apt-get upgrade
|
||||||
|
sudo apt-get update
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
### setup_14.x can change to your version
|
||||||
|
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
|
||||||
|
### install node and npm
|
||||||
|
sudo apt-get install -y nodejs
|
||||||
|
```
|
||||||
|
|
||||||
|
##### (optional) if the installation of node.js fail
|
||||||
|
```
|
||||||
|
sudo apt update
|
||||||
|
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
|
||||||
|
sudo apt-get install -y nodejs
|
||||||
|
```
|
||||||
|
|
||||||
##### Clone project
|
##### Clone project
|
||||||
```
|
```
|
||||||
git clone https://gitlab.com/bioproscientific/bioproapiserver.git
|
git clone https://gitlab.com/bioproscientific/bioproapiserver.git
|
||||||
@@ -35,12 +55,9 @@ vim config.js
|
|||||||
```
|
```
|
||||||
change the code following as:
|
change the code following as:
|
||||||
```
|
```
|
||||||
/*
|
|
||||||
change apiserver port to postgres port, 54321 --> 5432 (default)
|
|
||||||
*/
|
|
||||||
export const pgDB = {
|
export const pgDB = {
|
||||||
host: '127.0.0.1', // 服务器地址
|
host: '127.0.0.1', // 服务器地址
|
||||||
port: 54321, // 数据库端口号 -----------------> 5432
|
port: 5432, // 数据库端口号
|
||||||
username: 'biopro', // 数据库用户名
|
username: 'biopro', // 数据库用户名
|
||||||
password: 'BioProControlBox', // 数据库密码
|
password: 'BioProControlBox', // 数据库密码
|
||||||
database: 'postgres' // 数据库名称
|
database: 'postgres' // 数据库名称
|
||||||
@@ -60,7 +77,8 @@ sudo vim /etc/rc.local
|
|||||||
```
|
```
|
||||||
add the code following as:
|
add the code following as:
|
||||||
```
|
```
|
||||||
nohup node /home/pi/bioproapiserver/dist/app.js > /home/pi/.api_server.out &
|
now=$(date +"%F_%T")
|
||||||
|
sudo -H -u pi nohup node /home/pi/bioproapiserver/dist/app.js > /home/pi/.api_server_$now.out &
|
||||||
```
|
```
|
||||||
|
|
||||||
### Localhost develop
|
### Localhost develop
|
||||||
@@ -79,4 +97,4 @@ npm run start
|
|||||||
```
|
```
|
||||||
|
|
||||||
##### References
|
##### References
|
||||||
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
|
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
|
||||||
|
|||||||
Generated
+13
@@ -2448,6 +2448,14 @@
|
|||||||
"integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==",
|
"integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"axios": {
|
||||||
|
"version": "0.24.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
|
||||||
|
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
|
||||||
|
"requires": {
|
||||||
|
"follow-redirects": "^1.14.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"babel-core": {
|
"babel-core": {
|
||||||
"version": "7.0.0-bridge.0",
|
"version": "7.0.0-bridge.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz",
|
||||||
@@ -4860,6 +4868,11 @@
|
|||||||
"readable-stream": "^2.3.6"
|
"readable-stream": "^2.3.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.14.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz",
|
||||||
|
"integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA=="
|
||||||
|
},
|
||||||
"for-in": {
|
"for-in": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"link:fix": "eslint --fix ."
|
"link:fix": "eslint --fix ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.24.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"koa": "^2.11.0",
|
"koa": "^2.11.0",
|
||||||
"koa-body": "^4.1.1",
|
"koa-body": "^4.1.1",
|
||||||
|
|||||||
+26
-26
@@ -1,39 +1,39 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
// 系统配置
|
// system config
|
||||||
export const System = {
|
export const System = {
|
||||||
API_server_type: 'http://', // API服务器协议类型,包含"http://"或"https://"
|
API_server_type: 'http://',
|
||||||
API_server_host: 'localhost', // API服务器暴露的域名地址,请勿添加"http://"
|
API_server_host: 'localhost',
|
||||||
API_server_port: '3000', // API服务器监听的端口号
|
API_server_port: '3000',
|
||||||
HTTP_server_type: 'http://', // HTTP服务器协议类型,包含"http://"或"https://"
|
HTTP_server_type: 'http://',
|
||||||
HTTP_server_host: 'www.XXX.com', // HTTP服务器地址,请勿添加"http://" (即前端调用使用的服务器地址,如果是APP请设置为 * )
|
HTTP_server_host: 'www.XXX.com', // HTTP server address(as client browser location,* if its app )
|
||||||
HTTP_server_port: '65534', // HTTP服务器端口号
|
HTTP_server_port: '65534',
|
||||||
System_country: 'zh-cn', // 所在国家的国家代码
|
System_country: 'zh-cn',
|
||||||
System_plugin_path: path.join(__dirname, './plugins'), // 插件路径
|
System_plugin_path: path.join(__dirname, './plugins'),
|
||||||
Session_Key: 'RESTfulAPI', // 生产环境务必随机设置一个值
|
Session_Key: 'RESTfulAPI',
|
||||||
db_type: 'mysql' // 数据库类型
|
db_type: 'mysql'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DB = {
|
export const DB = {
|
||||||
host: 'localhost', // 服务器地址
|
host: 'localhost',
|
||||||
port: 3306, // 数据库端口号
|
port: 3306,
|
||||||
username: 'admin', // 数据库用户名
|
username: 'admin',
|
||||||
password: 'admin888', // 数据库密码
|
password: 'admin888',
|
||||||
database: 'development', // 数据库名称
|
database: 'development',
|
||||||
prefix: 'api_' // 默认"api_"
|
prefix: 'api_'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pgDB = {
|
export const pgDB = {
|
||||||
host: '127.0.0.1', // 服务器地址
|
host: '127.0.0.1',
|
||||||
port: 54321, // 数据库端口号
|
port: 5432,
|
||||||
username: 'biopro', // 数据库用户名
|
username: 'biopro',
|
||||||
password: 'BioProControlBox', // 数据库密码
|
password: 'BioProControlBox',
|
||||||
database: 'postgres' // 数据库名称
|
database: 'postgres'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SendEmail = {
|
export const SendEmail = {
|
||||||
service: 'smtp.abcd.com', // SMTP服务提供商域名
|
service: 'smtp.abcd.com',
|
||||||
username: 'postmaster%40abcd.com', // 用户名/用户邮箱
|
username: 'postmaster%40abcd.com',
|
||||||
password: 'password', // 邮箱密码
|
password: 'password',
|
||||||
sender_address: '"XX平台 👥" <postmaster@abcd.com>'
|
sender_address: '<postmaster@abcd.com>'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
from scipy import signal
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# argv = _type, order, fs, f0, f1, f2
|
||||||
|
if len(sys.argv) < 7:
|
||||||
|
_type = 'highpass' # 'highpass', 'lowpass', 'bandstop', 'bandpass'
|
||||||
|
order = 20
|
||||||
|
fs = 1000
|
||||||
|
f0 = 48
|
||||||
|
f1 = 52
|
||||||
|
f2 = 25
|
||||||
|
# exit()
|
||||||
|
else:
|
||||||
|
_type = sys.argv[1] # 'highpass', 'lowpass', 'bandstop', 'bandpass'
|
||||||
|
order = int(sys.argv[2])
|
||||||
|
fs = float(sys.argv[3])
|
||||||
|
f0 = float(sys.argv[4])
|
||||||
|
f1 = float(sys.argv[5])
|
||||||
|
f2 = float(sys.argv[6])
|
||||||
|
|
||||||
|
# fs = 1000
|
||||||
|
|
||||||
|
if _type in ['bandstop', 'bandpass']:
|
||||||
|
sos = signal.butter(order, [f0/fs*2,f1/fs*2], _type, output='sos')
|
||||||
|
elif _type in ['highpass', 'lowpass']:
|
||||||
|
sos = signal.butter(order, f2/fs*2, _type, output='sos')
|
||||||
|
else:
|
||||||
|
b, a = signal.iirnotch(f2, order, fs)
|
||||||
|
sos = signal.tf2sos(b, a)
|
||||||
|
|
||||||
|
ret = ''
|
||||||
|
for s_list in sos:
|
||||||
|
for s in s_list:
|
||||||
|
ret += str(s) + ','
|
||||||
|
ret = ret[:-1]
|
||||||
|
ret += '/'
|
||||||
|
|
||||||
|
print(ret[:-2], end='')
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import RecordingDataMeta from '../../models/file/recording_data_meta'
|
||||||
|
import childProcess from 'child_process'
|
||||||
|
import path from 'path'
|
||||||
|
import { homedir } from 'os'
|
||||||
|
|
||||||
|
const recordingDataMeta = new RecordingDataMeta()
|
||||||
|
|
||||||
|
export const spikeDetect = async (ctx, next) => {
|
||||||
|
const request = ctx.request.body
|
||||||
|
ctx.req.setTimeout(0)
|
||||||
|
|
||||||
|
const controllerId = request.controller_id
|
||||||
|
const metaId = request.meta_id
|
||||||
|
const channel = request.channel
|
||||||
|
const cutOffFreq = request.cut_off_freq
|
||||||
|
const filterOrder = request.filter_order
|
||||||
|
const threshold = request.threshold
|
||||||
|
const waveForm = request.waveForm
|
||||||
|
const dataType = request.data_type
|
||||||
|
|
||||||
|
const result = await recordingDataMeta.getByID(metaId)
|
||||||
|
|
||||||
|
const channels = JSON.parse(result[0].channels)
|
||||||
|
const sampleRate = 8e5 / result[0].parameter_set.ADC_CLOCK / channels.length
|
||||||
|
const timeDuration = result[0].time_duration / 1e6
|
||||||
|
const rawData = JSON.stringify(result[0].raw_data[channel])
|
||||||
|
|
||||||
|
function getPromise () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.spawn('python3', [
|
||||||
|
path.join(homedir(), 'bioproanalysis', 'spike_detect', 'main.py'),
|
||||||
|
'controller_id=' + controllerId,
|
||||||
|
'meta_id=' + metaId,
|
||||||
|
'channel=' + channel,
|
||||||
|
'cut_off_freq=' + cutOffFreq,
|
||||||
|
'filter_order=' + filterOrder,
|
||||||
|
'threshold=' + threshold,
|
||||||
|
'waveform=' + waveForm,
|
||||||
|
'sample_rate=' + sampleRate,
|
||||||
|
'time_duration=' + timeDuration,
|
||||||
|
'data_type=' + dataType,
|
||||||
|
'raw_data=' + rawData
|
||||||
|
])
|
||||||
|
|
||||||
|
let totalString = ''
|
||||||
|
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
const dataString = data.toString()
|
||||||
|
totalString += dataString
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.stderr.on('data', (error) => {
|
||||||
|
reject(error)
|
||||||
|
console.error(`Error ${error}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
resolve(totalString)
|
||||||
|
console.log(`spike detect analysis process exited with code ${code}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret = await getPromise()
|
||||||
|
ctx.body = ret
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IIRFliter = async (ctx, next) => {
|
||||||
|
const request = ctx.request.body
|
||||||
|
ctx.req.setTimeout(0)
|
||||||
|
|
||||||
|
const type = request.type
|
||||||
|
const order = request.order
|
||||||
|
const fs = request.fs
|
||||||
|
const f0 = request.f0
|
||||||
|
const f1 = request.f1
|
||||||
|
const f2 = request.f2
|
||||||
|
|
||||||
|
function getPromise () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.spawn('python3', [
|
||||||
|
path.join(homedir(), 'bioproanalysis', 'filter', 'IIRFilter.py'),
|
||||||
|
type,
|
||||||
|
order,
|
||||||
|
fs,
|
||||||
|
f0,
|
||||||
|
f1,
|
||||||
|
f2
|
||||||
|
])
|
||||||
|
|
||||||
|
let totalString = ''
|
||||||
|
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
const dataString = data.toString()
|
||||||
|
totalString += dataString
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.stderr.on('data', (error) => {
|
||||||
|
reject(error)
|
||||||
|
console.error(`Error ${error}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
resolve(totalString)
|
||||||
|
console.log(`iir filter analysis process exited with code ${code}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const ret = await getPromise()
|
||||||
|
ctx.body = ret
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
+118
-11
@@ -1,17 +1,19 @@
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import childProcess from 'child_process'
|
||||||
|
import { readFile, writeFile } from 'fs/promises'
|
||||||
|
import { homedir } from 'os'
|
||||||
|
const axios = require('axios')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
const publicKey = fs.readFileSync(path.join(__dirname, '../../publicKey.pub'))
|
const publicKey = fs.readFileSync(path.join(__dirname, '../../publicKey.pub'))
|
||||||
|
const licenseUrl = 'http://52.194.17.114:3000'
|
||||||
// 用户登录的时候返回token
|
const apiFuncName = 'apiServer'
|
||||||
// let token = jwt.sign({
|
|
||||||
// userInfo: userInfo // 你要保存到token的数据
|
|
||||||
// }, publicKey, { expiresIn: '7d' })
|
|
||||||
|
|
||||||
export const getCookie = (ctx, next) => {
|
export const getCookie = (ctx, next) => {
|
||||||
const token = jwt.sign({
|
const token = jwt.sign({
|
||||||
userInfo: 'tommy' // 你要保存到token的数据
|
userInfo: 'tommy'
|
||||||
}, publicKey, { expiresIn: '7d' })
|
}, publicKey, { expiresIn: '7d' })
|
||||||
|
|
||||||
ctx.body = token
|
ctx.body = token
|
||||||
@@ -22,9 +24,6 @@ export const getCookie = (ctx, next) => {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查授权是否合法
|
|
||||||
*/
|
|
||||||
export const CheckAuth = (ctx, next) => {
|
export const CheckAuth = (ctx, next) => {
|
||||||
const token = ctx.request.header.authorization
|
const token = ctx.request.header.authorization
|
||||||
try {
|
try {
|
||||||
@@ -38,7 +37,7 @@ export const CheckAuth = (ctx, next) => {
|
|||||||
return {
|
return {
|
||||||
status: 403,
|
status: 403,
|
||||||
result: {
|
result: {
|
||||||
errInfo: '没有授权'
|
errInfo: 'no auth'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,7 @@ export const CheckAuth = (ctx, next) => {
|
|||||||
return {
|
return {
|
||||||
status: 503,
|
status: 503,
|
||||||
result: {
|
result: {
|
||||||
errInfo: '解密错误'
|
errInfo: 'decode fail'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,3 +59,111 @@ export const Post = (ctx, next) => {
|
|||||||
return CheckAuth(ctx).then(result => { ctx.body = result; next() })
|
return CheckAuth(ctx).then(result => { ctx.body = result; next() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateLicense = async (ctx, next) => {
|
||||||
|
function wgetEXEC (url, name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.exec('wget ' + url + name + ' -O ' + homedir + '/checkToken')
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
})
|
||||||
|
// subprocess.stderr.on('data', (error) => {
|
||||||
|
// // reject(error)
|
||||||
|
// console.error(`Error ${error}`)
|
||||||
|
// })
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
resolve(true)
|
||||||
|
console.log(`wgetEXE process exited with code ${code}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function chmodEXEC () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.exec('chmod 777 ' + homedir + '/checkToken')
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
})
|
||||||
|
// subprocess.stderr.on('data', (error) => {
|
||||||
|
// // reject(error)
|
||||||
|
// console.error(`Error ${error}`)
|
||||||
|
// })
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
resolve(true)
|
||||||
|
console.log(`wgetEXE process exited with code ${code}`)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const mac = await readFile('/sys/class/net/eth0/address')
|
||||||
|
const ret = await axios.post(licenseUrl + '/api/controller/token', {
|
||||||
|
mac_controller: mac.toString().substr(0, 17)
|
||||||
|
})
|
||||||
|
switch (ret.status) {
|
||||||
|
case 200:
|
||||||
|
await writeFile(homedir + '/token.txt', ret.data.token)
|
||||||
|
await writeFile(homedir + '/cute.txt', ret.data.cute)
|
||||||
|
await wgetEXEC(licenseUrl + '/assets/exec/', ret.data.name)
|
||||||
|
await chmodEXEC()
|
||||||
|
ctx.status = 200
|
||||||
|
break
|
||||||
|
case 201:
|
||||||
|
await writeFile(homedir + '/token.txt', ret.data.token)
|
||||||
|
await writeFile(homedir + '/cute.txt', ret.data.cute)
|
||||||
|
await wgetEXEC(licenseUrl + '/assets/exec/', ret.data.name)
|
||||||
|
await chmodEXEC()
|
||||||
|
ctx.status = 200
|
||||||
|
break
|
||||||
|
case 202:
|
||||||
|
await writeFile(homedir + '/token.txt', ret.data.token)
|
||||||
|
await writeFile(homedir + '/cute.txt', ret.data.cute)
|
||||||
|
await wgetEXEC(licenseUrl + '/assets/exec/', ret.data.name)
|
||||||
|
await chmodEXEC()
|
||||||
|
ctx.status = 202
|
||||||
|
break
|
||||||
|
case 203:
|
||||||
|
ctx.status = 203
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
ctx.status = 305
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(ret.status, ret.data)
|
||||||
|
// 200 success; 201 doesnt need to update; 202 no license; 203 info fail
|
||||||
|
|
||||||
|
ctx.body = ''
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const checkLicense = async (ctx, next) => {
|
||||||
|
const mac = await readFile('/sys/class/net/eth0/address')
|
||||||
|
ctx.body = await runCheckToken(mac.toString().substr(0, 17))
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const runCheckToken = async (mac) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const tokenPath = homedir + '/token.txt'
|
||||||
|
const cutePath = homedir + '/cute.txt'
|
||||||
|
const subprocess = childProcess.exec(homedir + '/./checkToken ' + apiFuncName + ' ' + tokenPath + ' ' + cutePath)
|
||||||
|
let _data = ''
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
_data += data
|
||||||
|
})
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
const pass = crypto.createHmac('sha256', mac).update(apiFuncName + 'pass').digest('hex')
|
||||||
|
const outdated = crypto.createHmac('sha256', mac).update(apiFuncName + 'outdated').digest('hex')
|
||||||
|
switch (_data) {
|
||||||
|
case pass:
|
||||||
|
resolve('pass')
|
||||||
|
break
|
||||||
|
case outdated:
|
||||||
|
resolve('outdated')
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
resolve('fail')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import TaskModal from '../../models/controller/task'
|
||||||
|
|
||||||
|
const task = new TaskModal()
|
||||||
|
|
||||||
|
export const create = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const result = await task.create(data)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const update = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const result = await task.update(data)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByID = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await task.updateByID(data, id)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByAttr = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await task.updateByAttr(data, attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearDeleted = async (ctx, next) => {
|
||||||
|
const result = await task.clearDeleted()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByID = async (ctx, next) => {
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await task.getByID(id)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByAttr = async (ctx, next) => {
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await task.getByAttr(attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAll = async (ctx, next) => {
|
||||||
|
const result = await task.getAll()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
@@ -20,7 +20,8 @@ export const update = async (ctx, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const clearDeleted = async (ctx, next) => {
|
export const clearDeleted = async (ctx, next) => {
|
||||||
const result = await collection.clearDeleted()
|
const controllerID = ctx.params.controller_id
|
||||||
|
const result = await collection.clearDeleted(controllerID)
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
|
|
||||||
next()
|
next()
|
||||||
@@ -36,7 +37,8 @@ export const getByID = async (ctx, next) => {
|
|||||||
|
|
||||||
export const getByName = async (ctx, next) => {
|
export const getByName = async (ctx, next) => {
|
||||||
const name = ctx.params.name
|
const name = ctx.params.name
|
||||||
const result = await collection.getByName(name)
|
const controllerID = ctx.params.controller_id
|
||||||
|
const result = await collection.getByName(name, controllerID)
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
|
|
||||||
next()
|
next()
|
||||||
@@ -62,7 +64,8 @@ export const getByParentName = async (ctx, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getAll = async (ctx, next) => {
|
export const getAll = async (ctx, next) => {
|
||||||
const result = await collection.getAll()
|
const controllerID = ctx.params.controller_id
|
||||||
|
const result = await collection.getAll(controllerID)
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
|
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const recordingDataMeta = new RecordingDataMeta()
|
|||||||
export const create = async (ctx, next) => {
|
export const create = async (ctx, next) => {
|
||||||
const data = ctx.request.body
|
const data = ctx.request.body
|
||||||
console.log(auth.CheckAuth(ctx))
|
console.log(auth.CheckAuth(ctx))
|
||||||
|
// console.log(data)
|
||||||
// console.log(ctx.request.header.authorization)
|
// console.log(ctx.request.header.authorization)
|
||||||
const result = await recordingDataMeta.create(data)
|
const result = await recordingDataMeta.create(data)
|
||||||
// console.log(result)
|
// console.log(result)
|
||||||
@@ -47,6 +48,40 @@ export const getByParent = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getCountByParent = async (ctx, next) => {
|
||||||
|
const type = ctx.params.type
|
||||||
|
const parent = ctx.params.parent
|
||||||
|
const result = await recordingDataMeta.getCountByParent(type, parent)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByParentWithLimit = async (ctx, next) => {
|
||||||
|
const type = ctx.params.type
|
||||||
|
const parent = ctx.params.parent
|
||||||
|
const limit = ctx.params.limit
|
||||||
|
const offset = ctx.params.offset
|
||||||
|
const order = ctx.params.order
|
||||||
|
const result = await recordingDataMeta.getByParentWithLimit(type, parent, limit, offset, order)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByAttrsParentWithLimit = async (ctx, next) => {
|
||||||
|
const type = ctx.params.type
|
||||||
|
const parent = ctx.params.parent
|
||||||
|
const limit = ctx.params.limit
|
||||||
|
const offset = ctx.params.offset
|
||||||
|
const order = ctx.params.order
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const result = await recordingDataMeta.getByAttrsParentWithLimit(type, parent, limit, offset, order, attr)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const getByUUID = async (ctx, next) => {
|
export const getByUUID = async (ctx, next) => {
|
||||||
const uuid = ctx.params.uuid
|
const uuid = ctx.params.uuid
|
||||||
const result = await recordingDataMeta.getByUUID(uuid)
|
const result = await recordingDataMeta.getByUUID(uuid)
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ export const update = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateByIDs = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataMini.updateByIDs(data, id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
// export const get = async (ctx, next) => {
|
// export const get = async (ctx, next) => {
|
||||||
// const index = ctx.params.channel
|
// const index = ctx.params.channel
|
||||||
// const id = ctx.params.id
|
// const id = ctx.params.id
|
||||||
@@ -51,6 +61,15 @@ export const getByID = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getByIDs = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataMini.getByIDs(id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const getMeanDataByID = async (ctx, next) => {
|
export const getMeanDataByID = async (ctx, next) => {
|
||||||
const index = ctx.params.channel
|
const index = ctx.params.channel
|
||||||
const id = ctx.params.id
|
const id = ctx.params.id
|
||||||
|
|||||||
@@ -25,6 +25,26 @@ export const update = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateSdData = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataRaw.updateSdData(data, id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByIDs = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataRaw.updateByIDs(data, id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const clearDeleted = async (ctx, next) => {
|
export const clearDeleted = async (ctx, next) => {
|
||||||
const index = ctx.params.channel
|
const index = ctx.params.channel
|
||||||
const result = await recordingDataRaw.clearDeleted(index)
|
const result = await recordingDataRaw.clearDeleted(index)
|
||||||
@@ -42,6 +62,15 @@ export const getByID = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getByIDs = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataRaw.getByIDs(id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const getDataByID = async (ctx, next) => {
|
export const getDataByID = async (ctx, next) => {
|
||||||
const index = ctx.params.channel
|
const index = ctx.params.channel
|
||||||
const id = ctx.params.id
|
const id = ctx.params.id
|
||||||
@@ -51,6 +80,15 @@ export const getDataByID = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getSdDataByID = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await recordingDataRaw.getSdDataByID(id, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const getByParent = async (ctx, next) => {
|
export const getByParent = async (ctx, next) => {
|
||||||
const index = ctx.params.channel
|
const index = ctx.params.channel
|
||||||
const parent = ctx.params.parent
|
const parent = ctx.params.parent
|
||||||
@@ -70,6 +108,16 @@ export const getAttrByID = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getAttrByIDs = async (ctx, next) => {
|
||||||
|
const index = ctx.params.channel
|
||||||
|
const id = ctx.params.id
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const result = await recordingDataRaw.getByAttrIDs(id, attr, index)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
export const getAttrByParent = async (ctx, next) => {
|
export const getAttrByParent = async (ctx, next) => {
|
||||||
const index = ctx.params.channel
|
const index = ctx.params.channel
|
||||||
const parent = ctx.params.parent
|
const parent = ctx.params.parent
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
import RecordingDataMeta from '../../../models/file/recording_data_meta'
|
||||||
|
import Controller from '../../../models/product/controller'
|
||||||
|
import childProcess from 'child_process'
|
||||||
|
import path from 'path'
|
||||||
|
import { homedir } from 'os'
|
||||||
|
|
||||||
|
const recordingDataMeta = new RecordingDataMeta()
|
||||||
|
const controller = new Controller()
|
||||||
|
|
||||||
|
const sdPath = [homedir(), 'bioproanalysis', 'sdcard']
|
||||||
|
const sdGetPath = [...sdPath, 'neuLiveSD_C', 'sd_list']
|
||||||
|
const sdDeletePath = [...sdPath, 'neuLiveSD_C', 'sd_remove']
|
||||||
|
const sdUploadPath = [...sdPath, 'sd_download.py']
|
||||||
|
|
||||||
|
const getParameter = async (metaID, parameterName) => {
|
||||||
|
const ret = await recordingDataMeta.getByID(metaID)
|
||||||
|
return ret[0].parameter_set[parameterName]
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPath = async (uuid) => {
|
||||||
|
return getPathByUuid(uuid, getUuidPathArray(await getUuidPathStringPromise()))
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPathByUuid = (uuid, uuidPathArray) => {
|
||||||
|
for (const uuidPath of uuidPathArray) {
|
||||||
|
if (uuidPath[0] === uuid) {
|
||||||
|
return uuidPath[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// [uuid1, uuid2, uuid3...]
|
||||||
|
const getUuidList = (uuidPathString) => {
|
||||||
|
return uuidPathString.split('\n').map(val => val.split(' ')[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// [[uuid1, path1], [uuid2, path2], [uuid3, path3]...]
|
||||||
|
const getUuidPathArray = (uuidPathString) => {
|
||||||
|
return uuidPathString.split('\n').map(val => val.split(' '))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'uuid1 path1\n uuid2 path2\n uuid3 path3\n....'
|
||||||
|
const getUuidPathStringPromise = async () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.spawn(path.join(...sdGetPath))
|
||||||
|
|
||||||
|
let dataString = ''
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
dataString += data.toString()
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.stderr.on('data', (error) => {
|
||||||
|
console.error(`Error ${error}`)
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
console.log(`sdcard get process exited with code ${code}`)
|
||||||
|
resolve(dataString)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function uploadPromise (uuidPath, uuid, ampGain) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.spawn('python3', [
|
||||||
|
path.join(...sdUploadPath),
|
||||||
|
uuidPath,
|
||||||
|
uuid,
|
||||||
|
ampGain
|
||||||
|
])
|
||||||
|
|
||||||
|
let dataString = ''
|
||||||
|
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
dataString += data.toString()
|
||||||
|
console.log('upload', dataString)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.stderr.on('data', (error) => {
|
||||||
|
reject(error)
|
||||||
|
console.error(`Error ${error}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
console.log(`sd card upload process exited with code ${code}`)
|
||||||
|
resolve(dataString)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePromise (uuidPath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subprocess = childProcess.spawn(
|
||||||
|
path.join(...sdDeletePath),
|
||||||
|
[uuidPath, 120]
|
||||||
|
)
|
||||||
|
let dataString = ''
|
||||||
|
subprocess.stdout.on('data', async (data) => {
|
||||||
|
dataString += data.toString()
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.stderr.on('data', (error) => {
|
||||||
|
console.error(`Error ${error}`)
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
subprocess.on('close', (code) => {
|
||||||
|
console.log(`grep process exited with code ${code}`)
|
||||||
|
resolve(dataString)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const exist = async (ctx, next) => {
|
||||||
|
const request = ctx.request.body
|
||||||
|
// const controllerID = request.controllerID
|
||||||
|
const uuid = request.uuid
|
||||||
|
const path = await getPath(uuid)
|
||||||
|
let result
|
||||||
|
(path !== undefined) ? result = true : result = false
|
||||||
|
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const uploadThenDelete = async (ctx, next) => {
|
||||||
|
const request = ctx.request.body
|
||||||
|
const controllerID = request.controllerID
|
||||||
|
const metaID = request.metaID
|
||||||
|
const uuid = request.uuid
|
||||||
|
const uuidPath = await getPath(uuid)
|
||||||
|
const ampGain = await getParameter(metaID, 'AMP_GAIN')
|
||||||
|
|
||||||
|
// timeout defualt 120s to no-limit
|
||||||
|
ctx.req.setTimeout(0)
|
||||||
|
|
||||||
|
// controller column sd_uploading update
|
||||||
|
await controller.update({
|
||||||
|
sd_uploading: true
|
||||||
|
}, controllerID)
|
||||||
|
|
||||||
|
const uploadResult = await uploadPromise(uuidPath, uuid, ampGain)
|
||||||
|
|
||||||
|
if (uploadResult === 'true') {
|
||||||
|
// meta sd_card_uploaded true
|
||||||
|
await recordingDataMeta.update({
|
||||||
|
sd_data_uploaded: true
|
||||||
|
}, metaID)
|
||||||
|
await deletePromise(uuidPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// controller column sd_uploading close
|
||||||
|
await controller.update({
|
||||||
|
sd_uploading: false
|
||||||
|
}, controllerID)
|
||||||
|
|
||||||
|
ctx.body = uploadResult
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getFileList = async (ctx, next) => {
|
||||||
|
const result = await getUuidPathStringPromise()
|
||||||
|
const uuidList = getUuidList(result)
|
||||||
|
|
||||||
|
ctx.body = uuidList
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
// export const deleted = async (ctx, next) => {
|
||||||
|
// const request = ctx.request.body
|
||||||
|
// const controllerID = request.controllerID
|
||||||
|
// const uuid = request.uuid
|
||||||
|
// const uuidPath = await getPath(uuid)
|
||||||
|
|
||||||
|
// // timeout defualt 120s to no-limit
|
||||||
|
// ctx.req.setTimeout(0)
|
||||||
|
|
||||||
|
// // controller column sd_uploading update
|
||||||
|
// await controller.update({
|
||||||
|
// sd_uploading: true
|
||||||
|
// }, controllerID)
|
||||||
|
|
||||||
|
// const result = await deletePromise(uuidPath)
|
||||||
|
|
||||||
|
// // controller column sd_uploading close
|
||||||
|
// await controller.update({
|
||||||
|
// sd_uploading: false
|
||||||
|
// }, controllerID)
|
||||||
|
|
||||||
|
// ctx.body = result
|
||||||
|
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import RecordingMeta from '../../../models/file/bps_recording_meta'
|
||||||
|
import TriggerRaw from '../../../models/file/bps_trigger_raw'
|
||||||
|
|
||||||
|
const recordingMeta = new RecordingMeta()
|
||||||
|
const triggerRaw = new TriggerRaw()
|
||||||
|
|
||||||
|
export const getMetaByUUID = async (ctx, next) => {
|
||||||
|
const uuid = ctx.params.uuid
|
||||||
|
const result = await recordingMeta.getMetaByUUID(uuid)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMetaAll = async (ctx, next) => {
|
||||||
|
const result = await recordingMeta.getMetaAll()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getTriggerRawByUUID = async (ctx, next) => {
|
||||||
|
const parent_uuid = ctx.params.parent_uuid
|
||||||
|
const result = await triggerRaw.getDataByUUID(parent_uuid)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
@@ -1,17 +1,29 @@
|
|||||||
import upload from './upload'
|
import upload from './upload'
|
||||||
import * as api from './api'
|
import * as api from './api'
|
||||||
import * as auth from './auth'
|
import * as auth from './auth'
|
||||||
|
import * as controller from './product/controller'
|
||||||
|
import * as device from './product/device'
|
||||||
import * as collection from './file/collection'
|
import * as collection from './file/collection'
|
||||||
|
import * as task from './controller/task'
|
||||||
import * as recordingDataMeta from './file/recording_data_meta'
|
import * as recordingDataMeta from './file/recording_data_meta'
|
||||||
import * as recordingDataRaw from './file/recording_data_raw'
|
import * as recordingDataRaw from './file/recording_data_raw'
|
||||||
import * as recordingDataMini from './file/recording_data_mini'
|
import * as recordingDataMini from './file/recording_data_mini'
|
||||||
|
import * as analysis from './analysis'
|
||||||
|
import * as sdCard from './file/sd_card'
|
||||||
|
import * as trigger from './file/trigger'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
upload,
|
upload,
|
||||||
api,
|
api,
|
||||||
auth,
|
auth,
|
||||||
|
controller,
|
||||||
|
device,
|
||||||
collection,
|
collection,
|
||||||
|
task,
|
||||||
recordingDataMeta,
|
recordingDataMeta,
|
||||||
recordingDataRaw,
|
recordingDataRaw,
|
||||||
recordingDataMini
|
recordingDataMini,
|
||||||
|
analysis,
|
||||||
|
sdCard,
|
||||||
|
trigger,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import ControllerModal from '../../models/product/controller'
|
||||||
|
|
||||||
|
const controller = new ControllerModal()
|
||||||
|
|
||||||
|
export const create = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const result = await controller.create(data)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const update = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await controller.update(data, id)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByAttr = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await controller.updateByAttr(data, attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearDeleted = async (ctx, next) => {
|
||||||
|
const result = await controller.clearDeleted()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByName = async (ctx, next) => {
|
||||||
|
const name = ctx.params.name
|
||||||
|
const result = await controller.getByName(name)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByMac = async (ctx, next) => {
|
||||||
|
const mac = ctx.params.mac
|
||||||
|
const result = await controller.getByMac(mac)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByMqttId = async (ctx, next) => {
|
||||||
|
const mqttId = ctx.params.mqtt_id
|
||||||
|
const result = await controller.getByMqttId(mqttId)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByAttr = async (ctx, next) => {
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await controller.getByAttr(attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAll = async (ctx, next) => {
|
||||||
|
const result = await controller.getAll()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
// export const createTest = async (ctx, next) => {
|
||||||
|
// const data = {
|
||||||
|
// name: 'test',
|
||||||
|
// parent: -1,
|
||||||
|
// size: 0
|
||||||
|
// }
|
||||||
|
// const result = await controller.create(data)
|
||||||
|
// ctx.body = result
|
||||||
|
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export const updateTest = async (ctx, next) => {
|
||||||
|
// const data = {
|
||||||
|
// name: 'test121',
|
||||||
|
// parent: -1232,
|
||||||
|
// size: 1243
|
||||||
|
// }
|
||||||
|
// const id = 2
|
||||||
|
// const result = await controller.update(data, id)
|
||||||
|
// ctx.body = result
|
||||||
|
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import DeviceModal from '../../models/product/device'
|
||||||
|
|
||||||
|
const device = new DeviceModal()
|
||||||
|
|
||||||
|
export const create = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const result = await device.create(data)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const update = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const id = ctx.params.id
|
||||||
|
const result = await device.update(data, id)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByMac = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const mac = ctx.params.mac
|
||||||
|
const result = await device.updateByMac(data, mac)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateByAttr = async (ctx, next) => {
|
||||||
|
const data = ctx.request.body
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await device.updateByAttr(data, attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearDeleted = async (ctx, next) => {
|
||||||
|
const result = await device.clearDeleted()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByMac = async (ctx, next) => {
|
||||||
|
const mac = ctx.params.mac
|
||||||
|
const result = await device.getByMac(mac)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getByAttr = async (ctx, next) => {
|
||||||
|
const attr = ctx.params.attr
|
||||||
|
const value = ctx.params.value
|
||||||
|
const result = await device.getByAttr(attr, value)
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAll = async (ctx, next) => {
|
||||||
|
const result = await device.getAll()
|
||||||
|
ctx.body = result
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
// export const createTest = async (ctx, next) => {
|
||||||
|
// const data = {
|
||||||
|
// name: 'test',
|
||||||
|
// parent: -1,
|
||||||
|
// size: 0
|
||||||
|
// }
|
||||||
|
// const result = await device.create(data)
|
||||||
|
// ctx.body = result
|
||||||
|
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export const updateTest = async (ctx, next) => {
|
||||||
|
// const data = {
|
||||||
|
// name: 'test121',
|
||||||
|
// parent: -1232,
|
||||||
|
// size: 1243
|
||||||
|
// }
|
||||||
|
// const id = 2
|
||||||
|
// const result = await device.update(data, id)
|
||||||
|
// ctx.body = result
|
||||||
|
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
+7
-2
@@ -23,12 +23,15 @@ db.Sequelize = Sequelize
|
|||||||
db.sequelize = sequelize
|
db.sequelize = sequelize
|
||||||
|
|
||||||
db.tutorials = require('./schema/tutirial.model')(sequelize, Sequelize)
|
db.tutorials = require('./schema/tutirial.model')(sequelize, Sequelize)
|
||||||
|
db.controllers = require('./schema/controller.model')(sequelize, Sequelize)
|
||||||
|
db.tasks = require('./schema/task.model')(sequelize, Sequelize)
|
||||||
|
db.devices = require('./schema/device.model')(sequelize, Sequelize)
|
||||||
db.collections = require('./schema/collection.model')(sequelize, Sequelize)
|
db.collections = require('./schema/collection.model')(sequelize, Sequelize)
|
||||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||||
for (let i = 0; i < 32; i++) {
|
for (let i = 0; i < 64; i++) {
|
||||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||||
}
|
}
|
||||||
for (let i = 0; i < 32; i++) {
|
for (let i = 0; i < 64; i++) {
|
||||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||||
}
|
}
|
||||||
for (let i = 256; i < 288; i++) {
|
for (let i = 256; i < 288; i++) {
|
||||||
@@ -37,6 +40,8 @@ for (let i = 256; i < 288; i++) {
|
|||||||
for (let i = 256; i < 288; i++) {
|
for (let i = 256; i < 288; i++) {
|
||||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||||
}
|
}
|
||||||
|
db.recording_meta = require('./schema/bps_recording_meta.model')(sequelize, Sequelize)
|
||||||
|
db.trigger_raw = require('./schema/bps_trigger_raw.model')(sequelize, Sequelize)
|
||||||
|
|
||||||
db.sequelize.sync()
|
db.sequelize.sync()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
|
||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const RecordingMeta = sequelize.define('bps_recording_meta', {
|
||||||
|
uuid: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '',
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
folder_id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
task_uuid: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
device: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
time_duration: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '0'
|
||||||
|
},
|
||||||
|
start_time: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
end_time: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
tag: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
parameter_set: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
create_date: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return RecordingMeta
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const TriigerDataRaw = sequelize.define('bps_trigger_raw', {
|
||||||
|
channel: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
parent_uuid: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
start_time: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
end_time: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
freezeTableName: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return TriigerDataRaw
|
||||||
|
}
|
||||||
@@ -7,6 +7,10 @@ module.exports = (sequelize, Sequelize) => {
|
|||||||
type: Sequelize.JSONB,
|
type: Sequelize.JSONB,
|
||||||
defaultValue: {}
|
defaultValue: {}
|
||||||
},
|
},
|
||||||
|
controller_id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
size: {
|
size: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
defaultValue: -1
|
defaultValue: -1
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const Controller = sequelize.define('controller', {
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
mac_address: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
ip_address: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
wifi_name: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
wifi_password: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
mqtt_id: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
mqtt_address: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
api_mqtt_address: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
root: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
// group/user: {
|
||||||
|
// admin: [id...],
|
||||||
|
// normal: [id...],
|
||||||
|
// guest: [id...]
|
||||||
|
// }
|
||||||
|
group_auth: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
user_auth: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
device: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
device_scanned: {
|
||||||
|
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||||
|
defaultValue: []
|
||||||
|
},
|
||||||
|
device_connected: {
|
||||||
|
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||||
|
defaultValue: []
|
||||||
|
},
|
||||||
|
// project/task: {
|
||||||
|
// running: [id...],
|
||||||
|
// library: [id...]
|
||||||
|
// }
|
||||||
|
project: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
task: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
// task: {
|
||||||
|
// type: Sequelize.JSONB,
|
||||||
|
// defaultValue: {
|
||||||
|
// running: [],
|
||||||
|
// library: []
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
software_version: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
sd_uploading: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return Controller
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const Device = sequelize.define('device', {
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
mac_address: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
serial_number: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
library: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
library_version: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
device_version: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
battery: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: 0
|
||||||
|
},
|
||||||
|
temperature: {
|
||||||
|
type: Sequelize.DOUBLE,
|
||||||
|
defaultValue: 0
|
||||||
|
},
|
||||||
|
auto_connect: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: true
|
||||||
|
},
|
||||||
|
connect_priority: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: 0
|
||||||
|
},
|
||||||
|
connect_time: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
defaultValue: 0
|
||||||
|
},
|
||||||
|
connect_status: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: 'idle'
|
||||||
|
},
|
||||||
|
connect_id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
parameter_set: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
running: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
calibration: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
user_auth: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return Device
|
||||||
|
}
|
||||||
@@ -22,12 +22,16 @@ module.exports = (sequelize, Sequelize) => {
|
|||||||
defaultValue: ''
|
defaultValue: ''
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
|
},
|
||||||
|
start_time_abs: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: '0'
|
||||||
},
|
},
|
||||||
time_duration: {
|
time_duration: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: 0
|
defaultValue: '0'
|
||||||
},
|
},
|
||||||
configuration: {
|
configuration: {
|
||||||
type: Sequelize.JSONB,
|
type: Sequelize.JSONB,
|
||||||
@@ -73,13 +77,25 @@ module.exports = (sequelize, Sequelize) => {
|
|||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT,
|
||||||
defaultValue: ''
|
defaultValue: ''
|
||||||
},
|
},
|
||||||
|
sd_data_record: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: true
|
||||||
|
},
|
||||||
|
sd_data_uploaded: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
deleted: {
|
deleted: {
|
||||||
type: Sequelize.BOOLEAN,
|
type: Sequelize.BOOLEAN,
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
},
|
},
|
||||||
user_auth: {
|
user_auth: {
|
||||||
type: Sequelize.JSONB,
|
type: Sequelize.JSONB,
|
||||||
defaultValue: {}
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
},
|
},
|
||||||
created_at: {
|
created_at: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
|||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
@@ -36,12 +36,12 @@ module.exports = (sequelize, Sequelize, i) => {
|
|||||||
defaultValue: -1
|
defaultValue: -1
|
||||||
},
|
},
|
||||||
start_time: {
|
start_time: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
end_time: {
|
end_time: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
data_random: {
|
data_random: {
|
||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
|||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
@@ -32,17 +32,21 @@ module.exports = (sequelize, Sequelize, i) => {
|
|||||||
defaultValue: -1
|
defaultValue: -1
|
||||||
},
|
},
|
||||||
start_time: {
|
start_time: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
end_time: {
|
end_time: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
defaultValue: -1
|
defaultValue: '-1'
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT,
|
||||||
defaultValue: ''
|
defaultValue: ''
|
||||||
},
|
},
|
||||||
|
sd_data: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
compressed: {
|
compressed: {
|
||||||
type: Sequelize.BOOLEAN,
|
type: Sequelize.BOOLEAN,
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const Scheduler = sequelize.define('scheduler', {
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
script: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return Scheduler
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const Task = sequelize.define('task', {
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
describe: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
device_config: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
chart_config: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
formula_config: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
controller_id: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
defaultValue: -1
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return Task
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const User = sequelize.define('user', {
|
||||||
|
account: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
paword: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
mail: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
defaultValue: ''
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {}
|
||||||
|
},
|
||||||
|
devices_list: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
controller_list: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
collection_list: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
meta_list: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {
|
||||||
|
owner: [],
|
||||||
|
maintainer: [],
|
||||||
|
guest: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleted: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return User
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
const db = require('../../db/database')
|
||||||
|
|
||||||
|
// const Op = db.Sequelize.Op
|
||||||
|
|
||||||
|
class TaskModel {
|
||||||
|
async create (req) {
|
||||||
|
console.log(req)
|
||||||
|
return db.tasks.create(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update (req) {
|
||||||
|
const ret = await db.tasks.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByID (req, id) {
|
||||||
|
const ret = await db.tasks.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByAttr (req, attr, value) {
|
||||||
|
const whereObj = {}
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
|
||||||
|
const ret = await db.tasks.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearDeleted () {
|
||||||
|
const ret = await db.tasks.delete(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByID (id) {
|
||||||
|
const ret = await db.tasks.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByName (name) {
|
||||||
|
const ret = await db.tasks.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByAttr (attr, value) {
|
||||||
|
const whereObj = {}
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
|
||||||
|
const ret = await db.tasks.findAll(
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAll () {
|
||||||
|
const ret = await db.tasks.findAll()
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TaskModel
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
const db = require('../../db/database')
|
||||||
|
|
||||||
|
const Op = db.Sequelize.Op
|
||||||
|
|
||||||
|
class RecordingMeta {
|
||||||
|
async getMetaByUUID (uuid) {
|
||||||
|
const ret = await db.recording_meta.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
uuid: uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getMetaAll () {
|
||||||
|
const ret = await db.recording_meta.findAll({
|
||||||
|
order: [
|
||||||
|
['start_time', 'DESC']
|
||||||
|
]
|
||||||
|
})
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RecordingMeta
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
const db = require('../../db/database')
|
||||||
|
const { Transform } = require("stream")
|
||||||
|
|
||||||
|
class TriggerRaw {
|
||||||
|
async getDataByUUID (parent_uuid) {
|
||||||
|
const ret = await db.trigger_raw.findAllWithStream(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
parent_uuid: parent_uuid
|
||||||
|
},
|
||||||
|
attributes: [
|
||||||
|
'data'
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const transformer = new Transform({
|
||||||
|
transform(chunk, encoding, callback) {
|
||||||
|
const chunkDataStr = chunk.toString('utf8')
|
||||||
|
// replace: ref https://dmitripavlutin.com/replace-all-string-occurrences-javascript/#2-replace-with-a-global-regular-expression
|
||||||
|
// slice: remove last ','
|
||||||
|
const transformDataArr = JSON.parse(chunkDataStr)[0].data.replace(/[@#$]/g, '').slice(0, -1).split(',')
|
||||||
|
const step = 3
|
||||||
|
let transformData = ''
|
||||||
|
for (let startPos = 0; startPos < transformDataArr.length; startPos += step) {
|
||||||
|
// array chunking algo. comparison: https://www.better.dev/javascript-algorithms-array-chunking
|
||||||
|
transformData += transformDataArr.slice(startPos, startPos + step).join() + '\n' // join: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/join
|
||||||
|
}
|
||||||
|
callback(null, transformData)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return ret.pipe(transformer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TriggerRaw
|
||||||
@@ -4,11 +4,7 @@ const Op = db.Sequelize.Op
|
|||||||
|
|
||||||
class CollectionModel {
|
class CollectionModel {
|
||||||
async create (req) {
|
async create (req) {
|
||||||
return db.collections.create({
|
return db.collections.create(req)
|
||||||
name: req.name,
|
|
||||||
parent: req.parent,
|
|
||||||
size: req.size
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async update (req, id) {
|
async update (req, id) {
|
||||||
@@ -23,14 +19,26 @@ class CollectionModel {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearDeleted () {
|
async clearDeleted (controllerID) {
|
||||||
const ret = await db.collections.delete(
|
let ret
|
||||||
{
|
if (controllerID == null) {
|
||||||
where: {
|
ret = await db.collections.destroy(
|
||||||
deleted: true
|
{
|
||||||
|
where: {
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
} else {
|
||||||
|
ret = await db.collections.destroy(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
controller_id: controllerID,
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,14 +53,26 @@ class CollectionModel {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByName (name) {
|
async getByName (name, controllerID) {
|
||||||
const ret = await db.collections.findAll(
|
let ret
|
||||||
{
|
if (controllerID == null) {
|
||||||
where: {
|
ret = await db.collections.findAll(
|
||||||
name: name
|
{
|
||||||
|
where: {
|
||||||
|
name: name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
} else {
|
||||||
|
ret = await db.collections.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
controller_id: controllerID,
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +120,19 @@ class CollectionModel {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAll () {
|
async getAll (controllerID) {
|
||||||
const ret = await db.collections.findAll()
|
let ret
|
||||||
|
if (controllerID == null) {
|
||||||
|
ret = await db.collections.findAll()
|
||||||
|
} else {
|
||||||
|
ret = await db.collections.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
controller_id: controllerID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
import RecordingDataRaw from './recording_data_raw'
|
||||||
|
import RecordingDataMini from './recording_data_mini'
|
||||||
const db = require('../../db/database')
|
const db = require('../../db/database')
|
||||||
|
// const RecordingDataMini = require('./recording_data_mini')
|
||||||
|
|
||||||
|
const recordingDataRaw = new RecordingDataRaw()
|
||||||
|
const recordingDataMini = new RecordingDataMini()
|
||||||
|
|
||||||
const Op = db.Sequelize.Op
|
const Op = db.Sequelize.Op
|
||||||
|
|
||||||
@@ -36,7 +42,34 @@ class RecordingDataMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clearDeleted () {
|
async clearDeleted () {
|
||||||
const ret = await db.recording_data_metas.destroy(
|
let ret = await db.recording_data_metas.findAll(
|
||||||
|
{
|
||||||
|
attributes: [
|
||||||
|
'id',
|
||||||
|
'raw_data',
|
||||||
|
'mini_data'
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
for (let i = 0; i < ret.length; i++) {
|
||||||
|
const meta = ret[i]
|
||||||
|
for (const channel in meta.raw_data) {
|
||||||
|
if (meta.raw_data[channel] != null) {
|
||||||
|
await recordingDataRaw.updateByIDs({ deleted: true }, meta.raw_data[channel], channel)
|
||||||
|
recordingDataRaw.clearDeleted(channel)
|
||||||
|
}
|
||||||
|
if (meta.mini_data[channel] != null) {
|
||||||
|
for (const miniID in meta.mini_data[channel]) {
|
||||||
|
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel][miniID], channel)
|
||||||
|
}
|
||||||
|
recordingDataMini.clearDeleted(channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = await db.recording_data_metas.destroy(
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
deleted: true
|
deleted: true
|
||||||
@@ -58,13 +91,74 @@ class RecordingDataMeta {
|
|||||||
parent: parentOp
|
parent: parentOp
|
||||||
},
|
},
|
||||||
order: [
|
order: [
|
||||||
['id', 'ASC']
|
['id', 'DESC']
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getCountByParent (type, parent) {
|
||||||
|
const collectionType = type + '::jsonb'
|
||||||
|
const parentOp = {}
|
||||||
|
parentOp[collectionType] = {
|
||||||
|
[Op.contains]: '[' + parent + ']'
|
||||||
|
}
|
||||||
|
const ret = await db.recording_data_metas.count(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
parent: parentOp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByParentWithLimit (type, parent, limit, offset, order) {
|
||||||
|
const collectionType = type + '::jsonb'
|
||||||
|
const parentOp = {}
|
||||||
|
parentOp[collectionType] = {
|
||||||
|
[Op.contains]: '[' + parent + ']'
|
||||||
|
}
|
||||||
|
const ret = await db.recording_data_metas.findAndCountAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
parent: parentOp
|
||||||
|
},
|
||||||
|
order: [
|
||||||
|
['id', order]
|
||||||
|
],
|
||||||
|
limit: limit,
|
||||||
|
offset: offset
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByAttrsParentWithLimit (type, parent, limit, offset, order, attr) {
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const orderList = order.split('-')
|
||||||
|
const collectionType = type + '::jsonb'
|
||||||
|
const parentOp = {}
|
||||||
|
parentOp[collectionType] = {
|
||||||
|
[Op.contains]: '[' + parent + ']'
|
||||||
|
}
|
||||||
|
const ret = await db.recording_data_metas.findAndCountAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
parent: parentOp
|
||||||
|
},
|
||||||
|
attributes: attrList,
|
||||||
|
order: [
|
||||||
|
[orderList[0], orderList[1]]
|
||||||
|
],
|
||||||
|
limit: limit,
|
||||||
|
offset: offset
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async getByID (id) {
|
async getByID (id) {
|
||||||
const ret = await db.recording_data_metas.findAll(
|
const ret = await db.recording_data_metas.findAll(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,18 @@ class RecordingDataMini {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateByIDs (req, id, index) {
|
||||||
|
const ret = await db[index + '_recording_data_minis'].update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async clearDeleted (index) {
|
async clearDeleted (index) {
|
||||||
const ret = await db[index + '_recording_data_minis'].destroy(
|
const ret = await db[index + '_recording_data_minis'].destroy(
|
||||||
{
|
{
|
||||||
@@ -57,6 +69,19 @@ class RecordingDataMini {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getByIDs (id, index) {
|
||||||
|
const _id = JSON.parse('[' + id + ']')
|
||||||
|
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
||||||
|
{
|
||||||
|
batchSize: 1000,
|
||||||
|
where: {
|
||||||
|
id: _id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async getMeanDataByID (id, index) {
|
async getMeanDataByID (id, index) {
|
||||||
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const db = require('../../db/database')
|
const db = require('../../db/database')
|
||||||
|
const sequelize = require('sequelize')
|
||||||
|
|
||||||
class RecordingDataRaw {
|
class RecordingDataRaw {
|
||||||
async create (req, index) {
|
async create (req, index) {
|
||||||
@@ -19,6 +20,23 @@ class RecordingDataRaw {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateSdData (req, id, index) {
|
||||||
|
const ret = await db.sequelize.query(`UPDATE "public"."${index}_recording_data_raws" SET sd_data = sd_data || '${req.data}' WHERE id = ${String(id)}`)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByIDs (req, id, index) {
|
||||||
|
const ret = await db[index + '_recording_data_raws'].update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async clearDeleted (index) {
|
async clearDeleted (index) {
|
||||||
const ret = await db[index + '_recording_data_raws'].destroy(
|
const ret = await db[index + '_recording_data_raws'].destroy(
|
||||||
{
|
{
|
||||||
@@ -57,6 +75,19 @@ class RecordingDataRaw {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getByIDs (id, index) {
|
||||||
|
const _id = JSON.parse('[' + id + ']')
|
||||||
|
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||||
|
{
|
||||||
|
batchSize: 1000,
|
||||||
|
where: {
|
||||||
|
id: _id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async getDataByID (id, index) {
|
async getDataByID (id, index) {
|
||||||
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||||
{
|
{
|
||||||
@@ -72,6 +103,22 @@ class RecordingDataRaw {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSdDataByID (id, index) {
|
||||||
|
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||||
|
{
|
||||||
|
batchSize: 1000,
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
attributes: [
|
||||||
|
'sd_data'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async getByAttrID (id, attr, index) {
|
async getByAttrID (id, attr, index) {
|
||||||
const attrList = attr.split('-')
|
const attrList = attr.split('-')
|
||||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||||
@@ -85,6 +132,23 @@ class RecordingDataRaw {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getByAttrIDs (id, attr, index) {
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const _id = JSON.parse('[' + id + ']')
|
||||||
|
const ord = [sequelize.literal(`ARRAY_POSITION(ARRAY[${_id}]::integer[], "id")`)]
|
||||||
|
|
||||||
|
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: _id
|
||||||
|
},
|
||||||
|
attributes: attrList,
|
||||||
|
order: ord
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
async getByAttrParent (parent, attr, index) {
|
async getByAttrParent (parent, attr, index) {
|
||||||
const attrList = attr.split('-')
|
const attrList = attr.split('-')
|
||||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
const db = require('../../db/database')
|
||||||
|
|
||||||
|
// const Op = db.Sequelize.Op
|
||||||
|
|
||||||
|
class ControllerModel {
|
||||||
|
async create (req) {
|
||||||
|
console.log(req)
|
||||||
|
return db.controllers.create(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update (req, id) {
|
||||||
|
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
if (id != null) {
|
||||||
|
const ret = await db.controllers.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
} else {
|
||||||
|
const ret = await db.controllers.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByAttr (req, attr, value) {
|
||||||
|
const whereObj = {}
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
const ret = await db.controllers.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearDeleted () {
|
||||||
|
const ret = await db.controllers.delete(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByID (id) {
|
||||||
|
const ret = await db.controllers.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByName (name) {
|
||||||
|
const ret = await db.controllers.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByMac (mac) {
|
||||||
|
const ret = await db.controllers.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
mac_address: mac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByMqttId (mqttId) {
|
||||||
|
const ret = await db.controllers.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
mqtt_id: mqttId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByAttr (attr, value) {
|
||||||
|
const whereObj = {}
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
|
||||||
|
const ret = await db.controllers.findAll(
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAll () {
|
||||||
|
const ret = await db.controllers.findAll()
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ControllerModel
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
const db = require('../../db/database')
|
||||||
|
|
||||||
|
// const Op = db.Sequelize.Op
|
||||||
|
|
||||||
|
class DeviceModel {
|
||||||
|
async create (req) {
|
||||||
|
return db.devices.create({
|
||||||
|
name: req.name,
|
||||||
|
serial_number: req.serial_number,
|
||||||
|
mac_address: req.mac_address,
|
||||||
|
connect_priority: await db.devices.count()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async update (req, id) {
|
||||||
|
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
if (id != null) {
|
||||||
|
const ret = await db.devices.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
} else {
|
||||||
|
const ret = await db.devices.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByMac (req, mac) {
|
||||||
|
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||||
|
const ret = await db.devices.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
mac_address: mac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateByAttr (req, attr, value) {
|
||||||
|
const whereObj = {}
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
|
||||||
|
const ret = await db.devices.update(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearDeleted () {
|
||||||
|
const ret = await db.devices.destroy(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByID (id) {
|
||||||
|
const ret = await db.devices.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByName (name) {
|
||||||
|
const ret = await db.devices.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
name: name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByMac (mac) {
|
||||||
|
const ret = await db.devices.findAll(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
mac_address: mac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getByAttr (attr, value) {
|
||||||
|
const attrList = attr.split('-')
|
||||||
|
const valueList = value.split('-')
|
||||||
|
const whereObj = {}
|
||||||
|
attrList.forEach((key, idx) => {
|
||||||
|
whereObj[key] = valueList[idx]
|
||||||
|
})
|
||||||
|
|
||||||
|
const ret = await db.devices.findAll(
|
||||||
|
{
|
||||||
|
where: whereObj
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAll () {
|
||||||
|
const ret = await db.devices.findAll({
|
||||||
|
order: [
|
||||||
|
['connect_priority', 'ASC']
|
||||||
|
]
|
||||||
|
})
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DeviceModel
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import controllers from '../../controllers'
|
||||||
|
|
||||||
|
// '/api/analysis'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/analysis'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/spike_detect', controllers.analysis.spikeDetect],
|
||||||
|
['POST', prefix + '/iir_filter', controllers.analysis.IIRFliter]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import controllers from '../../controllers'
|
||||||
|
|
||||||
|
// '/api/controller'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/controller'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create', controllers.controller.create],
|
||||||
|
['POST', prefix + '/update/:id', controllers.controller.update],
|
||||||
|
['POST', prefix + '/update_by_attr/:attr/:value', controllers.controller.updateByAttr],
|
||||||
|
['GET', prefix + '/get_by_name/:name', controllers.controller.getByName],
|
||||||
|
['GET', prefix + '/get_by_mqtt_id/:mqtt_id', controllers.controller.getByMqttId],
|
||||||
|
['GET', prefix + '/get_by_mac/:mac', controllers.controller.getByMac],
|
||||||
|
['GET', prefix + '/get_by_attr/:attr/:value', controllers.controller.getByAttr],
|
||||||
|
['GET', prefix + '/get/all', controllers.controller.getAll]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import controllers from '../../controllers'
|
||||||
|
|
||||||
|
// '/api/device'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/device'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create', controllers.device.create],
|
||||||
|
['POST', prefix + '/update/:id', controllers.device.update],
|
||||||
|
['POST', prefix + '/update_by_mac/:mac', controllers.device.updateByMac],
|
||||||
|
['POST', prefix + '/update_by_attr/:attr/:value', controllers.device.updateByAttr],
|
||||||
|
['GET', prefix + '/clear_deleted/:id', controllers.device.clearDeleted],
|
||||||
|
['GET', prefix + '/get_by_mac/:mac', controllers.device.getByMac],
|
||||||
|
['GET', prefix + '/get_by_attr/:attr/:value', controllers.device.getByAttr],
|
||||||
|
['GET', prefix + '/get/all', controllers.device.getAll]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/collection'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/collection'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create', controllers.collection.create],
|
||||||
|
['POST', prefix + '/update/:id', controllers.collection.update],
|
||||||
|
['GET', prefix + '/clear_deleted/:controller_id', controllers.collection.clearDeleted],
|
||||||
|
['GET', prefix + '/get_by_id/:id', controllers.collection.getByID],
|
||||||
|
['GET', prefix + '/get_by_name/:name/:controller_id', controllers.collection.getByName],
|
||||||
|
['GET', prefix + '/get_by_parent/:type/:parent', controllers.collection.getByParent],
|
||||||
|
['GET', prefix + '/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName],
|
||||||
|
['GET', prefix + '/get/all/:controller_id', controllers.collection.getAll],
|
||||||
|
['GET', prefix + '/get_by_name/:name', controllers.collection.getByName],
|
||||||
|
['GET', prefix + '/get/all', controllers.collection.getAll],
|
||||||
|
['GET', prefix + '/clear_deleted', controllers.collection.clearDeleted]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import collection from './collection'
|
||||||
|
import meta from './meta'
|
||||||
|
import mini from './mini'
|
||||||
|
import raw from './raw'
|
||||||
|
import sdcard from './sdcard'
|
||||||
|
import trigger from './trigger'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/file'
|
||||||
|
return [
|
||||||
|
...collection(prefix),
|
||||||
|
...meta(prefix),
|
||||||
|
...mini(prefix),
|
||||||
|
...raw(prefix),
|
||||||
|
...sdcard(prefix),
|
||||||
|
...trigger(prefix)
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/meta'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/meta'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create', controllers.recordingDataMeta.create],
|
||||||
|
['POST', prefix + '/update/:id', controllers.recordingDataMeta.update],
|
||||||
|
['GET', prefix + '/clear_deleted/', controllers.recordingDataMeta.clearDeleted],
|
||||||
|
['GET', prefix + '/get_by_name/:name', controllers.recordingDataMeta.getByName],
|
||||||
|
['GET', prefix + '/get_by_uuid/:uuid', controllers.recordingDataMeta.getByUUID],
|
||||||
|
['GET', prefix + '/get_by_id/:id', controllers.recordingDataMeta.getByID],
|
||||||
|
['GET', prefix + '/get_by_path/:path', controllers.recordingDataMeta.getByPath],
|
||||||
|
['GET', prefix + '/get_by_parent/:type/:parent', controllers.recordingDataMeta.getByParent],
|
||||||
|
['GET', prefix + '/get_count_by_parent/:type/:parent', controllers.recordingDataMeta.getCountByParent],
|
||||||
|
['GET', prefix + '/get_by_parent_with_limit/:type/:parent/:limit/:offset/:order', controllers.recordingDataMeta.getByParentWithLimit],
|
||||||
|
['GET', prefix + '/get_by_attr_parent_with_limit/:type/:parent/:limit/:offset/:order/:attr', controllers.recordingDataMeta.getByAttrsParentWithLimit],
|
||||||
|
['GET', prefix + '/get_or_create_by_path/:path', controllers.recordingDataMeta.getOrCreateByPath],
|
||||||
|
['GET', prefix + '/get/all', controllers.recordingDataMeta.getAll]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/mini'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/mini'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create/:channel', controllers.recordingDataMini.create],
|
||||||
|
['POST', prefix + '/update/:channel/:id', controllers.recordingDataMini.update],
|
||||||
|
['GET', prefix + '/clear_deleted/:channel/:id', controllers.recordingDataMini.clearDeleted],
|
||||||
|
['GET', prefix + '/get_by_id/:channel/:id', controllers.recordingDataMini.getByID],
|
||||||
|
['GET', prefix + '/get_by_parent/:channel/:parent', controllers.recordingDataMini.getByParent],
|
||||||
|
['GET', prefix + '/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataMini.getAttrByID],
|
||||||
|
['GET', prefix + '/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent],
|
||||||
|
['GET', prefix + '/random/get_by_id/:channel/:id', controllers.recordingDataMini.getRandomDataByID],
|
||||||
|
['GET', prefix + '/mean/get_by_id/:channel/:id', controllers.recordingDataMini.getMeanDataByID]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/raw'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/raw'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create/:channel', controllers.recordingDataRaw.create],
|
||||||
|
['POST', prefix + '/update/:channel/:id', controllers.recordingDataRaw.update],
|
||||||
|
['POST', prefix + '/update_sd_data/:channel/:id', controllers.recordingDataRaw.updateSdData],
|
||||||
|
['GET', prefix + '/clear_deleted/:channel/:id', controllers.recordingDataRaw.clearDeleted],
|
||||||
|
['GET', prefix + '/get_by_id/:channel/:id', controllers.recordingDataRaw.getByID],
|
||||||
|
['GET', prefix + '/get_by_ids/:channel/:id', controllers.recordingDataRaw.getByIDs],
|
||||||
|
['GET', prefix + '/get_data_by_id/:channel/:id', controllers.recordingDataRaw.getDataByID],
|
||||||
|
['GET', prefix + '/get_sd_data_by_id/:channel/:id', controllers.recordingDataRaw.getSdDataByID],
|
||||||
|
['GET', prefix + '/get_by_parent/:channel/:parent', controllers.recordingDataRaw.getByParent],
|
||||||
|
['GET', prefix + '/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByID],
|
||||||
|
['GET', prefix + '/get_attr_by_ids/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByIDs],
|
||||||
|
['GET', prefix + '/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataRaw.getAttrByParent]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/sdcard'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/sdcard'
|
||||||
|
return [
|
||||||
|
['GET', prefix + '/get', controllers.sdCard.getFileList],
|
||||||
|
['POST', prefix + '/exist', controllers.sdCard.exist],
|
||||||
|
['POST', prefix + '/upload', controllers.sdCard.uploadThenDelete],
|
||||||
|
// ['POST', prefix + '/delete', controllers.sdCard.deleted]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/file/trigger'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/trigger'
|
||||||
|
return [
|
||||||
|
['GET', prefix + '/get_meta_by_uuid/:uuid', controllers.trigger.getMetaByUUID],
|
||||||
|
['GET', prefix + '/get/all', controllers.trigger.getMetaAll],
|
||||||
|
['GET', prefix + '/get_raw_by_uuid/:parent_uuid', controllers.trigger.getTriggerRawByUUID],
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import file from './file'
|
||||||
|
import project from './project'
|
||||||
|
import device from './device'
|
||||||
|
import controller from './controller'
|
||||||
|
import analysis from './analysis'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/api'
|
||||||
|
|
||||||
|
return [
|
||||||
|
...file(prefix),
|
||||||
|
...project(prefix),
|
||||||
|
...device(prefix),
|
||||||
|
...controller(prefix),
|
||||||
|
...analysis(prefix)
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import task from './task'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/project'
|
||||||
|
return [
|
||||||
|
...task(prefix)
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import controllers from '../../../controllers'
|
||||||
|
|
||||||
|
// '/api/task'
|
||||||
|
|
||||||
|
export default function (_prefix) {
|
||||||
|
const prefix = _prefix + '/task'
|
||||||
|
return [
|
||||||
|
['POST', prefix + '/create', controllers.task.create],
|
||||||
|
['POST', prefix + '/update/:id', controllers.task.update],
|
||||||
|
['POST', prefix + '/update_by_attr/:attr/:value', controllers.task.updateByAttr],
|
||||||
|
['GET', prefix + '/get_by_id/:id', controllers.task.getByID],
|
||||||
|
['GET', prefix + '/get_by_attr/:attr/:value', controllers.task.getByAttr],
|
||||||
|
['GET', prefix + '/get/all', controllers.task.getAll]
|
||||||
|
]
|
||||||
|
}
|
||||||
+26
-48
@@ -1,57 +1,35 @@
|
|||||||
import KoaRouter from 'koa-router'
|
import KoaRouter from 'koa-router'
|
||||||
import controllers from '../controllers'
|
import controllers from '../controllers'
|
||||||
|
import api from './api'
|
||||||
|
|
||||||
const router = new KoaRouter()
|
const router = new KoaRouter()
|
||||||
|
|
||||||
export default router
|
router
|
||||||
.get('/public/get', function (ctx, next) {
|
// .get('/public/get', function (ctx, next) {
|
||||||
ctx.body = '禁止访问!'
|
// ctx.body = 'no access'
|
||||||
})
|
// })
|
||||||
.all('/upload', controllers.upload)
|
// .all('/upload', controllers.upload)
|
||||||
.get('/public/api/:name', controllers.api.Get)
|
// .get('/public/api/:name', controllers.api.Get)
|
||||||
.post('/api/:name', controllers.api.Post)
|
// .post('/api/:name', controllers.api.Post)
|
||||||
.put('/api/:name', controllers.api.Put)
|
// .put('/api/:name', controllers.api.Put)
|
||||||
.del('/api/:name', controllers.api.Delete)
|
// .del('/api/:name', controllers.api.Delete)
|
||||||
.post('/auth/:action', controllers.auth.Post)
|
// .post('/auth/:action', controllers.auth.Post)
|
||||||
// user
|
// user
|
||||||
.get('/public/auth/get_cookie', controllers.auth.getCookie)
|
.get('/public/auth/get_cookie', controllers.auth.getCookie)
|
||||||
|
.get('/public/auth/update_license', controllers.auth.updateLicense)
|
||||||
|
.get('/public/auth/check_license', controllers.auth.checkLicense)
|
||||||
|
|
||||||
// collection
|
for (const _route of api('')) {
|
||||||
.post('/api/collection/create', controllers.collection.create)
|
switch (_route[0]) {
|
||||||
.get('/api/collection/get_by_id/:id', controllers.collection.getByID)
|
case 'GET':
|
||||||
.get('/api/collection/get_by_name/:name', controllers.collection.getByName)
|
router.get(_route[1], _route[2])
|
||||||
.get('/api/collection/get_by_parent/:type/:parent', controllers.collection.getByParent)
|
break
|
||||||
.get('/api/collection/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName)
|
case 'POST':
|
||||||
.get('/api/collection/get/all', controllers.collection.getAll)
|
router.post(_route[1], _route[2])
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// meta
|
export default router
|
||||||
.post('/api/file/meta/create', controllers.recordingDataMeta.create)
|
|
||||||
.post('/api/file/meta/update/:id', controllers.recordingDataMeta.update)
|
|
||||||
.get('/api/file/meta/clear_deleted/:id', controllers.recordingDataMeta.clearDeleted)
|
|
||||||
.get('/api/file/meta/get_by_name/:name', controllers.recordingDataMeta.getByName)
|
|
||||||
.get('/api/file/meta/get_by_uuid/:uuid', controllers.recordingDataMeta.getByUUID)
|
|
||||||
.get('/api/file/meta/get_by_id/:id', controllers.recordingDataMeta.getByID)
|
|
||||||
.get('/api/file/meta/get_by_path/:path', controllers.recordingDataMeta.getByPath)
|
|
||||||
.get('/api/file/meta/get_by_parent/:type/:parent', controllers.recordingDataMeta.getByParent)
|
|
||||||
.get('/api/file/meta/get_or_create_by_path/:path', controllers.recordingDataMeta.getOrCreateByPath)
|
|
||||||
|
|
||||||
// raw
|
|
||||||
.post('/api/file/raw/create/:channel', controllers.recordingDataRaw.create)
|
|
||||||
.post('/api/file/raw/update/:channel/:id', controllers.recordingDataRaw.update)
|
|
||||||
.get('/api/file/raw/clear_deleted/:channel/:id', controllers.recordingDataRaw.clearDeleted)
|
|
||||||
.get('/api/file/raw/get_by_id/:channel/:id', controllers.recordingDataRaw.getByID)
|
|
||||||
.get('/api/file/raw/get_data_by_id/:channel/:id', controllers.recordingDataRaw.getDataByID)
|
|
||||||
.get('/api/file/raw/get_by_parent/:channel/:parent', controllers.recordingDataRaw.getByParent)
|
|
||||||
.get('/api/file/raw/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByID)
|
|
||||||
.get('/api/file/raw/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataRaw.getAttrByParent)
|
|
||||||
|
|
||||||
// mini
|
|
||||||
.post('/api/file/mini/create/:channel', controllers.recordingDataMini.create)
|
|
||||||
.post('/api/file/mini/update/:channel/:id', controllers.recordingDataMini.update)
|
|
||||||
.get('/api/file/mini/clear_deleted/:channel/:id', controllers.recordingDataMini.clearDeleted)
|
|
||||||
.get('/api/file/mini/get_by_id/:channel/:id', controllers.recordingDataMini.getByID)
|
|
||||||
.get('/api/file/mini/get_by_parent/:channel/:parent', controllers.recordingDataMini.getByParent)
|
|
||||||
.get('/api/file/mini/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataMini.getAttrByID)
|
|
||||||
.get('/api/file/mini/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent)
|
|
||||||
.get('/api/file/mini/random/get_by_id/:channel/:id', controllers.recordingDataMini.getRandomDataByID)
|
|
||||||
.get('/api/file/mini/mean/get_by_id/:channel/:id', controllers.recordingDataMini.getMeanDataByID)
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Elite: 53
|
||||||
|
# Neulive: 101 or 95
|
||||||
|
ssh -NL 54321:localhost:5432 pi@192.168.2.1
|
||||||
Reference in New Issue
Block a user