Skip to content

Commit

Permalink
Refactor Server Config Files
Browse files Browse the repository at this point in the history
Quick refactoring to move config-related files into their own subfolder. Also
move individual classes out of MarkerEditorConfig.js, and split out standalone
helpers.

Also refactors ContextualLog to handle multiple requests for the same log prefix
  • Loading branch information
danrahn committed Oct 13, 2024
1 parent 7e421c1 commit c8f6e7c
Show file tree
Hide file tree
Showing 68 changed files with 743 additions and 659 deletions.
2 changes: 1 addition & 1 deletion Client/Script/AnimationHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConsoleLog, ContextualLog } from '/Shared/ConsoleLog.js';
import { $$ } from './Common.js';
import { Attributes } from './DataAttributes.js';

const Log = new ContextualLog('Animate');
const Log = ContextualLog.Create('Animate');

/**
* @typedef {Object} CustomAnimationOptions
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/BulkActionCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Theme } from './ThemeColors.js';

/** @typedef {{ [showId: number] : { [seasonId: number]: MarkerData[] } }} BulkMarkerResult */

const Log = new ContextualLog('BulkAction');
const Log = ContextualLog.Create('BulkAction');

/**
* Base class that represents a row in a bulk action customization table.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/BulkAddOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ThemeColors } from './ThemeColors.js';
/** @typedef {!import('/Shared/PlexTypes').SerializedMarkerData} SerializedMarkerData */
/** @typedef {!import('/Shared/PlexTypes').ShowData} ShowData */

const Log = new ContextualLog('BulkAddOverlay');
const Log = ContextualLog.Create('BulkAddOverlay');

/**
* UI for bulk adding markers to a given show/season
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/BulkShiftOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Tooltip from './Tooltip.js';
* @property {boolean} hasError Whether any markers are completely cut off by the shift
*/

const Log = new ContextualLog('BulkShift');
const Log = ContextualLog.Create('BulkShift');

/**
* UI for bulk shifting markers for a given show/season by a set amount of time.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ButtonCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Tooltip from './Tooltip.js';

/** @typedef {{[attribute: string]: string}} AttributeMap */

const Log = new ContextualLog('ButtonCreator');
const Log = ContextualLog.Create('ButtonCreator');

/**
* A static class that creates various buttons used throughout the app.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Tooltip from './Tooltip.js';
* Adapted from PlexWeb/script/chart.js
*/

const Log = new ContextualLog('Chart');
const Log = ContextualLog.Create('Chart');

/* eslint-disable no-invalid-this */ // Remove if Chart becomes a proper class

Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ClientDataExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MarkerTable from './MarkerTable.js';
/** @typedef {!import('./ResultRow/EpisodeResultRow').EpisodeResultRow} EpisodeResultRow */
/** @typedef {!import('./ResultRow/MovieResultRow').MovieResultRow} MovieResultRow */

const Log = new ContextualLog('ClientData');
const Log = ContextualLog.Create('ClientData');

/**
* @typedef {Object} BaseItemCommon
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ClientSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Tooltip from './Tooltip.js';
/** @typedef {!import('/Shared/ServerConfig').SerializedConfig} SerializedConfig */
/** @typedef {!import('./Overlay').OverlayOptions} OverlayOptions */

const Log = new ContextualLog('ClientSettings');
const Log = ContextualLog.Create('ClientSettings');

/**
* Base class for implementing a client-side setting.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PostCommands } from '/Shared/PostCommands.js';
/** @typedef {!import('/Shared/ServerConfig').SerializedConfig} SerializedConfig */
/** @template T @typedef {!import('/Shared/ServerConfig').TypedSetting<T>} TypedSetting<T> */

const Log = new ContextualLog('ServerCommands');
const Log = ContextualLog.Create('ServerCommands');

/**
* Core method that makes a request to the server, expecting JSON in return.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ErrorHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ContextualLog } from '/Shared/ConsoleLog.js';
import FetchError from './FetchError.js';
import Overlay from './Overlay.js';

const Log = new ContextualLog('ErrorHandling');
const Log = ContextualLog.Create('ErrorHandling');

/**
* Displays an overlay for the given error
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/FilterDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SectionType } from '/Shared/PlexTypes.js';
/** @typedef {!import('/Shared/MarkerBreakdown').MarkerBreakdownMap} MarkerBreakdownMap */
/** @typedef {!import('/Shared/PlexTypes').MarkerData} MarkerData */

