Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ instructions [here](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
### How is a contribution reviewed and accepted?

- **If you are opening an issue...**

- Fill out all required sections for your issue type. Issues that are not
filled out properly will be flagged as `invalid` and will be closed if not
updated.
Expand Down
28 changes: 15 additions & 13 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"prepare:redoc": "redoc-cli bundle --cdn -o docs/index.html src/schema/schema.yaml",
"prepare:type-check": "tsc --pretty --noEmit",
"prepare": "run-s compile-schemas && run-p \"prepare:**\"",
"compile-schemas": "node -r esm src/schema/compile-schemas.js",
"pull-ai-schema": "node -r esm src/schema/pull-ai-schema.js",
"compile-schemas": "node src/schema/compile-schemas.mjs",
"pull-ai-schema": "node dist/schema/pull-ai-schema.js",
"dev-server": "run-s compile-schemas && node dist/cli.js",
"redoc": "nodemon -w src/schema/schema.yaml -x npm run prepare:redoc",
"siserver": "nodemon -w dist -x node -r esm dist/stream-info-service.js -e js,yaml",
"siserver": "nodemon -w dist -x node dist/stream-info-service.js -e js,yaml",
"dev:server": "NODE_ENV=development LP_API_FRONTEND=false nodemon --inspect -w dist -x node dist/cli.js -e js,yaml",
"dev:babel": "yarn run prepare:babel --watch",
"dev:yaml-json": "nodemon -w ./src/schema -e 'yaml' -x 'run-s compile-schemas'",
Expand All @@ -43,6 +43,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.421.0",
"@aws-sdk/s3-request-presigner": "^3.48.0",
"@babel/core": "^7.25.0",
"@cloudflare/json-schema-walker": "^0.1.1",
"@cloudflare/kv-asset-handler": "^0.0.11",
"@lit-protocol/sdk-nodejs": "^1.1.241",
Expand All @@ -56,6 +57,7 @@
"@tus/server": "^1.0.0",
"@types/amqp-connection-manager": "2.0.10",
"@types/cors": "^2.8.12",
"@types/express-mung": "0.5.5",
"ajv": "^8.16.0",
"ajv-cli": "^3.1.0",
"ajv-formats": "^3.0.1",
Expand All @@ -74,7 +76,7 @@
"dotenv": "^8.1.0",
"email-validator": "^2.0.4",
"ethers": "^6.4.0",
"express": "^4.16.4",
"express": "5.1.0",
"express-async-errors": "^3.1.1",
"express-mung": "^0.5.1",
"express-prom-bundle": "^6.4.1",
Expand All @@ -95,7 +97,7 @@
"lodash": "^4.17.21",
"m3u8-parser": "^4.4.0",
"mime": "^3.0.0",
"minio": "^7.0.12",
"minio": "8",
"morgan": "^1.9.1",
"mqtt": "^4.2.6",
"ms": "^2.1.2",
Expand All @@ -118,13 +120,13 @@
"yargs": "^17.3.1"
},
"devDependencies": {
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/preset-typescript": "^7.14.5",
"@babel/cli": "^7.25.0",
"@babel/core": "^7.25.0",
"@babel/preset-env": "^7.25.0",
"@babel/preset-typescript": "^7.25.0",
"@types/basic-auth": "^1.1.3",
"@types/express": "^4.17.12",
"@types/express-mung": "^0.5.2",
"@types/express": "^5.0.0",
"@types/express-mung": "^0.5.5",
"@types/http-proxy": "^1.17.8",
"@types/jest": "^29.5.3",
"@types/jsonwebtoken": "^8.5.6",
Expand All @@ -151,7 +153,7 @@
"prettier": "^2.6.2",
"redoc-cli": "^0.8.3",
"tus-js-client": "^3.0.0-0",
"typescript": "^4.3.4"
"typescript": "^5.6.0"
},
"homepage": "https://livepeer.org",
"repository": {
Expand All @@ -165,7 +167,7 @@
]
},
"browserslist": [
"node 16"
"node 22"
],
"types": "src/schema/types.d.ts",
"nodemonConfig": {
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/app/stream-info/stream-info-app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import express, { Router } from "express";
import "express-async-errors"; // it monkeypatches, i guess
import morgan from "morgan";
import fetch from "node-fetch";
import { hostname } from "os";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { authorizer } from "../middleware";
import Router from "express/lib/router";
import { Router } from "express";
import { db } from "../store";
import sql from "sql-template-strings";
import consul from "consul";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/api-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Special controller for forwarding all incoming requests to a geolocated API region
*/

import Router from "express/lib/router";
import { Router } from "express";
import geolocateMiddleware from "../middleware/geolocate";
import fetch from "node-fetch";
import qs from "qs";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/api-token.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";
import { v4 as uuid } from "uuid";
import sql from "sql-template-strings";

Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/controllers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ const getPendingAssetAndTask = async (playbackId: string) => {
return { asset, task };
};

app.use("/upload/tus/*", async (req, res, next) => {
app.use("/upload/tus/*path", async (req, res, next) => {
if (!tusServer) {
throw new NotImplementedError("Tus server not configured");
}
Expand All @@ -1148,7 +1148,7 @@ app.post("/upload/tus", async (req, res) => {
return tusServer.handle(req, res);
});

app.all("/upload/tus/*", (req, res) => {
app.all("/upload/tus/*path", (req, res) => {
return tusServer.handle(req, res);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/broadcaster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";
import fetch from "node-fetch";
import { authorizer, geolocateMiddleware } from "../middleware";
import { shuffle } from "../util";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/did.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";

const app = Router();

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/geolocate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { geolocateMiddleware } from "../middleware";
import Router from "express/lib/router";
import { Router } from "express";

const app = Router();

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/ingest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";
import { geolocateMiddleware } from "../middleware";
import { amalgamate } from "./broadcaster";
import { shuffle } from "../util";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/live-proxy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import router from "express/lib/router";
import { Router as router } from "express";
import fetch from "node-fetch";
import { Parser } from "m3u8-parser";
import composeM3U8 from "./compose-m3u8";
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/controllers/orchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Request } from "express";
import Router from "express/lib/router";
import { Request, Router } from "express";

const app = Router();

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/region.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";
import { authorizer, validatePost } from "../middleware";
import { db } from "../store";

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/stream-proxy-os.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import router from "express/lib/router";
import { Router as router } from "express";
import fetch from "node-fetch";
import { Parser } from "m3u8-parser";
import composeM3U8 from "./compose-m3u8";
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/stream-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// /api/* that everything else lives at. This makes it follow the naming
// conventions on the broadcasters themselves.

import Router from "express/lib/router";
import { Router } from "express";
import composeM3U8 from "./compose-m3u8";
const app = Router();

Expand Down
51 changes: 24 additions & 27 deletions packages/api/src/controllers/usage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request } from "express";
import Router from "express/lib/router";
import { Router } from "express";
import fetch from "node-fetch";
import qs from "qs";
import { products } from "../config";
Expand Down Expand Up @@ -227,13 +227,11 @@ export async function getUsageData(
}

app.get("/", authorizer({ anyAdmin: true }), async (req, res) => {
let { fromTime, toTime } = req.query;

// if time range isn't specified return all usage
if (!fromTime && !toTime) {
fromTime = +new Date(2020, 0); // start at beginning
toTime = +new Date();
}
// Parse query parameters properly
let fromTime = req.query.fromTime
? Number(req.query.fromTime)
: +new Date(2020, 0);
let toTime = req.query.toTime ? Number(req.query.toTime) : +new Date();

const cachedUsageHistory = await db.stream.cachedUsageHistory(
fromTime,
Expand Down Expand Up @@ -263,13 +261,11 @@ app.get(
);

app.get("/user", authorizer({ anyAdmin: true }), async (req, res) => {
let { fromTime, toTime } = req.query;

// if time range isn't specified return all usage
if (!fromTime && !toTime) {
fromTime = +new Date(2020, 0); // start at beginning
toTime = +new Date();
}
// Parse query parameters properly
let fromTime = req.query.fromTime
? Number(req.query.fromTime)
: +new Date(2020, 0);
let toTime = req.query.toTime ? Number(req.query.toTime) : +new Date();

if (!req.query.userId) {
res.status(400);
Expand All @@ -278,9 +274,10 @@ app.get("/user", authorizer({ anyAdmin: true }), async (req, res) => {
}

const ingests = await req.getIngest();
const userId = req.query.userId as string;

const usage = await getBillingUsage(
req.query.userId,
userId,
fromTime,
toTime,
ingests[0].origin,
Expand All @@ -292,21 +289,19 @@ app.get("/user", authorizer({ anyAdmin: true }), async (req, res) => {
});

app.get("/user/overage", authorizer({ anyAdmin: true }), async (req, res) => {
let { fromTime, toTime } = req.query;

// if time range isn't specified return all usage
if (!fromTime && !toTime) {
fromTime = +new Date(2020, 0); // start at beginning
toTime = +new Date();
}
// Parse query parameters properly
let fromTime = req.query.fromTime
? Number(req.query.fromTime)
: +new Date(2020, 0);
let toTime = req.query.toTime ? Number(req.query.toTime) : +new Date();

if (!req.query.userId) {
res.status(400);
res.json({ error: "userId is required" });
return;
}

const user = await db.user.get(req.query.userId);
const user = await db.user.get(req.query.userId as string);

if (!user) {
throw new NotFoundError(`Account not found: ${req.query.userId}`);
Expand All @@ -315,7 +310,7 @@ app.get("/user/overage", authorizer({ anyAdmin: true }), async (req, res) => {
const ingests = await req.getIngest();

const usage = await getBillingUsage(
req.query.userId,
req.query.userId as string,
fromTime,
toTime,
ingests[0].origin,
Expand All @@ -333,15 +328,17 @@ app.get("/user/overage", authorizer({ anyAdmin: true }), async (req, res) => {
);

res.status(200);
res.json(overage, usagePercentages);
res.json({ overage, usagePercentages });
});

// Runs the update-usage job on demand if necessary
app.post("/update", authorizer({ anyAdmin: true }), async (req, res) => {
// import the job dynamically to avoid circular dependencies
const { default: updateUsage } = await import("../jobs/update-usage");

let { fromTime, toTime } = req.query;
// Parse query parameters properly
const fromTime = req.query.fromTime ? Number(req.query.fromTime) : undefined;
const toTime = req.query.toTime ? Number(req.query.toTime) : undefined;

const { usageHistory } = await updateUsage(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router from "express/lib/router";
import { Router } from "express";

const app = Router();

Expand Down
Loading
Loading