feat(api): public settings route (#57)

adds public settings route that provides initalized value to check if the app has been configured
for the first time
pull/58/head
sct 4 years ago committed by GitHub
parent fcaabcb428
commit c0166e7ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,11 +42,16 @@ interface MainSettings {
apiKey: string; apiKey: string;
} }
interface PublicSettings {
initialized: boolean;
}
interface AllSettings { interface AllSettings {
main: MainSettings; main: MainSettings;
plex: PlexSettings; plex: PlexSettings;
radarr: RadarrSettings[]; radarr: RadarrSettings[];
sonarr: SonarrSettings[]; sonarr: SonarrSettings[];
public: PublicSettings;
} }
const SETTINGS_PATH = path.join(__dirname, '../../config/settings.json'); const SETTINGS_PATH = path.join(__dirname, '../../config/settings.json');
@ -68,6 +73,9 @@ class Settings {
}, },
radarr: [], radarr: [],
sonarr: [], sonarr: [],
public: {
initialized: false,
},
}; };
if (initialSettings) { if (initialSettings) {
Object.assign<AllSettings, AllSettings>(this.data, initialSettings); Object.assign<AllSettings, AllSettings>(this.data, initialSettings);
@ -106,6 +114,14 @@ class Settings {
this.data.sonarr = data; this.data.sonarr = data;
} }
get public(): PublicSettings {
return this.data.public;
}
set public(data: PublicSettings) {
this.data.public = data;
}
/** /**
* Settings Load * Settings Load
* *
@ -126,7 +142,7 @@ class Settings {
const data = fs.readFileSync(SETTINGS_PATH, 'utf-8'); const data = fs.readFileSync(SETTINGS_PATH, 'utf-8');
if (data) { if (data) {
this.data = JSON.parse(data); this.data = Object.assign(this.data, JSON.parse(data));
} }
return this.data; return this.data;
} }

@ -184,6 +184,12 @@ components:
- activeDirectory - activeDirectory
- is4k - is4k
- enableSeasonFolders - enableSeasonFolders
PublicSettings:
type: object
properties:
initialized:
type: boolean
example: false
AllSettings: AllSettings:
type: object type: object
properties: properties:
@ -199,11 +205,14 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/SonarrSettings' $ref: '#/components/schemas/SonarrSettings'
public:
$ref: '#/components/schemas/PublicSettings'
required: required:
- main - main
- plex - plex
- radarr - radarr
- sonarr - sonarr
- public
securitySchemes: securitySchemes:
cookieAuth: cookieAuth:
@ -430,6 +439,19 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SonarrSettings' $ref: '#/components/schemas/SonarrSettings'
/settings/public:
get:
summary: Returns public settings
description: Returns settings that are not protected or sensitive. Mainly used to determine if the app has been configured for the first time.
tags:
- settings
responses:
'200':
description: Public Settings returned
content:
application/json:
schema:
$ref: '#/components/schemas/PublicSettings'
/auth/me: /auth/me:
get: get:
summary: Returns the currently logged in user summary: Returns the currently logged in user

@ -4,6 +4,7 @@ import authRoutes from './auth';
import { checkUser, isAuthenticated } from '../middleware/auth'; import { checkUser, isAuthenticated } from '../middleware/auth';
import settingsRoutes from './settings'; import settingsRoutes from './settings';
import { Permission } from '../lib/permissions'; import { Permission } from '../lib/permissions';
import { getSettings } from '../lib/settings';
const router = Router(); const router = Router();
@ -16,7 +17,13 @@ router.use(
); );
router.use('/auth', authRoutes); router.use('/auth', authRoutes);
router.get('/', (req, res) => { router.get('/settings/public', (_req, res) => {
const settings = getSettings();
return res.status(200).json(settings.public);
});
router.get('/', (_req, res) => {
return res.status(200).json({ return res.status(200).json({
api: 'Overseerr API', api: 'Overseerr API',
version: '1.0', version: '1.0',

@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React from 'react';
import Transition from '../../Transition'; import Transition from '../../Transition';
interface SidebarProps { interface SidebarProps {

Loading…
Cancel
Save