Skip to content

Commit

Permalink
feat(api): public settings route (#57)
Browse files Browse the repository at this point in the history
adds public settings route that provides initalized value to check if the app has been configured
for the first time
  • Loading branch information
sct committed Sep 7, 2020
1 parent fcaabcb commit c0166e7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
18 changes: 17 additions & 1 deletion server/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ interface MainSettings {
apiKey: string;
}

interface PublicSettings {
initialized: boolean;
}

interface AllSettings {
main: MainSettings;
plex: PlexSettings;
radarr: RadarrSettings[];
sonarr: SonarrSettings[];
public: PublicSettings;
}

const SETTINGS_PATH = path.join(__dirname, '../../config/settings.json');
Expand All @@ -68,6 +73,9 @@ class Settings {
},
radarr: [],
sonarr: [],
public: {
initialized: false,
},
};
if (initialSettings) {
Object.assign<AllSettings, AllSettings>(this.data, initialSettings);
Expand Down Expand Up @@ -106,6 +114,14 @@ class Settings {
this.data.sonarr = data;
}

get public(): PublicSettings {
return this.data.public;
}

set public(data: PublicSettings) {
this.data.public = data;
}

/**
* Settings Load
*
Expand All @@ -126,7 +142,7 @@ class Settings {
const data = fs.readFileSync(SETTINGS_PATH, 'utf-8');

if (data) {
this.data = JSON.parse(data);
this.data = Object.assign(this.data, JSON.parse(data));
}
return this.data;
}
Expand Down
22 changes: 22 additions & 0 deletions server/overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ components:
- activeDirectory
- is4k
- enableSeasonFolders
PublicSettings:
type: object
properties:
initialized:
type: boolean
example: false
AllSettings:
type: object
properties:
Expand All @@ -199,11 +205,14 @@ components:
type: array
items:
$ref: '#/components/schemas/SonarrSettings'
public:
$ref: '#/components/schemas/PublicSettings'
required:
- main
- plex
- radarr
- sonarr
- public

securitySchemes:
cookieAuth:
Expand Down Expand Up @@ -430,6 +439,19 @@ paths:
application/json:
schema:
$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:
get:
summary: Returns the currently logged in user
Expand Down
9 changes: 8 additions & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import authRoutes from './auth';
import { checkUser, isAuthenticated } from '../middleware/auth';
import settingsRoutes from './settings';
import { Permission } from '../lib/permissions';
import { getSettings } from '../lib/settings';

const router = Router();

Expand All @@ -16,7 +17,13 @@ router.use(
);
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({
api: 'Overseerr API',
version: '1.0',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import Transition from '../../Transition';

interface SidebarProps {
Expand Down

0 comments on commit c0166e7

Please sign in to comment.