Add etags for branding as well

This commit is contained in:
Ajay
2024-04-20 13:16:34 -04:00
parent 4b795da5a0
commit 063607fe30
2 changed files with 13 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ import { promiseOrTimeout } from "../utils/promise";
import { QueryCacher } from "../utils/queryCacher";
import { brandingHashKey, brandingIPKey, brandingKey } from "../utils/redisKeys";
import * as SeedRandom from "seedrandom";
import { getEtag } from "../middleware/etag";
enum BrandingSubmissionType {
Title = "title",
@@ -294,6 +295,10 @@ export async function getBranding(req: Request, res: Response) {
try {
const result = await getVideoBranding(res, videoID, service, ip, returnUserID, fetchAll);
await getEtag("branding", (videoID as string), service)
.then(etag => res.set("ETag", etag))
.catch(() => null);
const status = result.titles.length > 0 || result.thumbnails.length > 0 ? 200 : 404;
return res.status(status).json(result);
} catch (e) {
@@ -317,6 +322,10 @@ export async function getBrandingByHashEndpoint(req: Request, res: Response) {
try {
const result = await getVideoBrandingByHash(hashPrefix, service, ip, returnUserID, fetchAll);
await getEtag("brandingHash", (hashPrefix as string), service)
.then(etag => res.set("ETag", etag))
.catch(() => null);
const status = !isEmpty(result) ? 200 : 404;
return res.status(status).json(result);
} catch (e) {