const Log = new ContextualLog('SortFilter');
const Log = ContextualLog.Create('SortFilter');

/**
* TODO: BETWEEN and percentage-based for TV shows (something like >90% && <100% could be helpful)
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/MarkerBreakdownChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ThemeColors } from './ThemeColors.js';

/** @typedef {!import('./Chart').ChartDataPoint} ChartDataPoint */

const Log = new ContextualLog('BreakdownChart');
const Log = ContextualLog.Create('BreakdownChart');

/**
* Available charts
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/MarkerEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Tooltip from './Tooltip.js';
/** @typedef {!import('./ClientDataExtensions').MediaItemWithMarkerTable} MediaItemWithMarkerTable */
/** @typedef {!import('./MarkerTableRow').MarkerRow} MarkerRow */

const Log = new ContextualLog('MarkerEdit');
const Log = ContextualLog.Create('MarkerEdit');

/**
* Handles the editing of markers in the marker table.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/MarkerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import TableElements from './TableElements.js';
* }} BestFocusMatchBackups
* */

const Log = new ContextualLog('MarkerTable');
const Log = ContextualLog.Create('MarkerTable');

/**
* Static helper class that encapsulates the logic that determines keyboard navigation targets.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/MarkerTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { TimestampThumbnails } from './TimestampThumbnails.js';
import Tooltip from './Tooltip.js';


const Log = new ContextualLog('MarkerTableRow');
const Log = ContextualLog.Create('MarkerTableRow');

/** @typedef {!import('./ClientDataExtensions').MediaItemWithMarkerTable} MediaItemWithMarkerTable */
/** @typedef {!import('./ResultRow/BaseItemResultRow').BaseItemResultRow} BaseItemResultRow */
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Tooltip from './Tooltip.js';
*/


const Log = new ContextualLog('Overlay');
const Log = ContextualLog.Create('Overlay');

/* eslint-disable no-invalid-this */ // Remove if Overlay becomes a proper class

Expand Down
2 changes: 1 addition & 1 deletion Client/Script/PlexClientState.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ServerCommands } from './Commands.js';
/** @typedef {!import('./ResultRow/SeasonResultRow').SeasonResultRow} SeasonResultRow */
/** @typedef {!import('./ResultRow/ShowResultRow').ShowResultRow} ShowResultRow */

const Log = new ContextualLog('PlexClientState');
const Log = ContextualLog.Create('PlexClientState');

/**
* A class that contains two maps, mapping words of media titles
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/PlexUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SectionType } from '/Shared/PlexTypes.js';
/** @typedef {!import('./ClientDataExtensions').ClientMovieData} ClientMovieData */


const BaseLog = new ContextualLog('PlexUI');
const BaseLog = ContextualLog.Create('PlexUI');

/**
* OR-able modifier states
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/PurgedMarkerCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ContextualLog } from '/Shared/ConsoleLog.js';
/** @typedef {!import('/Shared/PlexTypes').MarkerAction} MarkerAction */


const Log = new ContextualLog('PurgedGroup');
const Log = ContextualLog.Create('PurgedGroup');

/** Enum defining the various states of initialization possible for a PurgedGroup
* @enum */
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/PurgedMarkerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import TableElements from './TableElements.js';
/** @typedef {!import('./PurgedMarkerCache').PurgedSection} PurgedSection */


const Log = new ContextualLog('PurgedManager');
const Log = ContextualLog.Create('PurgedManager');

/**
* A class that holds the information relevant for a button callback
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/BaseItemResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Tooltip from '../Tooltip.js';
/** @typedef {!import('./ResultRow').FocusNext} FocusNext */


const Log = new ContextualLog('BaseItemRow');
const Log = ContextualLog.Create('BaseItemRow');

/**
* Class with functionality shared between "base" media types, i.e. movies and episodes.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/BulkActionResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import BulkShiftOverlay from '../BulkShiftOverlay.js';
import ButtonCreator from '../ButtonCreator.js';
import { ContextualLog } from '/Shared/ConsoleLog.js';

const Log = new ContextualLog('BulkActionRow');
const Log = ContextualLog.Create('BulkActionRow');

/**
* A result row that offers bulk marker actions, like shifting everything X milliseconds.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/MovieResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Tooltip from '../Tooltip.js';
/** @typedef {!import('../ClientDataExtensions').ClientMovieData} ClientMovieData */


