added advertising

This commit is contained in:
SlimusMinus
2026-09-23 23:38:54 +03:00
parent 3661985a6a
commit 4e20315998
33 changed files with 3351 additions and 18 deletions

21
src/utils/adSession.js Normal file
View File

@@ -0,0 +1,21 @@
const AD_SESSION_KEY = "ad_session_id";
function generateAdSessionId() {
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
export function getAdSessionId() {
let sessionId = localStorage.getItem(AD_SESSION_KEY);
if (!sessionId) {
sessionId = generateAdSessionId();
localStorage.setItem(AD_SESSION_KEY, sessionId);
}
return sessionId;
}

View File

@@ -0,0 +1,16 @@
// Разрешённые переходы статусов кампании (зеркало логики бэкенда).
// FINISHED — конечное состояние: переходов из него нет.
export const CAMPAIGN_STATUS_TRANSITIONS = {
DRAFT: ["ACTIVE"],
ACTIVE: ["PAUSED", "FINISHED"],
PAUSED: ["ACTIVE", "FINISHED"],
FINISHED: [],
};
export function getNextCampaignStatuses(currentStatus) {
return CAMPAIGN_STATUS_TRANSITIONS[currentStatus] || [];
}
export function isProcessingTranscoding(status) {
return status === "PENDING" || status === "PROCESSING";
}

13
src/utils/withAds.js Normal file
View File

@@ -0,0 +1,13 @@
export function withAds(posts, every = 10) {
if (!Array.isArray(posts)) return [];
if (every <= 0) return posts.map((data) => ({ kind: "post", data }));
const items = [];
posts.forEach((data, index) => {
if (index > 0 && index % every === 0) {
items.push({ kind: "ad", key: `ad-${index}` });
}
items.push({ kind: "post", data });
});
return items;
}