Skip to content

Commit

Permalink
switch ott-server to import ott-common instead of referencing the…
Browse files Browse the repository at this point in the history
… relative file path (#1356)

* switch `ott-server` to import `ott-common` instead of referencing the relative file path

* fix lints

* Revert "fix lints"

This reverts commit 1da6370.

* fix auth middleware to not allow undefined tokens to be valid, fixes new type errors

* fix missing await

* fix lints and format
  • Loading branch information
dyc3 committed Feb 22, 2024
1 parent dcab0d9 commit 9435d66
Show file tree
Hide file tree
Showing 47 changed files with 132 additions and 115 deletions.
2 changes: 1 addition & 1 deletion server/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OttException } from "../common/exceptions";
import { OttException } from "ott-common/exceptions";
import { conf } from "./ott-config";

/**
Expand Down
6 changes: 3 additions & 3 deletions server/api/announce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { getLogger } from "../logger";
import { conf } from "../ott-config";
import express, { RequestHandler } from "express";
import { redisClient } from "../redisclient";
import { ANNOUNCEMENT_CHANNEL } from "../../common/constants";
import { OttResponseBody } from "../../common/models/rest-api";
import { OttException } from "../../common/exceptions";
import { ANNOUNCEMENT_CHANNEL } from "ott-common/constants";
import { OttResponseBody } from "ott-common/models/rest-api";
import { OttException } from "ott-common/exceptions";
import { BadApiArgumentException } from "../exceptions";

const router = express.Router();
Expand Down
4 changes: 2 additions & 2 deletions server/api/data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getLogger } from "../logger";
import { conf } from "../ott-config";
import express, { RequestHandler, ErrorRequestHandler } from "express";
import { OttApiResponseAddPreview, OttResponseBody } from "../../common/models/rest-api";
import { OttException } from "../../common/exceptions";
import { OttApiResponseAddPreview, OttResponseBody } from "ott-common/models/rest-api";
import { OttException } from "ott-common/exceptions";
import { BadApiArgumentException } from "../exceptions";
import InfoExtract from "../infoextractor";
import { consumeRateLimitPoints } from "../rate-limit";
Expand Down
2 changes: 1 addition & 1 deletion server/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getLogger } from "../logger";
import express from "express";
import { rateLimiter } from "../rate-limit";
import roommanager from "../roommanager";
import { RoomRequestType } from "../../common/models/messages";
import { RoomRequestType } from "ott-common/models/messages";
import usermanager from "../usermanager";
import faker from "faker";
import tokens from "../auth/tokens";
Expand Down
18 changes: 9 additions & 9 deletions server/api/room.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import _ from "lodash";
import { getLogger } from "../logger";
import roommanager from "../roommanager";
import { QueueMode, Visibility } from "../../common/models/types";
import { QueueMode, Visibility } from "ott-common/models/types";
import { consumeRateLimitPoints } from "../rate-limit";
import { BadApiArgumentException, FeatureDisabledException } from "../exceptions";
import { OttException } from "../../common/exceptions";
import { OttException } from "ott-common/exceptions";
import express, { RequestHandler, ErrorRequestHandler } from "express";
import clientmanager from "../clientmanager";
import {
ApplySettingsRequest,
RoomRequestType,
UndoRequest,
AddRequest,
} from "../../common/models/messages";
} from "ott-common/models/messages";
import storage from "../storage";
import { Grants } from "../../common/permissions";
import { Video } from "../../common/models/video.js";
import { ROOM_NAME_REGEX } from "../../common/constants";
import { Grants } from "ott-common/permissions";
import { Video } from "ott-common/models/video";
import { ROOM_NAME_REGEX } from "ott-common/constants";
import {
OttApiRequestAddToQueue,
OttApiRequestPatchRoom,
Expand All @@ -27,7 +27,7 @@ import {
OttApiResponseRoomCreate,
OttApiResponseRoomGenerate,
OttResponseBody,
} from "../../common/models/rest-api";
} from "ott-common/models/rest-api";
import { getApiKey } from "../admin";
import { v4 as uuidv4 } from "uuid";
import { counterHttpErrors } from "../metrics";
Expand Down Expand Up @@ -431,7 +431,7 @@ const addToQueue: RequestHandler<
} else {
throw new BadApiArgumentException("service,id", "missing");
}
await room.processUnauthorizedRequest(roomRequest, { token: req.token });
await room.processUnauthorizedRequest(roomRequest, { token: req.token! });
res.json({
success: true,
});
Expand All @@ -454,7 +454,7 @@ const removeFromQueue: RequestHandler<
type: RoomRequestType.RemoveRequest,
video: { service: req.body.service, id: req.body.id },
},
{ token: req.token }
{ token: req.token! }
);
res.json({
success: true,
Expand Down
6 changes: 3 additions & 3 deletions server/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import express from "express";
import tokens, { SessionInfo } from "./tokens";
import { uniqueNamesGenerator } from "unique-names-generator";
import passport from "passport";
import { AuthToken, MySession } from "../../common/models/types";
import { AuthToken, MySession } from "ott-common/models/types";
import nocache from "nocache";
import usermanager from "../usermanager";
import { OttException } from "../../common/exceptions";
import { OttException } from "ott-common/exceptions";
import { requireApiKey } from "../admin";

const router = express.Router();
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function authTokenMiddleware(
req.token = token;
}

if (!(await tokens.validate(req.token))) {
if (!req.token || !(await tokens.validate(req.token))) {
res.status(400).json({
success: false,
error: {
Expand Down
2 changes: 1 addition & 1 deletion server/auth/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from "crypto";
import { redisClient } from "../redisclient";
import { AuthToken } from "../../common/models/types";
import { AuthToken } from "ott-common/models/types";

const PREFIX = "auth";
const EXPIRATION_TIME = 14 * 24 * 60 * 60; // 14 days in seconds
Expand Down
6 changes: 3 additions & 3 deletions server/balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import WebSocket from "ws";

import { getLogger } from "./logger";
import { conf } from "./ott-config";
import { Result, err, ok, intoResult } from "../common/result";
import { AuthToken, ClientId } from "../common/models/types";
import { replacer } from "../common/serialize";
import { Result, err, ok, intoResult } from "ott-common/result";
import { AuthToken, ClientId } from "ott-common/models/types";
import { replacer } from "ott-common/serialize";
import { OttWebsocketError } from "ott-common/models/types";
import roommanager from "./roommanager";
import type { RoomListItem } from "./api/room";
Expand Down
6 changes: 3 additions & 3 deletions server/client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AuthToken, ClientId, ClientInfo, OttWebsocketError } from "../common/models/types";
import type { ClientMessage, ServerMessage } from "../common/models/messages";
import { AuthToken, ClientId, ClientInfo, OttWebsocketError } from "ott-common/models/types";
import type { ClientMessage, ServerMessage } from "ott-common/models/messages";
import WebSocket from "ws";
import { SessionInfo, setSessionInfo } from "./auth/tokens";
import { v4 as uuidv4 } from "uuid";
import EventEmitter from "events";
import { getLogger } from "./logger";
import { getSessionInfo } from "./auth/tokens";
import { BalancerConnection, BalancerConnectionReal } from "./balancer";
import { replacer } from "../common/serialize";
import { replacer } from "ott-common/serialize";

const log = getLogger("client");

Expand Down
10 changes: 5 additions & 5 deletions server/clientmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import {
ServerMessageSync,
ServerMessageUser,
ServerMessageYou,
} from "../common/models/messages";
} from "ott-common/models/messages";
import { ClientNotFoundInRoomException, MissingToken } from "./exceptions";
import { MySession, OttWebsocketError, AuthToken, ClientId } from "../common/models/types";
import { MySession, OttWebsocketError, AuthToken, ClientId } from "ott-common/models/types";
import roommanager from "./roommanager";
import { ANNOUNCEMENT_CHANNEL, ROOM_NAME_REGEX } from "../common/constants";
import { ANNOUNCEMENT_CHANNEL, ROOM_NAME_REGEX } from "ott-common/constants";
import tokens, { SessionInfo } from "./auth/tokens";
import { RoomStateSyncable } from "./room";
import { Gauge } from "prom-client";
import { replacer } from "../common/serialize";
import { replacer } from "ott-common/serialize";
import { Client, ClientJoinStatus, DirectClient, BalancerClient } from "./client";
import { BalancerConnection, MsgB2M, balancerManager, initBalancerConnections } from "./balancer";
import usermanager from "./usermanager";
import { OttException } from "../common/exceptions";
import { OttException } from "ott-common/exceptions";
import { conf } from "./ott-config";

const log = getLogger("clientmanager");
Expand Down
2 changes: 1 addition & 1 deletion server/exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { URL } from "url";
import { OttException } from "../common/exceptions";
import { OttException } from "ott-common/exceptions";

// export type OttException = UnsupportedServiceException | InvalidAddPreviewInputException | OutOfQuotaException | InvalidVideoIdException | FeatureDisabledException | UnsupportedMimeTypeException | LocalFileException | MissingMetadataException | IncompleteServiceAdapterException | PermissionDeniedException | ImpossiblePromotionException | InvalidRoleException | RoomNotFoundException | RoomAlreadyLoadedException | RoomNameTakenException | VideoAlreadyQueuedException | VideoNotFoundException | BadApiArgumentException

Expand Down
2 changes: 1 addition & 1 deletion server/express-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { User as UserAccount } from "./models/user";
import { AuthToken } from "./common/models/types";
import { AuthToken } from "ott-common/models/types";
import { SessionInfo } from "./auth/tokens";
import * as core from "express-serve-static-core";

Expand Down
4 changes: 2 additions & 2 deletions server/infoextractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
import { getLogger } from "./logger";
import { redisClient } from "./redisclient";
import { isSupportedMimeType } from "./mime";
import { Video, VideoId, VideoMetadata, VideoService } from "../common/models/video";
import { Video, VideoId, VideoMetadata, VideoService } from "ott-common/models/video";
import { ServiceAdapter } from "./serviceadapter";
import { OttException } from "../common/exceptions";
import { OttException } from "ott-common/exceptions";
import TubiAdapter from "./services/tubi";
import { Counter } from "prom-client";
import { conf } from "./ott-config";
Expand Down
2 changes: 1 addition & 1 deletion server/mailer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Result, ok, err } from "../common/result";
import { Result, ok, err } from "ott-common/result";
import Mailjet, { Client as MailjetClient } from "node-mailjet";
import { conf } from "./ott-config";
import { getLogger } from "./logger";
Expand Down
4 changes: 2 additions & 2 deletions server/models/cachedvideo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ALL_VIDEO_SERVICES } from "../../common/constants";
import { VideoService } from "../../common/models/video";
import { ALL_VIDEO_SERVICES } from "ott-common/constants";
import { VideoService } from "ott-common/models/video";
import { Sequelize, Model, DataTypes, Optional } from "sequelize";

interface CachedVideoAttributes {
Expand Down
8 changes: 4 additions & 4 deletions server/models/room.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Sequelize, Model, DataTypes, Optional } from "sequelize";
import { QueueMode, Visibility, Role, BehaviorOption } from "../../common/models/types";
import { QueueMode, Visibility, Role, BehaviorOption } from "ott-common/models/types";
import { User } from "./user";
import { ALL_SKIP_CATEGORIES, ROOM_NAME_REGEX } from "../../common/constants";
import type { OldRoleGrants, GrantMask } from "../../common/permissions";
import { QueueItem } from "../../common/models/video";
import { ALL_SKIP_CATEGORIES, ROOM_NAME_REGEX } from "ott-common/constants";
import type { OldRoleGrants, GrantMask } from "ott-common/permissions";
import { QueueItem } from "ott-common/models/video";
import { Category } from "sponsorblock-api";

export interface RoomAttributes {
Expand Down
4 changes: 2 additions & 2 deletions server/ott-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import validator from "validator";
import convict from "convict";
import toml from "toml";
import type winston from "winston";
import { ALL_VIDEO_SERVICES } from "../common/constants";
import { Result, err, ok, intoResult } from "../common/result";
import { ALL_VIDEO_SERVICES } from "ott-common/constants";
import { Result, err, ok, intoResult } from "ott-common/result";

convict.addParser({ extension: "toml", parse: toml.parse });

Expand Down
24 changes: 12 additions & 12 deletions server/room.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import permissions, { GrantMask, Grants } from "../common/permissions";
import permissions, { GrantMask, Grants } from "ott-common/permissions";
import { redisClient } from "./redisclient";
import { getLogger } from "./logger";
import winston from "winston";
Expand Down Expand Up @@ -28,7 +28,7 @@ import {
ShuffleRequest,
PlaybackSpeedRequest,
KickRequest,
} from "../common/models/messages";
} from "ott-common/models/messages";
import _ from "lodash";
import InfoExtract from "./infoextractor";
import usermanager from "./usermanager";
Expand All @@ -45,12 +45,12 @@ import {
RoomSettings,
AuthToken,
BehaviorOption,
} from "../common/models/types";
} from "ott-common/models/types";
import { User } from "./models/user";
import type { QueueItem, Video, VideoId } from "../common/models/video";
import type { QueueItem, Video, VideoId } from "ott-common/models/video";
import dayjs, { Dayjs } from "dayjs";
import type { PickFunctions } from "../common/typeutils";
import { replacer } from "../common/serialize";
import type { PickFunctions } from "ott-common/typeutils";
import { replacer } from "ott-common/serialize";
import {
ClientNotFoundInRoomException,
ImpossiblePromotionException,
Expand All @@ -59,19 +59,19 @@ import {
} from "./exceptions";
import storage from "./storage";
import tokens, { SessionInfo } from "./auth/tokens";
import { OttException } from "../common/exceptions";
import { OttException } from "ott-common/exceptions";
import { getSponsorBlock } from "./sponsorblock";
import { ResponseError as SponsorblockResponseError, Segment, Category } from "sponsorblock-api";
import { VideoQueue } from "./videoqueue";
import { Counter } from "prom-client";
import roommanager from "./roommanager";
import { calculateCurrentPosition } from "../common/timestamp";
import { RestoreQueueRequest } from "../common/models/messages";
import { countEligibleVoters, voteSkipThreshold } from "../common";
import { calculateCurrentPosition } from "ott-common/timestamp";
import { RestoreQueueRequest } from "ott-common/models/messages";
import { countEligibleVoters, voteSkipThreshold } from "ott-common";
import type { ClientManagerCommand } from "./clientmanager";
import { canKickUser } from "../common/userutils";
import { canKickUser } from "ott-common/userutils";
import { conf } from "./ott-config";
import { ALL_SKIP_CATEGORIES } from "../common/constants";
import { ALL_SKIP_CATEGORIES } from "ott-common/constants";

/**
* Represents a User from the Room's perspective.
Expand Down
8 changes: 4 additions & 4 deletions server/roommanager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Room, RoomState, RoomStateFromRedis, RoomStatePersistable } from "./room";
import { AuthToken, Role, RoomOptions, Visibility } from "../common/models/types";
import { AuthToken, Role, RoomOptions, Visibility } from "ott-common/models/types";
import _ from "lodash";
import { getLogger } from "./logger";
import { redisClient } from "./redisclient";
Expand All @@ -9,11 +9,11 @@ import {
RoomNameTakenException,
RoomNotFoundException,
} from "./exceptions";
import { RoomRequest, RoomRequestContext, ServerMessage } from "../common/models/messages";
import { RoomRequest, RoomRequestContext, ServerMessage } from "ott-common/models/messages";
import { Gauge } from "prom-client";
import { EventEmitter } from "events";
import { Result, ok, err } from "../common/result";
import { Grants } from "../common/permissions";
import { Result, ok, err } from "ott-common/result";
import { Grants } from "ott-common/permissions";
import type { ClientManagerCommand } from "./clientmanager";

export const log = getLogger("roommanager");
Expand Down
2 changes: 1 addition & 1 deletion server/serviceadapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */
import { Video, VideoId, VideoMetadata, VideoService } from "../common/models/video";
import { Video, VideoId, VideoMetadata, VideoService } from "ott-common/models/video";
import { IncompleteServiceAdapterException } from "./exceptions";
import { getLogger } from "./logger";