const Log = new ContextualLog('MovieRow');
const Log = ContextualLog.Create('MovieRow');

/**
* A result row for a single movie.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/ResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ThemeColors } from '../ThemeColors.js';

/** @typedef {{ scrollTo?: HTMLElement, focusTo?: HTMLElement}} FocusNext */

const Log = new ContextualLog('ResultRow');
const Log = ContextualLog.Create('ResultRow');

/**
* ResultRow is the base class that all result rows inherit from in some capacity.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/SeasonResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Tooltip from '../Tooltip.js';
/** @typedef {!import('/Shared/PlexTypes').SerializedMarkerData} SerializedMarkerData */


const Log = new ContextualLog('SeasonRow');
const Log = ContextualLog.Create('SeasonRow');

/**
* A result row for a single season of a show.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/SeasonResultRowBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PurgedMarkers } from '../PurgedMarkerManager.js';
/** @typedef {!import('/Shared/PlexTypes').SeasonData} SeasonData */


const Log = new ContextualLog('SeasonRowBase');
const Log = ContextualLog.Create('SeasonRowBase');

export class SeasonResultRowBase extends ResultRow {

Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/SectionOptionsResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SectionOptionsOverlay from '../SectionOptionsOverlay.js';
import { ThemeColors } from '../ThemeColors.js';
import Tooltip from '../Tooltip.js';

const Log = new ContextualLog('SectionOptionsRow');
const Log = ContextualLog.Create('SectionOptionsRow');

/**
* A section-wide header that is displayed no matter what the current view state is (beside the blank state).
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/ShowResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Tooltip from '../Tooltip.js';
/** @typedef {!import('/Shared/PlexTypes').ShowData} ShowData */


const Log = new ContextualLog('ShowRow');
const Log = ContextualLog.Create('ShowRow');

/**
* A result row for a single show in the library.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ResultRow/ShowResultRowBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { $$, buildNode, plural } from '../Common.js';
import { ContextualLog } from '/Shared/ConsoleLog.js';
import { PurgedMarkers } from '../PurgedMarkerManager.js';

const Log = new ContextualLog('ShowRowBase');
const Log = ContextualLog.Create('ShowRowBase');

/**
* Base class for a show result row, either a "real" one or a title placeholder.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/SVGHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { buildNode, buildNodeNS } from './Common.js';
/** @typedef {!import('./Icons').IconKeys} IconKeys */
/** @typedef {!import('./ThemeColors').ThemeColorKeys} ThemeColorKeys */

const Log = new ContextualLog('SVGCache');
const Log = ContextualLog.Create('SVGCache');

/**
* Subset of attributes that we expect might be set on an SVG
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/SectionOptionsOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Tooltip from './Tooltip.js';
/** @typedef {import('./Overlay').OverlayOptions} OverlayOptions */


const Log = new ContextualLog('SectionOps');
const Log = ContextualLog.Create('SectionOps');

class SectionOptionsOverlay {
/**
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ServerSettingsDialog/PathMappingsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ThemeColors } from '../ThemeColors.js';
import Tooltip from '../Tooltip.js';
import { ValidationInputDelay } from './ServerSettingsDialogConstants.js';

const Log = new ContextualLog('PathMappings');
const Log = ContextualLog.Create('PathMappings');

/**
* Encapsulates the UI of the editable path mappings table in the server settings dialog.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ServerSettingsDialog/ServerSettingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { PathMappingsTable } from './PathMappingsTable.js';
* @typedef {!import('/Shared/ServerConfig').TypedSetting<T>} TypedSetting<T>
* */

const Log = new ContextualLog('ServerConfig');
const Log = ContextualLog.Create('ServerConfig');

/**
* Elements IDs for authentication password fields. */
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/StickySettings/StickySettingsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContextualLog } from '/Shared/ConsoleLog.js';
import { CustomEvents } from '../CustomEvents.js';
import { StickySettingsType } from './StickySettingsTypes.js';

const Log = new ContextualLog('StickySettings');
const Log = ContextualLog.Create('StickySettings');

/**
* The protected fields of ConfigBase that are available to derived classes, but not available externally.
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/ThemeColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContextualLog } from '/Shared/ConsoleLog.js';

/** @typedef {!import('./Icons').IconKeys} IconKeys */

const Log = new ContextualLog('ThemeColors');
const Log = ContextualLog.Create('ThemeColors');

/**
* List of available theme colors. */
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/TimestampThumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Tooltip from './Tooltip.js';
/** @typedef {!import('./MarkerTableRow').MarkerRow} MarkerRow */
/** @typedef {!import('./ResultRow/BaseItemResultRow').BaseItemResultRow} BaseItemResultRow */

const Log = new ContextualLog('TimestampThumbs');
const Log = ContextualLog.Create('TimestampThumbs');

/**
* @typedef {{
Expand Down
2 changes: 1 addition & 1 deletion Client/Script/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { $, buildNode } from './Common.js';
import { Attributes } from './DataAttributes.js';
import { ContextualLog } from '/Shared/ConsoleLog.js';

const Log = new ContextualLog('Tooltip');
const Log = ContextualLog.Create('Tooltip');

const windowMargin = 10;

Expand Down
2 changes: 1 addition & 1 deletion Client/Script/VersionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ButtonCreator from './ButtonCreator.js';
/** @typedef {{[version: string]: { ignoreType : number, ignoreDate : number}}} UpdateCheckSettings */


const Log = new ContextualLog('VersionManager');
const Log = ContextualLog.Create('VersionManager');

/**
* Handles checking whether a new version of the app is available on GitHub
Expand Down
10 changes: 8 additions & 2 deletions Server/Authentication/AuthDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authSchemaUpgrades, authSchemaVersion } from './AuthenticationConstants
import { ContextualLog } from '../../Shared/ConsoleLog.js';
import SqliteDatabase from '../SqliteDatabase.js';

const Log = new ContextualLog('AuthDB');
const Log = ContextualLog.Create('AuthDB');

/** @readonly @type {AuthDatabase} */
export let AuthDB;
Expand Down Expand Up @@ -54,7 +54,13 @@ export class AuthDatabase {
const dbPath = join(dbRoot, 'auth.db');
const db = await SqliteDatabase.OpenDatabase(dbPath, true /*allowCreate*/);
this.#db = db;
const version = (await db.get('SELECT version FROM schema_version;'))?.version || 0;
let version = 0;
try {
version = (await db.get('SELECT version FROM schema_version;'))?.version || 0;
} catch (err) {
Log.info('Version information not found in auth DB, starting from scratch.');
}

await this.#upgradeSchema(version);
}

Expand Down
4 changes: 2 additions & 2 deletions Server/Authentication/SqliteSessionStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Store } from 'express-session';

