mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-13 02:14:32 +01:00
Add etags for branding as well
This commit is contained in:
parent
4b795da5a0
commit
063607fe30
2 changed files with 13 additions and 2 deletions
|
@ -1,9 +1,9 @@
|
||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { VideoID, VideoIDHash, Service } from "../types/segments.model";
|
import { VideoID, VideoIDHash, Service } from "../types/segments.model";
|
||||||
import { QueryCacher } from "../utils/queryCacher";
|
import { QueryCacher } from "../utils/queryCacher";
|
||||||
import { skipSegmentsHashKey, skipSegmentsKey, videoLabelsHashKey, videoLabelsKey } from "../utils/redisKeys";
|
import { brandingHashKey, brandingKey, skipSegmentsHashKey, skipSegmentsKey, videoLabelsHashKey, videoLabelsKey } from "../utils/redisKeys";
|
||||||
|
|
||||||
type hashType = "skipSegments" | "skipSegmentsHash" | "videoLabel" | "videoLabelHash";
|
type hashType = "skipSegments" | "skipSegmentsHash" | "videoLabel" | "videoLabelHash" | "branding" | "brandingHash";
|
||||||
type ETag = `"${hashType};${VideoIDHash};${Service};${number}"`;
|
type ETag = `"${hashType};${VideoIDHash};${Service};${number}"`;
|
||||||
type hashKey = string | VideoID | VideoIDHash;
|
type hashKey = string | VideoID | VideoIDHash;
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ function getLastModified(hashType: hashType, hashKey: hashKey, service: Service)
|
||||||
else if (hashType === "skipSegmentsHash") redisKey = skipSegmentsHashKey(hashKey as VideoIDHash, service);
|
else if (hashType === "skipSegmentsHash") redisKey = skipSegmentsHashKey(hashKey as VideoIDHash, service);
|
||||||
else if (hashType === "videoLabel") redisKey = videoLabelsKey(hashKey as VideoID, service);
|
else if (hashType === "videoLabel") redisKey = videoLabelsKey(hashKey as VideoID, service);
|
||||||
else if (hashType === "videoLabelHash") redisKey = videoLabelsHashKey(hashKey as VideoIDHash, service);
|
else if (hashType === "videoLabelHash") redisKey = videoLabelsHashKey(hashKey as VideoIDHash, service);
|
||||||
|
else if (hashType === "branding") redisKey = brandingKey(hashKey as VideoID, service);
|
||||||
|
else if (hashType === "brandingHash") redisKey = brandingHashKey(hashKey as VideoIDHash, service);
|
||||||
else return Promise.reject();
|
else return Promise.reject();
|
||||||
return QueryCacher.getKeyLastModified(redisKey);
|
return QueryCacher.getKeyLastModified(redisKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { promiseOrTimeout } from "../utils/promise";
|
||||||
import { QueryCacher } from "../utils/queryCacher";
|
import { QueryCacher } from "../utils/queryCacher";
|
||||||
import { brandingHashKey, brandingIPKey, brandingKey } from "../utils/redisKeys";
|
import { brandingHashKey, brandingIPKey, brandingKey } from "../utils/redisKeys";
|
||||||
import * as SeedRandom from "seedrandom";
|
import * as SeedRandom from "seedrandom";
|
||||||
|
import { getEtag } from "../middleware/etag";
|
||||||
|
|
||||||
enum BrandingSubmissionType {
|
enum BrandingSubmissionType {
|
||||||
Title = "title",
|
Title = "title",
|
||||||
|
@ -294,6 +295,10 @@ export async function getBranding(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const result = await getVideoBranding(res, videoID, service, ip, returnUserID, fetchAll);
|
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;
|
const status = result.titles.length > 0 || result.thumbnails.length > 0 ? 200 : 404;
|
||||||
return res.status(status).json(result);
|
return res.status(status).json(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -317,6 +322,10 @@ export async function getBrandingByHashEndpoint(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const result = await getVideoBrandingByHash(hashPrefix, service, ip, returnUserID, fetchAll);
|
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;
|
const status = !isEmpty(result) ? 200 : 404;
|
||||||
return res.status(status).json(result);
|
return res.status(status).json(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue