Add settings api, update models
parent
21067730dd
commit
7ff8d5f190
|
@ -0,0 +1,50 @@
|
|||
NODE_ENV=development
|
||||
APP_SALT=RANDOM_SEED
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_NAME=retro-pilot
|
||||
DB_USER=root
|
||||
DB_PASS=root
|
||||
# If using docker compose, this should match the container service name
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
# Whether or not to DROP all tables and recreate to match the current models
|
||||
DB_FORCE_SYNC=false
|
||||
|
||||
ALLOW_REGISTRATION=true
|
||||
AUTH_2FA_ISSUER=RetroPilot
|
||||
|
||||
HTTP_INTERFACE=0.0.0.0
|
||||
HTTP_PORT=8080
|
||||
|
||||
# Set to false to skip sending mail, all attempted mail is logged under DEBUG
|
||||
CAN_SEND_MAIL=false
|
||||
# credentials for smtp server to send account registration mails. if not filled in, get the generated tokens from the server.log manually
|
||||
SMTP_HOST="localhost"
|
||||
SMTP_PORT=25
|
||||
SMTP_USER=root
|
||||
SMTP_PASS=
|
||||
SMTP_FROM="no-reply@retropilot.org"
|
||||
|
||||
# base url of the retropilot server
|
||||
BASE_URL="http://192.168.1.165:8080/"
|
||||
# base url sent to devices for POSTing drives & logs
|
||||
BASE_UPLOAD_URL="http://192.168.1.165:8080/backend/post_upload"
|
||||
# base download url for drive & log data
|
||||
BASE_DRIVE_DOWNLOAD_URL="http://192.168.1.165:8080/realdata/"
|
||||
# path mapping of above download url for expressjs, prefix with "/"
|
||||
BASE_DRIVE_DOWNLOAD_PATH_MAPPING="/realdata"
|
||||
# relative or absolute ( "/..." for absolute path )
|
||||
STORAGE_PATH="realdata/"
|
||||
|
||||
CABANA_URL="http://192.168.1.165:8080/cabana/index.html"
|
||||
|
||||
DEVICE_STORAGE_QUOTA_MB=200000
|
||||
DEVICE_EXPIRATION_DAYS=30
|
||||
|
||||
WELCOME_MESSAGE="<><><><><><><><><><><><><><><><><><><><><><><br>2022 RetroPilot"
|
||||
|
||||
USE_USER_ADMIN_API=0
|
||||
|
||||
CLIENT_SOCKET_PORT=81
|
||||
CLIENT_SOCKET_HOST="0.0.0.0"
|
|
@ -1,23 +1,15 @@
|
|||
import Accounts from './accounts.model';
|
||||
import AthenaActionLog from './athena_action_log.model';
|
||||
import AthenaReturnedData from './athena_returned_data.model';
|
||||
import DeviceAuthorisedUsers from './device_authorised_users.model';
|
||||
import Devices from './devices.model';
|
||||
import DriveSegments from './drive_segments.model';
|
||||
import Drives from './drives.model';
|
||||
import OAuthAccounts from './oauth_accounts.model';
|
||||
|
||||
import orm from './orm';
|
||||
|
||||
export {
|
||||
Accounts,
|
||||
AthenaActionLog,
|
||||
AthenaReturnedData,
|
||||
DeviceAuthorisedUsers,
|
||||
Devices,
|
||||
DriveSegments,
|
||||
Drives,
|
||||
OAuthAccounts,
|
||||
};
|
||||
|
||||
export default orm;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import { Accounts } from '../../../models';
|
||||
|
||||
export async function SetResearchStatus(userId, status) {
|
||||
if (typeof (status) !== 'boolean') { return { success: false, notBoolean: true }; }
|
||||
|
||||
Accounts.update({ research_enabled: status }, { where: { id: userId } });
|
||||
}
|
||||
|
||||
export async function GetResearchStatus(userId) {
|
||||
return Accounts.findOne({where: {id: userId}, attributes: ['research_enabled']})
|
||||
}
|
||||
|
||||
|
||||
export default null;
|
|
@ -0,0 +1,34 @@
|
|||
import bodyParser from 'body-parser';
|
||||
import crypto from 'crypto';
|
||||
import dirTree from 'directory-tree';
|
||||
import express from 'express';
|
||||
import log4js from 'log4js';
|
||||
|
||||
import { requireAuthenticated } from '../../../middlewares/authentication';
|
||||
import { SetResearchStatus, GetResearchStatus } from '../../../controllers/user/settings';
|
||||
|
||||
const logger = log4js.getLogger();
|
||||
|
||||
// /api/devices
|
||||
const router = express.Router();
|
||||
|
||||
router.patch('/research/:enabled', requireAuthenticated, async (req, res) => {
|
||||
const { enabled } = req.params;
|
||||
if (!enabled) { res.json({ bad: true }); }
|
||||
const doEnable = enabled === 'true';
|
||||
const accountId = req.account.id;
|
||||
|
||||
const update = await SetResearchStatus(req.account.id, doEnable);
|
||||
|
||||
return res.json({ success: true, data: req.account });
|
||||
});
|
||||
|
||||
router.get('/research/', requireAuthenticated, async (req, res) => {
|
||||
const accountId = req.account.id;
|
||||
|
||||
const update = await GetResearchStatus(req.account.id);
|
||||
|
||||
return res.json({ success: true, data: update });
|
||||
});
|
||||
|
||||
export default router;
|
Loading…
Reference in New Issue