import { AuthDB } from './AuthDatabase.js';
import { Config } from '../MarkerEditorConfig.js';
import { Config } from '../Config/MarkerEditorConfig.js';
import { ContextualLog } from '../../Shared/ConsoleLog.js';
import ServerError from '../ServerError.js';
import { SessionSecretTableName } from './AuthenticationConstants.js';
Expand All @@ -18,7 +18,7 @@ import { SessionSecretTableName } from './AuthenticationConstants.js';
/** @typedef {(err?: any) => void} EmptyStoreCallback */
/** @typedef {(err: any, session?: import('express-session').SessionData | null) => void} StoreCallbackWithSession */

const Log = new ContextualLog('SessionStore');
const Log = ContextualLog.Create('SessionStore');

const doNothing = () => {};

Expand Down
2 changes: 1 addition & 1 deletion Server/Commands/AuthenticationCommands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '../MarkerEditorConfig.js';
import { Config } from '../Config/MarkerEditorConfig.js';
import { PostCommands } from '../../Shared/PostCommands.js';
import { registerCommand } from './PostCommand.js';
import ServerError from '../ServerError.js';
Expand Down
2 changes: 1 addition & 1 deletion Server/Commands/ConfigCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ServerConfigState, ServerSettings } from '../../Shared/ServerConfig.js'

import { ServerEvents, waitForServerEvent } from '../ServerEvents.js';
import { ServerState, SetServerState } from '../ServerState.js';
import { Config } from '../MarkerEditorConfig.js';
import { Config } from '../Config/MarkerEditorConfig.js';
import { PostCommands } from '../../Shared/PostCommands.js';
import { registerCommand } from './PostCommand.js';
import { sendJsonSuccess } from '../ServerHelpers.js';
Expand Down
Loading

0 comments on commit c8f6e7c

Please sign in to comment.