diff --git a/common/package.json b/common/package.json index 97b9ee80c..fd7b64fe0 100644 --- a/common/package.json +++ b/common/package.json @@ -2,28 +2,8 @@ "name": "ott-common", "version": "0.10.0", "license": "AGPL-3.0-or-later", + "module": "es2020", "type": "module", - "main": "ts-out/index.js", - "module": "ts-out/index.js", - "files": [ - "ts-out/" - ], - "exports": { - ".": "./ts-out/index.js", - "./constants": "./ts-out/constants.js", - "./exceptions": "./ts-out/exceptions.js", - "./models/messages": "./ts-out/models/messages.js", - "./models/rest-api": "./ts-out/models/rest-api.js", - "./models/types": "./ts-out/models/types.js", - "./models/video": "./ts-out/models/video.js", - "./permissions": "./ts-out/permissions.js", - "./queueexport": "./ts-out/queueexport.js", - "./result": "./ts-out/result.js", - "./serialize": "./ts-out/serialize.js", - "./timestamp": "./ts-out/timestamp.js", - "./userutils": "./ts-out/userutils.js", - "./voteskip": "./ts-out/voteskip.js" - }, "scripts": { "build": "tsc", "lint": "tsc --noEmit && eslint --ext .js,.ts --fix .", diff --git a/deploy/monolith.Dockerfile b/deploy/monolith.Dockerfile index 007b25148..8d1917341 100644 --- a/deploy/monolith.Dockerfile +++ b/deploy/monolith.Dockerfile @@ -32,4 +32,4 @@ COPY deploy/$DEPLOY_TARGET.toml /usr/app/env/production.toml HEALTHCHECK --interval=30s --timeout=3s CMD ( curl -f http://localhost:8080/api/status || exit 1 ) # Start Server -CMD ["yarn", "workspace", "ott-server", "run", "start-lean"] +CMD ["yarn", "workspace", "ott-server", "run", "start-lean"] \ No newline at end of file diff --git a/server/admin.ts b/server/admin.ts index fe68b1e93..bd3282a18 100644 --- a/server/admin.ts +++ b/server/admin.ts @@ -1,4 +1,4 @@ -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../common/exceptions"; import { conf } from "./ott-config"; /** diff --git a/server/api/announce.ts b/server/api/announce.ts index e4b629fae..340b96a47 100644 --- a/server/api/announce.ts +++ b/server/api/announce.ts @@ -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 "ott-common/constants"; -import { OttResponseBody } from "ott-common/models/rest-api"; -import { OttException } from "ott-common/exceptions"; +import { ANNOUNCEMENT_CHANNEL } from "../../common/constants"; +import { OttResponseBody } from "../../common/models/rest-api"; +import { OttException } from "../../common/exceptions"; import { BadApiArgumentException } from "../exceptions"; const router = express.Router(); diff --git a/server/api/data.ts b/server/api/data.ts index 11a37f74b..7b6f02284 100644 --- a/server/api/data.ts +++ b/server/api/data.ts @@ -1,8 +1,8 @@ import { getLogger } from "../logger"; import { conf } from "../ott-config"; import express, { RequestHandler, ErrorRequestHandler } from "express"; -import { OttApiResponseAddPreview, OttResponseBody } from "ott-common/models/rest-api"; -import { OttException } from "ott-common/exceptions"; +import { OttApiResponseAddPreview, OttResponseBody } from "../../common/models/rest-api"; +import { OttException } from "../../common/exceptions"; import { BadApiArgumentException } from "../exceptions"; import InfoExtract from "../infoextractor"; import { consumeRateLimitPoints } from "../rate-limit"; diff --git a/server/api/dev.ts b/server/api/dev.ts index bdfdc6ed5..2dbcce830 100644 --- a/server/api/dev.ts +++ b/server/api/dev.ts @@ -2,7 +2,7 @@ import { getLogger } from "../logger"; import express from "express"; import { rateLimiter } from "../rate-limit"; import roommanager from "../roommanager"; -import { RoomRequestType } from "ott-common/models/messages"; +import { RoomRequestType } from "../../common/models/messages"; import usermanager from "../usermanager"; import faker from "faker"; import tokens from "../auth/tokens"; diff --git a/server/api/room.ts b/server/api/room.ts index 29bf3d25c..2698ca52b 100644 --- a/server/api/room.ts +++ b/server/api/room.ts @@ -1,10 +1,10 @@ import _ from "lodash"; import { getLogger } from "../logger"; import roommanager from "../roommanager"; -import { QueueMode, Visibility } from "ott-common/models/types"; +import { QueueMode, Visibility } from "../../common/models/types"; import { consumeRateLimitPoints } from "../rate-limit"; import { BadApiArgumentException, FeatureDisabledException } from "../exceptions"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../../common/exceptions"; import express, { RequestHandler, ErrorRequestHandler } from "express"; import clientmanager from "../clientmanager"; import { @@ -12,11 +12,11 @@ import { RoomRequestType, UndoRequest, AddRequest, -} from "ott-common/models/messages"; +} from "../../common/models/messages"; import storage from "../storage"; -import { Grants } from "ott-common/permissions"; -import { Video } from "ott-common/models/video"; -import { ROOM_NAME_REGEX } from "ott-common/constants"; +import { Grants } from "../../common/permissions"; +import { Video } from "../../common/models/video.js"; +import { ROOM_NAME_REGEX } from "../../common/constants"; import { OttApiRequestAddToQueue, OttApiRequestPatchRoom, @@ -27,7 +27,7 @@ import { OttApiResponseRoomCreate, OttApiResponseRoomGenerate, OttResponseBody, -} from "ott-common/models/rest-api"; +} from "../../common/models/rest-api"; import { getApiKey } from "../admin"; import { v4 as uuidv4 } from "uuid"; import { counterHttpErrors } from "../metrics"; @@ -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, }); @@ -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, diff --git a/server/auth/index.ts b/server/auth/index.ts index 37e61323b..84bee1320 100644 --- a/server/auth/index.ts +++ b/server/auth/index.ts @@ -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 "ott-common/models/types"; +import { AuthToken, MySession } from "../../common/models/types"; import nocache from "nocache"; import usermanager from "../usermanager"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../../common/exceptions"; import { requireApiKey } from "../admin"; const router = express.Router(); @@ -55,7 +55,7 @@ export async function authTokenMiddleware( req.token = token; } - if (!req.token || !(await tokens.validate(req.token))) { + if (!(await tokens.validate(req.token))) { res.status(400).json({ success: false, error: { diff --git a/server/auth/tokens.ts b/server/auth/tokens.ts index ed517c274..8ae69f235 100644 --- a/server/auth/tokens.ts +++ b/server/auth/tokens.ts @@ -1,6 +1,6 @@ import crypto from "crypto"; import { redisClient } from "../redisclient"; -import { AuthToken } from "ott-common/models/types"; +import { AuthToken } from "../../common/models/types"; const PREFIX = "auth"; const EXPIRATION_TIME = 14 * 24 * 60 * 60; // 14 days in seconds diff --git a/server/balancer.ts b/server/balancer.ts index c9472fbb0..4b02f9c04 100644 --- a/server/balancer.ts +++ b/server/balancer.ts @@ -4,9 +4,9 @@ import WebSocket from "ws"; import { getLogger } from "./logger"; import { conf } from "./ott-config"; -import { Result, err, ok, intoResult } from "ott-common/result"; -import { AuthToken, ClientId } from "ott-common/models/types"; -import { replacer } from "ott-common/serialize"; +import { Result, err, ok, intoResult } from "../common/result"; +import { AuthToken, ClientId } from "../common/models/types"; +import { replacer } from "../common/serialize"; import { OttWebsocketError } from "ott-common/models/types"; import roommanager from "./roommanager"; import type { RoomListItem } from "./api/room"; diff --git a/server/client.ts b/server/client.ts index b170c84f7..00915bdb5 100644 --- a/server/client.ts +++ b/server/client.ts @@ -1,5 +1,5 @@ -import { AuthToken, ClientId, ClientInfo, OttWebsocketError } from "ott-common/models/types"; -import type { ClientMessage, ServerMessage } from "ott-common/models/messages"; +import { AuthToken, ClientId, ClientInfo, OttWebsocketError } from "../common/models/types"; +import type { ClientMessage, ServerMessage } from "../common/models/messages"; import WebSocket from "ws"; import { SessionInfo, setSessionInfo } from "./auth/tokens"; import { v4 as uuidv4 } from "uuid"; @@ -7,7 +7,7 @@ import EventEmitter from "events"; import { getLogger } from "./logger"; import { getSessionInfo } from "./auth/tokens"; import { BalancerConnection, BalancerConnectionReal } from "./balancer"; -import { replacer } from "ott-common/serialize"; +import { replacer } from "../common/serialize"; const log = getLogger("client"); diff --git a/server/clientmanager.ts b/server/clientmanager.ts index 334ddf018..801e7a0db 100644 --- a/server/clientmanager.ts +++ b/server/clientmanager.ts @@ -14,19 +14,19 @@ import { ServerMessageSync, ServerMessageUser, ServerMessageYou, -} from "ott-common/models/messages"; +} from "../common/models/messages"; import { ClientNotFoundInRoomException, MissingToken } from "./exceptions"; -import { MySession, OttWebsocketError, AuthToken, ClientId } from "ott-common/models/types"; +import { MySession, OttWebsocketError, AuthToken, ClientId } from "../common/models/types"; import roommanager from "./roommanager"; -import { ANNOUNCEMENT_CHANNEL, ROOM_NAME_REGEX } from "ott-common/constants"; +import { ANNOUNCEMENT_CHANNEL, ROOM_NAME_REGEX } from "../common/constants"; import tokens, { SessionInfo } from "./auth/tokens"; import { RoomStateSyncable } from "./room"; import { Gauge } from "prom-client"; -import { replacer } from "ott-common/serialize"; +import { replacer } from "../common/serialize"; import { Client, ClientJoinStatus, DirectClient, BalancerClient } from "./client"; import { BalancerConnection, MsgB2M, balancerManager, initBalancerConnections } from "./balancer"; import usermanager from "./usermanager"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../common/exceptions"; import { conf } from "./ott-config"; const log = getLogger("clientmanager"); diff --git a/server/exceptions.ts b/server/exceptions.ts index a61e68122..f01123e7e 100644 --- a/server/exceptions.ts +++ b/server/exceptions.ts @@ -1,5 +1,5 @@ import { URL } from "url"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../common/exceptions"; // export type OttException = UnsupportedServiceException | InvalidAddPreviewInputException | OutOfQuotaException | InvalidVideoIdException | FeatureDisabledException | UnsupportedMimeTypeException | LocalFileException | MissingMetadataException | IncompleteServiceAdapterException | PermissionDeniedException | ImpossiblePromotionException | InvalidRoleException | RoomNotFoundException | RoomAlreadyLoadedException | RoomNameTakenException | VideoAlreadyQueuedException | VideoNotFoundException | BadApiArgumentException diff --git a/server/express-types.d.ts b/server/express-types.d.ts index e5cc6ebde..5f6e17cd7 100644 --- a/server/express-types.d.ts +++ b/server/express-types.d.ts @@ -1,5 +1,5 @@ import { User as UserAccount } from "./models/user"; -import { AuthToken } from "ott-common/models/types"; +import { AuthToken } from "./common/models/types"; import { SessionInfo } from "./auth/tokens"; import * as core from "express-serve-static-core"; diff --git a/server/infoextractor.ts b/server/infoextractor.ts index ad1e63e96..6a0a6deb4 100644 --- a/server/infoextractor.ts +++ b/server/infoextractor.ts @@ -18,9 +18,9 @@ import { import { getLogger } from "./logger"; import { redisClient } from "./redisclient"; import { isSupportedMimeType } from "./mime"; -import { Video, VideoId, VideoMetadata, VideoService } from "ott-common/models/video"; +import { Video, VideoId, VideoMetadata, VideoService } from "../common/models/video"; import { ServiceAdapter } from "./serviceadapter"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../common/exceptions"; import TubiAdapter from "./services/tubi"; import { Counter } from "prom-client"; import { conf } from "./ott-config"; diff --git a/server/mailer.ts b/server/mailer.ts index 7ecaa1334..b79311275 100644 --- a/server/mailer.ts +++ b/server/mailer.ts @@ -1,4 +1,4 @@ -import { Result, ok, err } from "ott-common/result"; +import { Result, ok, err } from "../common/result"; import Mailjet, { Client as MailjetClient } from "node-mailjet"; import { conf } from "./ott-config"; import { getLogger } from "./logger"; diff --git a/server/models/cachedvideo.ts b/server/models/cachedvideo.ts index 47161a806..00c4b422a 100644 --- a/server/models/cachedvideo.ts +++ b/server/models/cachedvideo.ts @@ -1,5 +1,5 @@ -import { ALL_VIDEO_SERVICES } from "ott-common/constants"; -import { VideoService } from "ott-common/models/video"; +import { ALL_VIDEO_SERVICES } from "../../common/constants"; +import { VideoService } from "../../common/models/video"; import { Sequelize, Model, DataTypes, Optional } from "sequelize"; interface CachedVideoAttributes { diff --git a/server/models/room.ts b/server/models/room.ts index ad197827d..44cf05486 100644 --- a/server/models/room.ts +++ b/server/models/room.ts @@ -1,9 +1,9 @@ import { Sequelize, Model, DataTypes, Optional } from "sequelize"; -import { QueueMode, Visibility, Role, BehaviorOption } from "ott-common/models/types"; +import { QueueMode, Visibility, Role, BehaviorOption } from "../../common/models/types"; import { User } from "./user"; -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 { ALL_SKIP_CATEGORIES, ROOM_NAME_REGEX } from "../../common/constants"; +import type { OldRoleGrants, GrantMask } from "../../common/permissions"; +import { QueueItem } from "../../common/models/video"; import { Category } from "sponsorblock-api"; export interface RoomAttributes { diff --git a/server/ott-config.ts b/server/ott-config.ts index e67195901..14a450f66 100644 --- a/server/ott-config.ts +++ b/server/ott-config.ts @@ -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 "ott-common/constants"; -import { Result, err, ok, intoResult } from "ott-common/result"; +import { ALL_VIDEO_SERVICES } from "../common/constants"; +import { Result, err, ok, intoResult } from "../common/result"; convict.addParser({ extension: "toml", parse: toml.parse }); diff --git a/server/package.json b/server/package.json index 6003e6c3a..c092066bb 100644 --- a/server/package.json +++ b/server/package.json @@ -6,7 +6,7 @@ "module": "esnext", "scripts": { "start": "node --experimental-specifier-resolution=node --loader ts-node/esm app.ts", - "start-lean": "node --experimental-specifier-resolution=node --optimize-for-size --max-old-space-size=200 ts-out/app.js", + "start-lean": "node --experimental-specifier-resolution=node --optimize-for-size --max-old-space-size=200 ts-out/server/app.js", "debug": "nodemon --exec node --experimental-specifier-resolution=node --loader ts-node/esm --ignore 'tests/*' --inspect -e ts,js app.ts", "build": "tsc", "lint": "tsc --noEmit && eslint --fix .", diff --git a/server/room.ts b/server/room.ts index 61713faa6..8619b3277 100644 --- a/server/room.ts +++ b/server/room.ts @@ -1,4 +1,4 @@ -import permissions, { GrantMask, Grants } from "ott-common/permissions"; +import permissions, { GrantMask, Grants } from "../common/permissions"; import { redisClient } from "./redisclient"; import { getLogger } from "./logger"; import winston from "winston"; @@ -28,7 +28,7 @@ import { ShuffleRequest, PlaybackSpeedRequest, KickRequest, -} from "ott-common/models/messages"; +} from "../common/models/messages"; import _ from "lodash"; import InfoExtract from "./infoextractor"; import usermanager from "./usermanager"; @@ -45,12 +45,12 @@ import { RoomSettings, AuthToken, BehaviorOption, -} from "ott-common/models/types"; +} from "../common/models/types"; import { User } from "./models/user"; -import type { QueueItem, Video, VideoId } from "ott-common/models/video"; +import type { QueueItem, Video, VideoId } from "../common/models/video"; import dayjs, { Dayjs } from "dayjs"; -import type { PickFunctions } from "ott-common/typeutils"; -import { replacer } from "ott-common/serialize"; +import type { PickFunctions } from "../common/typeutils"; +import { replacer } from "../common/serialize"; import { ClientNotFoundInRoomException, ImpossiblePromotionException, @@ -59,19 +59,19 @@ import { } from "./exceptions"; import storage from "./storage"; import tokens, { SessionInfo } from "./auth/tokens"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../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 "ott-common/timestamp"; -import { RestoreQueueRequest } from "ott-common/models/messages"; -import { countEligibleVoters, voteSkipThreshold } from "ott-common"; +import { calculateCurrentPosition } from "../common/timestamp"; +import { RestoreQueueRequest } from "../common/models/messages"; +import { countEligibleVoters, voteSkipThreshold } from "../common"; import type { ClientManagerCommand } from "./clientmanager"; -import { canKickUser } from "ott-common/userutils"; +import { canKickUser } from "../common/userutils"; import { conf } from "./ott-config"; -import { ALL_SKIP_CATEGORIES } from "ott-common/constants"; +import { ALL_SKIP_CATEGORIES } from "../common/constants"; /** * Represents a User from the Room's perspective. diff --git a/server/roommanager.ts b/server/roommanager.ts index 37f647ac0..6fccabd2d 100644 --- a/server/roommanager.ts +++ b/server/roommanager.ts @@ -1,5 +1,5 @@ import { Room, RoomState, RoomStateFromRedis, RoomStatePersistable } from "./room"; -import { AuthToken, Role, RoomOptions, Visibility } from "ott-common/models/types"; +import { AuthToken, Role, RoomOptions, Visibility } from "../common/models/types"; import _ from "lodash"; import { getLogger } from "./logger"; import { redisClient } from "./redisclient"; @@ -9,11 +9,11 @@ import { RoomNameTakenException, RoomNotFoundException, } from "./exceptions"; -import { RoomRequest, RoomRequestContext, ServerMessage } from "ott-common/models/messages"; +import { RoomRequest, RoomRequestContext, ServerMessage } from "../common/models/messages"; import { Gauge } from "prom-client"; import { EventEmitter } from "events"; -import { Result, ok, err } from "ott-common/result"; -import { Grants } from "ott-common/permissions"; +import { Result, ok, err } from "../common/result"; +import { Grants } from "../common/permissions"; import type { ClientManagerCommand } from "./clientmanager"; export const log = getLogger("roommanager"); diff --git a/server/serviceadapter.ts b/server/serviceadapter.ts index 06c5f809a..4f3e68897 100644 --- a/server/serviceadapter.ts +++ b/server/serviceadapter.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable no-unused-vars */ -import { Video, VideoId, VideoMetadata, VideoService } from "ott-common/models/video"; +import { Video, VideoId, VideoMetadata, VideoService } from "../common/models/video"; import { IncompleteServiceAdapterException } from "./exceptions"; import { getLogger } from "./logger"; diff --git a/server/services/dailymotion.ts b/server/services/dailymotion.ts index c6f5f792e..80e11c901 100644 --- a/server/services/dailymotion.ts +++ b/server/services/dailymotion.ts @@ -2,7 +2,7 @@ import { URL } from "url"; import axios from "axios"; import { ServiceAdapter } from "../serviceadapter"; import { InvalidVideoIdException } from "../exceptions"; -import { Video } from "ott-common/models/video"; +import { Video } from "../../common/models/video"; export default class DailyMotionAdapter extends ServiceAdapter { api = axios.create({ diff --git a/server/services/dash.ts b/server/services/dash.ts index bf9122b65..970482223 100644 --- a/server/services/dash.ts +++ b/server/services/dash.ts @@ -8,7 +8,7 @@ import { } from "../exceptions"; import { getMimeType, isSupportedMimeType } from "../mime"; import { getLogger } from "../logger"; -import { Video } from "ott-common/models/video"; +import { Video } from "../../common/models/video"; import { DashMPD } from "@liveinstantly/dash-mpd-parser"; import axios from "axios"; import { parseIso8601Duration } from "./parsing/iso8601"; diff --git a/server/services/direct.ts b/server/services/direct.ts index ead8cc86a..87d01e867 100644 --- a/server/services/direct.ts +++ b/server/services/direct.ts @@ -9,7 +9,7 @@ import { import { getMimeType, isSupportedMimeType } from "../mime"; import { FfprobeStrategy, OnDiskPreviewFfprobe, RunFfprobe, StreamFfprobe } from "../ffprobe"; import { getLogger } from "../logger"; -import { Video } from "ott-common/models/video"; +import { Video } from "../../common/models/video"; import { conf } from "../ott-config"; const log = getLogger("direct"); diff --git a/server/services/googledrive.ts b/server/services/googledrive.ts index 83168d574..b3d7bc3ec 100644 --- a/server/services/googledrive.ts +++ b/server/services/googledrive.ts @@ -6,7 +6,7 @@ import { InvalidVideoIdException, OutOfQuotaException, } from "../exceptions"; -import { Video, VideoService } from "ott-common/models/video"; +import { Video, VideoService } from "../../common/models/video"; import { getLogger } from "../logger"; const log = getLogger("googledrive"); diff --git a/server/services/hls.ts b/server/services/hls.ts index dfd88ccd3..2c0e2b44f 100644 --- a/server/services/hls.ts +++ b/server/services/hls.ts @@ -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 "ott-common/models/video"; +import { Video } from "../../common/models/video"; import { Parser as M3u8Parser } from "m3u8-parser"; import axios from "axios"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../../common/exceptions"; const log = getLogger("hls"); diff --git a/server/services/peertube.ts b/server/services/peertube.ts index e2ba50006..c8473387e 100644 --- a/server/services/peertube.ts +++ b/server/services/peertube.ts @@ -1,7 +1,7 @@ import axios, { type AxiosResponse } from "axios"; import { ServiceAdapter } from "../serviceadapter"; import { conf } from "../ott-config"; -import { Video, VideoMetadata, VideoService } from "ott-common/models/video"; +import { Video, VideoMetadata, VideoService } from "../../common/models/video"; import { InvalidVideoIdException } from "../exceptions"; interface PeertubeApiVideo { diff --git a/server/services/pluto.ts b/server/services/pluto.ts index 5771a81d1..799a16de6 100644 --- a/server/services/pluto.ts +++ b/server/services/pluto.ts @@ -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 "ott-common/models/video"; +import type { Video, VideoMetadata, VideoService } from "../../common/models/video"; import { conf } from "../ott-config"; import { v1 as uuidv1 } from "uuid"; import { InvalidVideoIdException } from "../exceptions"; diff --git a/server/services/reddit.ts b/server/services/reddit.ts index 4168ea2a2..dd25c3527 100644 --- a/server/services/reddit.ts +++ b/server/services/reddit.ts @@ -2,7 +2,7 @@ import { URL } from "url"; import axios from "axios"; import { ServiceAdapter, VideoRequest } from "../serviceadapter"; import { getLogger } from "../logger"; -import { Video, VideoMetadata } from "ott-common/models/video"; +import { Video, VideoMetadata } from "../../common/models/video"; import { InvalidVideoIdException } from "../exceptions"; import infoextractor from "../infoextractor"; import { conf } from "../ott-config"; diff --git a/server/services/tubi.ts b/server/services/tubi.ts index 77b2294ae..f5e122573 100644 --- a/server/services/tubi.ts +++ b/server/services/tubi.ts @@ -2,7 +2,7 @@ import { URL } from "url"; import axios from "axios"; import { getLogger } from "../logger"; import { ServiceAdapter, VideoRequest } from "../serviceadapter"; -import { Video, VideoMetadata, VideoService } from "ott-common/models/video"; +import { Video, VideoMetadata, VideoService } from "../../common/models/video"; import { conf } from "../ott-config"; const log = getLogger("tubi"); diff --git a/server/services/vimeo.ts b/server/services/vimeo.ts index 4f7aec107..b137fd37e 100644 --- a/server/services/vimeo.ts +++ b/server/services/vimeo.ts @@ -2,7 +2,7 @@ import { URL } from "url"; import axios, { AxiosResponse } from "axios"; import { ServiceAdapter } from "../serviceadapter"; import { InvalidVideoIdException } from "../exceptions"; -import { Video } from "ott-common/models/video"; +import { Video } from "../../common/models/video"; import { getLogger } from "../logger"; const log = getLogger("vimeo"); diff --git a/server/services/youtube.ts b/server/services/youtube.ts index 30fecc4d9..4ab2b924c 100644 --- a/server/services/youtube.ts +++ b/server/services/youtube.ts @@ -11,9 +11,9 @@ import { VideoNotFoundException, } from "../exceptions"; import { getLogger } from "../logger"; -import { Video, VideoId, VideoMetadata } from "ott-common/models/video"; +import { Video, VideoId, VideoMetadata } from "../../common/models/video"; import storage from "../storage"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../../common/exceptions"; import { conf } from "../ott-config"; import { parseIso8601Duration } from "./parsing/iso8601"; diff --git a/server/storage/cachedvideo.ts b/server/storage/cachedvideo.ts index 1f36c3fe1..701ba2b60 100644 --- a/server/storage/cachedvideo.ts +++ b/server/storage/cachedvideo.ts @@ -1,7 +1,7 @@ import dayjs from "dayjs"; import { CachedVideo as DbCachedVideo } from "../models"; import Sequelize from "sequelize"; -import type { Video, VideoMetadata, VideoService } from "ott-common/models/video"; +import type { Video, VideoMetadata, VideoService } from "../../common/models/video"; import { getLogger } from "../logger"; import _ from "lodash"; import { CachedVideoCreationAttributes, CachedVideo } from "../models/cachedvideo"; diff --git a/server/storage/room.ts b/server/storage/room.ts index e11ed7684..89f1b1e65 100644 --- a/server/storage/room.ts +++ b/server/storage/room.ts @@ -1,9 +1,9 @@ import { Room as DbRoomModel, User as UserModel } from "../models"; import { Room as DbRoom, RoomAttributes } from "../models/room"; -import { Role, RoomOptions } from "ott-common/models/types"; +import { Role, RoomOptions } from "../../common/models/types"; import { getLogger } from "../logger"; import Sequelize from "sequelize"; -import permissions from "ott-common/permissions"; +import permissions from "../../common/permissions"; import type { RoomStatePersistable } from "../room"; import _ from "lodash"; diff --git a/server/tests/unit/api/accountrecovery.spec.ts b/server/tests/unit/api/accountrecovery.spec.ts index a97a469db..41fb1fe3e 100644 --- a/server/tests/unit/api/accountrecovery.spec.ts +++ b/server/tests/unit/api/accountrecovery.spec.ts @@ -17,7 +17,7 @@ import { User } from "../../../models/user"; import { MockMailer } from "server/mailer"; import { conf } from "../../../ott-config"; import { redisClient } from "../../../redisclient"; -import { OttApiRequestAccountRecoveryVerify } from "ott-common/models/rest-api"; +import { OttApiRequestAccountRecoveryVerify } from "common/models/rest-api"; describe("Account Recovery", () => { let token; diff --git a/server/tests/unit/api/announcement.spec.ts b/server/tests/unit/api/announcement.spec.ts index e38f4ec45..fab05319f 100644 --- a/server/tests/unit/api/announcement.spec.ts +++ b/server/tests/unit/api/announcement.spec.ts @@ -12,10 +12,10 @@ import { import request from "supertest"; import { main } from "../../../app"; import { setApiKey } from "../../../admin"; -import { ANNOUNCEMENT_CHANNEL } from "ott-common/constants"; +import { ANNOUNCEMENT_CHANNEL } from "../../../../common/constants"; import { redisClient } from "../../../redisclient"; import tokens, { type SessionInfo } from "../../../auth/tokens"; -import type { AuthToken } from "ott-common/models/types"; +import type { AuthToken } from "../../../../common/models/types"; const TEST_API_KEY = "TESTAPIKEY"; diff --git a/server/tests/unit/api/room.spec.ts b/server/tests/unit/api/room.spec.ts index 5da048eb0..7dfc3ed15 100644 --- a/server/tests/unit/api/room.spec.ts +++ b/server/tests/unit/api/room.spec.ts @@ -10,7 +10,7 @@ import { MockInstance, } from "vitest"; import _ from "lodash"; -import { AuthToken, QueueMode, Visibility } from "ott-common/models/types"; +import { QueueMode, Visibility } from "../../../../common/models/types"; import request from "supertest"; import tokens from "../../../../server/auth/tokens"; import roommanager from "../../../../server/roommanager"; @@ -18,7 +18,7 @@ import { RoomNotFoundException } from "../../../../server/exceptions"; import { main } from "../../../app"; import { Room as RoomModel, User as UserModel } from "../../../models"; import usermanager from "../../../usermanager"; -import { OttApiRequestRoomCreate } from "ott-common/models/rest-api"; +import { OttApiRequestRoomCreate } from "common/models/rest-api"; import { conf } from "../../../../server/ott-config"; import { User } from "../../../models/user"; @@ -81,14 +81,10 @@ expect.extend({ describe("Room API", () => { let app; let owner: User; - let token: AuthToken; beforeAll(async () => { app = (await main()).app; - const auth = await request(app).get("/api/auth/grant"); - token = auth.body.token; - owner = await usermanager.registerUser({ email: "owner@localhost", username: "owner", @@ -97,7 +93,7 @@ describe("Room API", () => { }); afterAll(async () => { - await owner?.destroy(); + owner?.destroy(); }); describe("GET /room/:name", () => { @@ -137,7 +133,6 @@ describe("Room API", () => { let resp = await request(app) .get("/api/room/test1") - .auth(token, { type: "bearer" }) .set({ Authorization: "Bearer foobar" }) .expect("Content-Type", /json/) .expect(200); @@ -156,7 +151,6 @@ describe("Room API", () => { it("should fail if the room does not exist", async () => { let resp = await request(app) .get("/api/room/test1") - .auth(token, { type: "bearer" }) .expect("Content-Type", /json/) .expect(404); expect(resp.body.success).toEqual(false); @@ -200,7 +194,6 @@ describe("Room API", () => { async (visibility: Visibility) => { let resp = await request(app) .post("/api/room/create") - .auth(token, { type: "bearer" }) .send({ name: "test1", isTemporary: true, visibility: visibility }) .expect("Content-Type", /json/) .expect(201); @@ -273,7 +266,6 @@ describe("Room API", () => { ])("should fail to create room for validation errors: %s", async (error, body) => { let resp = await request(app) .post("/api/room/create") - .auth(token, { type: "bearer" }) .send(body) .expect("Content-Type", /json/) .expect(400); @@ -287,7 +279,6 @@ describe("Room API", () => { it("should create permanent room without owner", async () => { let resp = await request(app) .post("/api/room/create") - .auth(token, { type: "bearer" }) .send({ name: "testnoowner", isTemporary: false }) .expect("Content-Type", /json/) .expect(201); @@ -307,7 +298,6 @@ describe("Room API", () => { }); let resp = await request(app) .post("/api/room/create") - .auth(token, { type: "bearer" }) .send({ name: "testowner" }) .expect("Content-Type", /json/) .expect(201); @@ -338,7 +328,6 @@ describe("Room API", () => { const resp = await request(app) .post(path) - .auth(token, { type: "bearer" }) .send(body) .expect("Content-Type", /json/) .expect(403); @@ -391,7 +380,7 @@ describe("Room API", () => { ])("should fail to modify room for validation errors: %s", async (error, body) => { let resp = await request(app) .patch("/api/room/foo") - .auth(token, { type: "bearer" }) + .set({ Authorization: "Bearer foobar" }) .send(body) .expect("Content-Type", /json/) .expect(400); @@ -434,7 +423,7 @@ describe("Room API", () => { async (requestAutoSkipSegmentCategories, savedAutoSkipSegmentCategories) => { let resp = await request(app) .patch("/api/room/foo") - .auth(token, { type: "bearer" }) + .set({ Authorization: "Bearer foobar" }) .send({ autoSkipSegmentCategories: requestAutoSkipSegmentCategories, }) diff --git a/server/tests/unit/api/user.spec.ts b/server/tests/unit/api/user.spec.ts index 4634b1702..8653babc4 100644 --- a/server/tests/unit/api/user.spec.ts +++ b/server/tests/unit/api/user.spec.ts @@ -16,7 +16,7 @@ import usermanager from "../../../usermanager"; import { User as UserModel } from "../../../models"; import { conf } from "../../../ott-config"; import { User } from "../../../models/user"; -import { AuthToken } from "ott-common/models/types"; +import { AuthToken } from "common/models/types"; describe("User API", () => { let token; diff --git a/server/tests/unit/clientmanager.spec.ts b/server/tests/unit/clientmanager.spec.ts index 6fd9b637b..1fff37104 100644 --- a/server/tests/unit/clientmanager.spec.ts +++ b/server/tests/unit/clientmanager.spec.ts @@ -9,9 +9,9 @@ import { balancerManager, } from "../../balancer"; import { BalancerClient, Client } from "../../client"; -import { OttWebsocketError } from "ott-common/models/types"; +import { OttWebsocketError } from "common/models/types"; import { buildClients } from "../../redisclient"; -import { Result, ok } from "ott-common/result"; +import { Result, ok } from "../../../common/result"; import roommanager from "../../roommanager"; import { loadModels } from "../../models"; import type { Request } from "express"; diff --git a/server/tests/unit/infoextractor.spec.ts b/server/tests/unit/infoextractor.spec.ts index fce6a915a..ad3181d3f 100644 --- a/server/tests/unit/infoextractor.spec.ts +++ b/server/tests/unit/infoextractor.spec.ts @@ -19,7 +19,7 @@ import { buildClients, redisClient } from "../../redisclient"; import _ from "lodash"; import { loadModels } from "../../models"; import { loadConfigFile, conf } from "../../ott-config"; -import { Video, VideoMetadata, VideoService } from "ott-common/models/video"; +import { Video, VideoMetadata, VideoService } from "../../../common/models/video"; class TestAdapter extends ServiceAdapter { get serviceId(): VideoService { diff --git a/server/tests/unit/room.spec.ts b/server/tests/unit/room.spec.ts index 629a437bd..085a74c50 100644 --- a/server/tests/unit/room.spec.ts +++ b/server/tests/unit/room.spec.ts @@ -11,12 +11,12 @@ import { } from "vitest"; import dayjs from "dayjs"; import tokens, { SessionInfo } from "../../auth/tokens"; -import { RoomRequestType } from "ott-common/models/messages"; -import { AuthToken, BehaviorOption, QueueMode, Role } from "ott-common/models/types"; +import { RoomRequestType } from "../../../common/models/messages"; +import { AuthToken, BehaviorOption, QueueMode, Role } from "../../../common/models/types"; import { Room, RoomUser } from "../../room"; import infoextractor from "../../infoextractor"; -import { Video, VideoId } from "ott-common/models/video"; -import permissions from "ott-common/permissions"; +import { Video, VideoId } from "../../../common/models/video"; +import permissions from "../../../common/permissions"; import _ from "lodash"; import { VideoQueue } from "../../videoqueue"; import { loadModels } from "../../models"; diff --git a/server/tests/unit/roommanager.spec.ts b/server/tests/unit/roommanager.spec.ts index 4908ffffc..d86df1d09 100644 --- a/server/tests/unit/roommanager.spec.ts +++ b/server/tests/unit/roommanager.spec.ts @@ -4,11 +4,11 @@ import roommanager, { redisStateToState } from "../../roommanager"; // @ts-ignore import { Room as DbRoom, loadModels } from "../../models"; import { Room, RoomStateFromRedis } from "../../room"; -import { AuthToken, QueueMode, Role, Visibility } from "ott-common/models/types"; +import { AuthToken, QueueMode, Role, Visibility } from "../../../common/models/types"; import dayjs from "dayjs"; import { RoomNotFoundException } from "../../exceptions"; import storage from "../../storage"; -import { RoomRequest, RoomRequestType } from "ott-common/models/messages"; +import { RoomRequest, RoomRequestType } from "../../../common/models/messages"; import { VideoQueue } from "../../../server/videoqueue"; import { buildClients } from "../../redisclient"; diff --git a/server/tests/unit/services/youtube.spec.ts b/server/tests/unit/services/youtube.spec.ts index 78ba370e6..f1b8e347f 100644 --- a/server/tests/unit/services/youtube.spec.ts +++ b/server/tests/unit/services/youtube.spec.ts @@ -14,7 +14,7 @@ import YouTubeAdapter, { YoutubeApiVideoListResponse, YoutubeApiVideo, } from "../../../services/youtube"; -import { Video } from "ott-common/models/video"; +import { Video } from "../../../../common/models/video"; import { InvalidVideoIdException, OutOfQuotaException } from "../../../exceptions"; import { buildClients, redisClient } from "../../../redisclient"; import { AxiosError, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from "axios"; diff --git a/server/tests/unit/storage.spec.ts b/server/tests/unit/storage.spec.ts index 0cc4e25f4..46e1c2b78 100644 --- a/server/tests/unit/storage.spec.ts +++ b/server/tests/unit/storage.spec.ts @@ -2,9 +2,9 @@ import { describe, it, expect, beforeAll, beforeEach, afterEach } from "vitest"; import _ from "lodash"; import { CachedVideo, Room as DbRoom, User, loadModels } from "../../models"; import storage from "../../storage"; -import permissions, { Grants } from "ott-common/permissions"; -import { Visibility, QueueMode } from "ott-common/models/types"; -import { Video, VideoId } from "ott-common/models/video"; +import permissions, { Grants } from "../../../common/permissions"; +import { Visibility, QueueMode } from "../../../common/models/types"; +import { Video, VideoId } from "../../../common/models/video"; import { Room } from "../../room"; import { roomToDb, roomToDbPartial } from "../../storage/room"; import { buildClients } from "../../redisclient"; diff --git a/server/usermanager.ts b/server/usermanager.ts index cdfb6553e..c01b0be40 100644 --- a/server/usermanager.ts +++ b/server/usermanager.ts @@ -12,7 +12,7 @@ import { RateLimiterRedisv4, consumeRateLimitPoints, rateLimiter } from "./rate- import tokens from "./auth/tokens"; import nocache from "nocache"; import { uniqueNamesGenerator } from "unique-names-generator"; -import { USERNAME_LENGTH_MAX } from "ott-common/constants"; +import { USERNAME_LENGTH_MAX } from "../common/constants"; import { BadApiArgumentException, FeatureDisabledException, @@ -26,14 +26,14 @@ import { AuthToken } from "ott-common/models/types"; import { EventEmitter } from "events"; import { Sequelize, UniqueConstraintError } from "sequelize"; import { Email, Mailer, MailerError, MailjetMailer, MockMailer } from "./mailer"; -import { Result, err } from "ott-common/result"; +import { Result, err } from "../common/result"; import type { OttApiRequestAccountRecoveryStart, OttApiRequestAccountRecoveryVerify, OttResponseBody, -} from "ott-common/models/rest-api"; +} from "../common/models/rest-api"; import { counterHttpErrors } from "./metrics"; -import { OttException } from "ott-common/exceptions"; +import { OttException } from "../common/exceptions"; const pwd = securePassword(); const log = getLogger("usermanager"); @@ -194,13 +194,13 @@ router.post("/", nocache(), async (req, res) => { } oldUsername = req.ottsession.username; req.ottsession.username = req.body.username; - await tokens.setSessionInfo(req.token!, req.ottsession); + await tokens.setSessionInfo(req.token, req.ottsession); res.json({ success: true, }); } log.info(`${oldUsername} changed username to ${req.body.username}`); - onUserModified(req.token!); + onUserModified(req.token); }); router.post("/login", async (req, res, next) => { @@ -263,9 +263,9 @@ router.post("/login", async (req, res, next) => { return; } req.ottsession = { isLoggedIn: true, user_id: user.id }; - await tokens.setSessionInfo(req.token!, req.ottsession); + await tokens.setSessionInfo(req.token, req.ottsession); try { - onUserLogIn(user, req.token!); + onUserLogIn(user, req.token); } catch (err) { log.error( `An unknown error occurred when running onUserLogIn: ${err} ${err.message}` @@ -296,8 +296,8 @@ router.post("/logout", async (req, res) => { return; } req.ottsession = { isLoggedIn: false, username: uniqueNamesGenerator() }; - await tokens.setSessionInfo(req.token!, req.ottsession); - onUserLogOut(user, req.token!); + await tokens.setSessionInfo(req.token, req.ottsession); + onUserLogOut(user, req.token); res.json({ success: true, }); @@ -321,9 +321,9 @@ router.post("/register", async (req, res) => { log.info(`User registered: ${result.id}`); req.login(result, async () => { req.ottsession = { isLoggedIn: true, user_id: result.id }; - await tokens.setSessionInfo(req.token!, req.ottsession); + await tokens.setSessionInfo(req.token, req.ottsession); try { - onUserLogIn(result, req.token!); + onUserLogIn(result, req.token); } catch (err) { log.error( `An unknown error occurred when running onUserLogIn: ${err} ${err.message}` @@ -921,7 +921,7 @@ if (conf.get("env") === "test") { const user = await getUser({ user: "forced@localhost" }); req.login(user, async err => { req.ottsession = { isLoggedIn: true, user_id: user.id }; - await tokens.setSessionInfo(req.token!, req.ottsession); + await tokens.setSessionInfo(req.token, req.ottsession); res.json({ success: !!err, }); diff --git a/server/videoqueue.ts b/server/videoqueue.ts index 7d1f432d6..039e25144 100644 --- a/server/videoqueue.ts +++ b/server/videoqueue.ts @@ -1,7 +1,7 @@ import { Mutex } from "@divine/synchronization"; import { Dirtyable } from "./util"; -import { QueueItem, Video, VideoId } from "ott-common/models/video"; +import { QueueItem, Video, VideoId } from "../common/models/video"; import _ from "lodash"; import { VideoNotFoundException } from "./exceptions"; diff --git a/server/vitest.config.ts b/server/vitest.config.ts index ed0e2da32..c8bbfe29f 100644 --- a/server/vitest.config.ts +++ b/server/vitest.config.ts @@ -7,13 +7,7 @@ export default defineConfig({ pool: "forks", setupFiles: ["./tests/unit/jest.setup.redis-mock.js"], coverage: { - exclude: [ - ...(configDefaults.coverage.exclude ?? []), - "config/**", - "migrations/**", - "**/tests/**", - "**/common/**", - ], + exclude: [...(configDefaults.coverage.exclude ?? []), "config/**", "migrations/**"], }, }, }); diff --git a/tests/e2e/integration/room-settings.spec.ts b/tests/e2e/integration/room-settings.spec.ts index 187f0ca23..570da62bd 100644 --- a/tests/e2e/integration/room-settings.spec.ts +++ b/tests/e2e/integration/room-settings.spec.ts @@ -1,6 +1,6 @@ // import faker from "faker"; // import uuid from "uuid"; -import { QueueMode, Visibility } from "ott-common/models/types"; +import { QueueMode, Visibility } from "../../../common/models/types"; describe("Room settings", () => { // let roomName;