added advertising
This commit is contained in:
21
src/utils/adSession.js
Normal file
21
src/utils/adSession.js
Normal 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;
|
||||
}
|
||||
16
src/utils/campaignStatus.js
Normal file
16
src/utils/campaignStatus.js
Normal 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
13
src/utils/withAds.js
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user