Expand Down
2 changes: 1 addition & 1 deletion server/services/dailymotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { URL } from "url";
import axios from "axios";
import { ServiceAdapter } from "../serviceadapter";
import { InvalidVideoIdException } from "../exceptions";
import { Video } from "../../common/models/video";
import { Video } from "ott-common/models/video";

export default class DailyMotionAdapter extends ServiceAdapter {
api = axios.create({
Expand Down
2 changes: 1 addition & 1 deletion server/services/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../exceptions";
import { getMimeType, isSupportedMimeType } from "../mime";
import { getLogger } from "../logger";
import { Video } from "../../common/models/video";
import { Video } from "ott-common/models/video";
import { DashMPD } from "@liveinstantly/dash-mpd-parser";
import axios from "axios";
import { parseIso8601Duration } from "./parsing/iso8601";
Expand Down
2 changes: 1 addition & 1 deletion server/services/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { getMimeType, isSupportedMimeType } from "../mime";
import { FfprobeStrategy, OnDiskPreviewFfprobe, RunFfprobe, StreamFfprobe } from "../ffprobe";
import { getLogger } from "../logger";
import { Video } from "../../common/models/video";
import { Video } from "ott-common/models/video";
import { conf } from "../ott-config";

const log = getLogger("direct");
Expand Down
2 changes: 1 addition & 1 deletion server/services/googledrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
InvalidVideoIdException,
OutOfQuotaException,
} from "../exceptions";
import { Video, VideoService } from "../../common/models/video";
import { Video, VideoService } from "ott-common/models/video";
import { getLogger } from "../logger";

const log = getLogger("googledrive");
Expand Down
4 changes: 2 additions & 2 deletions server/services/hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { ServiceAdapter } from "../serviceadapter";
import { LocalFileException, UnsupportedMimeTypeException } from "../exceptions";
import { getMimeType, isSupportedMimeType } from "../mime";
import { getLogger } from "../logger";
import { Video } from "../../common/models/video";
import { Video } from "ott-common/models/video";
import { Parser as M3u8Parser } from "m3u8-parser";
import axios from "axios";
import { OttException } from "../../common/exceptions";
import { OttException } from "ott-common/exceptions";

const log = getLogger("hls");

Expand Down
2 changes: 1 addition & 1 deletion server/services/peertube.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { type AxiosResponse } from "axios";
import { ServiceAdapter } from "../serviceadapter";
import { conf } from "../ott-config";
import { Video, VideoMetadata, VideoService } from "../../common/models/video";
import { Video, VideoMetadata, VideoService } from "ott-common/models/video";
import { InvalidVideoIdException } from "../exceptions";

interface PeertubeApiVideo {
Expand Down
2 changes: 1 addition & 1 deletion server/services/pluto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { URL } from "url";
import axios from "axios";
import { getLogger } from "../logger";
import { ServiceAdapter, VideoRequest } from "../serviceadapter";
import type { Video, VideoMetadata, VideoService } from "../../common/models/video";
import type { Video, VideoMetadata, VideoService } from "ott-common/models/video";
import { conf } from "../ott-config";
import { v1 as uuidv1 } from "uuid";
import { InvalidVideoIdException } from "../exceptions";
Expand Down
Loading

0 comments on commit 9435d66

Please sign in to comment.