Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redesign #2298

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
148,049 changes: 148,049 additions & 0 deletions .yarn/releases/yarn-classic.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-classic.cjs
4 changes: 2 additions & 2 deletions packages/api/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function getFiles(dir) {
dirents.map((dirent) => {
const res = resolve(dir, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
}),
})
);
return Array.prototype.concat(...files).filter((f) => !f.includes("cache"));
}
Expand Down Expand Up @@ -46,7 +46,7 @@ let frontendBundlePlugin = {
loader: "js",
resolveDir: resolve(args.resolveDir, args.path),
};
},
}
);

// Any files from the static-build directory should be bundled as binary
Expand Down
14 changes: 7 additions & 7 deletions packages/api/src/app-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function initDb(params: CliArgs, serviceName = "api") {
...pgBaseParams,
poolMaxSize: pgJobsPoolSize,
appName: `${appName}-jobs`,
},
}
);
return { db, jobsDb, store };
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export async function initClients(params: CliArgs, serviceName = "api") {

if (!stripeSecretKey) {
console.warn(
"Warning: Missing Stripe API key. In development, make sure to configure one in .env.local file.",
"Warning: Missing Stripe API key. In development, make sure to configure one in .env.local file."
);
}
const stripe = stripeSecretKey
Expand Down Expand Up @@ -155,7 +155,7 @@ export default async function appRouter(params: CliArgs) {
if (supportAddr || sendgridTemplateId || sendgridApiKey) {
if (!(supportAddr && sendgridTemplateId && sendgridApiKey)) {
throw new Error(
`Sending emails requires supportAddr, sendgridTemplateId, and sendgridApiKey`,
`Sending emails requires supportAddr, sendgridTemplateId, and sendgridApiKey`
);
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ export default async function appRouter(params: CliArgs) {
exposedHeaders: ["*"],
},
},
}),
})
);

// stripe webhook requires raw body
Expand All @@ -241,7 +241,7 @@ export default async function appRouter(params: CliArgs) {
if (returnRegionInOrchestrator) {
app.use((req, res, next) => {
req.orchestratorsGetters.push(() =>
regionsGetter(halfRegionOrchestratorsUntrusted),
regionsGetter(halfRegionOrchestratorsUntrusted)
);
return next();
});
Expand All @@ -251,7 +251,7 @@ export default async function appRouter(params: CliArgs) {
app.use(
subgraph({
subgraphUrl,
}),
})
);
}

Expand All @@ -261,7 +261,7 @@ export default async function appRouter(params: CliArgs) {
prefixRouter.get(
"/stream/:streamId/broadcaster",
geolocateMiddleware({}),
getBroadcasterHandler,
getBroadcasterHandler
);
for (const [name, controller] of Object.entries(controllers)) {
// if we're operating in api-region mode, only handle geolocation traffic, forward the rest on
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/app/stream-info/parse-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function parseCli() {

Options my also be provided as LP_API_ prefixed environment variables, e.g. LP_API_PORT=5000 is the same as --port=5000.

`,
`
)
.env("LP_API_")
//.strict(true)
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/app/stream-info/stream-info-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class statusPoller {

if (si.stream?.id !== getStreamId(mid)) {
console.log(
`stream id changed from ${si.stream?.id} to ${getStreamId(mid)}`,
`stream id changed from ${si.stream?.id} to ${getStreamId(mid)}`
);
// save the old stream info so it's properly housekept later
this.seenStreams.set(`old_${mid}_${si.stream?.id}`, si);
Expand Down Expand Up @@ -266,7 +266,7 @@ class statusPoller {

private async housekeepSeenStreams(
activeStreams?: MasterPlaylistDictionary,
force?: boolean,
force?: boolean
) {
for (const [mid, si] of this.seenStreams) {
if (activeStreams && mid in activeStreams) {
Expand Down Expand Up @@ -395,7 +395,7 @@ export default async function makeApp(params: CliArgs) {
.listen(port, () => {
listenPort = listener.address().port;
logger.info(
`Stream info server listening on http://0.0.0.0:${listenPort}`,
`Stream info server listening on http://0.0.0.0:${listenPort}`
);
resolve();
})
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/compile-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ fs.ensureDirSync(schemaDistDir);

const apiSchemaStr = fs.readFileSync(
path.resolve(schemaDir, "api-schema.yaml"),
"utf8",
"utf8"
);
const dbSchemaStr = fs.readFileSync(
path.resolve(schemaDir, "db-schema.yaml"),
"utf8",
"utf8"
);
const apiData = parseYaml(apiSchemaStr);
const dbData = parseYaml(dbSchemaStr);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/controllers/access-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe("controllers/access-control", () => {
expect(res3.status).toBe(403);
let resJson = await res3.json();
expect(resJson.errors[0]).toBe(
`Content is gated and origin not in allowed origins`,
`Content is gated and origin not in allowed origins`
);
const res4 = await client.post("/access-control/gate", {
stream: `video+${gatedAsset.playbackId}`,
Expand All @@ -338,7 +338,7 @@ describe("controllers/access-control", () => {
expect(res4.status).toBe(403);
let resJson2 = await res4.json();
expect(resJson2.errors[0]).toBe(
"Content is gated and corresponding public key not found",
"Content is gated and corresponding public key not found"
);
});

Expand Down
46 changes: 23 additions & 23 deletions packages/api/src/controllers/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type GateConfig = {
async function fireGateWebhook(
webhook: DBWebhook,
content: DBStream | WithID<Asset>,
payload: AccessControlGatePayload,
payload: AccessControlGatePayload
) {
let timestamp = Date.now();
let jsonPayload = {
Expand Down Expand Up @@ -75,7 +75,7 @@ async function fireGateWebhook(
const sigHeaders = signatureHeaders(
params.body,
webhook.sharedSecret,
timestamp,
timestamp
);
params.headers = { ...params.headers, ...sigHeaders };

Expand Down Expand Up @@ -113,7 +113,7 @@ async function fireGateWebhook(
timestamp,
statusCode,
errorMessage,
undefined,
undefined
);
}
if ("pull" in content && content.pull) {
Expand All @@ -129,26 +129,26 @@ async function fireGateWebhook(
`access-control: gate: webhook=${
webhook.id
} statusCode=${statusCode} respSpanId=${resp?.headers.get(
"X-Tlive-Spanid",
"X-Tlive-Spanid"
)} respBody=${Buffer.from(respBody).toString("base64")} duration=${
process.hrtime(startTime)[1] / 1e6
}ms accessKey=${payload.accessKey} playbackId=${
content.playbackId
} webhook=${
webhook.id
} referer=${referer} origin=${origin} playURL=${playURL} playDomain=${playDomain}`,
} referer=${referer} origin=${origin} playURL=${playURL} playDomain=${playDomain}`
);
} catch (e) {
console.log(
`access-control: gate: webhook=${
webhook.id
} statusCode=${statusCode} respSpanId=${resp?.headers.get(
"X-Tlive-Spanid",
"X-Tlive-Spanid"
)} respBody=${Buffer.from(respBody).toString("base64")} duration=${
process.hrtime(startTime)[1] / 1e6
}ms accessKey=${payload.accessKey} playbackId=${
content.playbackId
} webhook=${webhook.id}`,
} webhook=${webhook.id}`
);
}
} else {
Expand All @@ -157,7 +157,7 @@ async function fireGateWebhook(
webhook.id
} statusCode=${statusCode} duration=${
process.hrtime(startTime)[1] / 1e6
}ms`,
}ms`
);
}
return statusCode;
Expand All @@ -172,7 +172,7 @@ function checkRespBody(resp: string): number | null {
return body.ret;
} catch (e) {
console.log(
`access-control: error checking response body for status code: ${e}`,
`access-control: error checking response body for status code: ${e}`
);
}
}
Expand All @@ -192,7 +192,7 @@ app.post(
(await db.stream.getByPlaybackId(playbackId)) ||
(await db.asset.getByPlaybackId(playbackId))
);
},
}
);

res.set("Cache-Control", "max-age=120,stale-while-revalidate=600");
Expand Down Expand Up @@ -261,7 +261,7 @@ app.post(
if (origin === "null" || origin === "") {
origin = referer;
console.log(
`access-control: gate: origin is null, using referer=${origin} for playbackId=${playbackId}`,
`access-control: gate: origin is null, using referer=${origin} for playbackId=${playbackId}`
);
}

Expand All @@ -279,7 +279,7 @@ app.post(
access-control: gate: content with playbackId=${playbackId} is gated but origin=${origin} not in allowed origins=${allowedOrigins}, disallowing playback
`);
throw new ForbiddenError(
`Content is gated and origin not in allowed origins`,
`Content is gated and origin not in allowed origins`
);
}
}
Expand All @@ -296,7 +296,7 @@ app.post(
access-control: gate: no pub provided for playbackId=${playbackId}, disallowing playback
`);
throw new ForbiddenError(
"Content is gated and requires a public key",
"Content is gated and requires a public key"
);
}

Expand All @@ -307,15 +307,15 @@ app.post(
sql`signing_key.data->>'publicKey' = ${req.body.pub}`,
];
return db.signingKey.find(query, { limit: 2 });
},
}
);

if (signingKeyOutput.length == 0) {
console.log(`
access-control: gate: content with playbackId=${playbackId} is gated but corresponding public key not found for key=${req.body.pub}, disallowing playback
`);
throw new ForbiddenError(
"Content is gated and corresponding public key not found",
"Content is gated and corresponding public key not found"
);
}

Expand All @@ -325,7 +325,7 @@ app.post(
access-control: gate: content contentId=${content.id} with playbackId=${playbackId} is gated but multiple (${signingKeyOutput.length}) public keys found for key=${req.body.pub}, disallowing playback, colliding keys=${collisionKeys}
`);
throw new BadRequestError(
"Multiple signing keys found for the same public key.",
"Multiple signing keys found for the same public key."
);
}

Expand All @@ -352,7 +352,7 @@ app.post(
case "webhook":
if (!req.body.accessKey || req.body.type !== "accessKey") {
throw new ForbiddenError(
"Content is gated and requires an access key",
"Content is gated and requires an access key"
);
}
const webhook = await db.webhook.get(content.playbackPolicy.webhookId, {
Expand All @@ -363,7 +363,7 @@ app.post(
access-control: gate: content with playbackId=${playbackId} is gated but corresponding webhook not found for webhookId=${content.playbackPolicy.webhookId}, disallowing playback
`);
throw new InternalServerError(
"Content is gated and corresponding webhook not found",
"Content is gated and corresponding webhook not found"
);
}

Expand All @@ -379,22 +379,22 @@ app.post(
access-control: gate: content with playbackId=${playbackId} is gated but webhook=${webhook.id} failed, disallowing playback
`);
throw new BadGatewayError(
"Content is gated and corresponding webhook failed",
"Content is gated and corresponding webhook failed"
);
} else {
console.log(`
access-control: gate: content with playbackId=${playbackId} is gated but webhook=${webhook.id} returned status code ${statusCode}, disallowing playback
`);
throw new ForbiddenError(
"Content is gated and corresponding webhook failed",
"Content is gated and corresponding webhook failed"
);
}
default:
throw new BadRequestError(
`unknown playbackPolicy type: ${playbackPolicyType}`,
`unknown playbackPolicy type: ${playbackPolicyType}`
);
}
},
}
);

app.get("/public-key", async (req, res) => {
Expand All @@ -414,7 +414,7 @@ app.get("/public-key", async (req, res) => {
return response.json();
} else {
throw new Error(
`access-control: error retrieving public key from catalyst statusCode=${response.status} catalystUrl=${url}`,
`access-control: error retrieving public key from catalyst statusCode=${response.status} catalystUrl=${url}`
);
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ app.post(
i++;
}
res.end(`cleaned routes for ${cleaned}/${toClean.length} streams\n`);
},
}
);

app.post("/active-clean", authorizer({ anyAdmin: true }), async (req, res) => {
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
Expand Up @@ -116,7 +116,7 @@ app.get("/", async (req, res) => {
query.push(
sql`coalesce(api_token.data->>'projectId', ${
req.user.defaultProjectId || ""
}) = ${req.project?.id || ""}`,
}) = ${req.project?.id || ""}`
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/api-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("controllers/api-token", () => {

const nonAdminUserRes = await server.store.get(
`user/${nonAdminUser.id}`,
false,
false
);
nonAdminUser = { ...nonAdminUserRes, emailValid: true };
await server.store.replace(nonAdminUser);
Expand Down
Loading
Loading