mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-30 17:32:26 +00:00
Merge pull request #1914 from PR0M3TH3AN/ai/schema-validate-20250523-8496220375948723743
chore(ai): event schema validation tool + fixes
This commit is contained in:
6 files changed
+393
-10
No files matched your search
@@ -341,11 +341,12 @@ valid events:
|
||||
|
||||
```bash
|
||||
# Run the validation script
|
||||
node scripts/agent/validate-events.test.mjs
|
||||
node scripts/agent/validate-events.mjs
|
||||
|
||||
# Run the unit test suite
|
||||
npm run test:unit
|
||||
```
|
||||
|
||||
When modifying schemas or builders, use `scripts/agent/validate-events.test.mjs` to
|
||||
verify your changes locally.
|
||||
When modifying schemas or builders, use `scripts/agent/validate-events.mjs` to
|
||||
verify your changes locally. This tool also scans the codebase to ensure all
|
||||
active event builders are covered by tests.
|
||||
@@ -0,0 +1,379 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { execSync } from "child_process";
|
||||
import {
|
||||
NOTE_TYPES,
|
||||
validateEventStructure,
|
||||
buildVideoPostEvent,
|
||||
buildHttpAuthEvent,
|
||||
buildReportEvent,
|
||||
buildVideoMirrorEvent,
|
||||
buildRepostEvent,
|
||||
buildShareEvent,
|
||||
buildRelayListEvent,
|
||||
buildDmRelayListEvent,
|
||||
buildProfileMetadataEvent,
|
||||
buildMuteListEvent,
|
||||
buildDeletionEvent,
|
||||
buildLegacyDirectMessageEvent,
|
||||
buildDmAttachmentEvent,
|
||||
buildDmReadReceiptEvent,
|
||||
buildDmTypingIndicatorEvent,
|
||||
buildViewEvent,
|
||||
buildZapRequestEvent,
|
||||
buildReactionEvent,
|
||||
buildCommentEvent,
|
||||
buildWatchHistoryEvent,
|
||||
buildSubscriptionListEvent,
|
||||
buildBlockListEvent,
|
||||
buildHashtagPreferenceEvent,
|
||||
buildAdminListEvent,
|
||||
} from "../../js/nostrEventSchemas.js";
|
||||
|
||||
const PUBKEY = "0000000000000000000000000000000000000000000000000000000000000001";
|
||||
const CREATED_AT = 1700000000;
|
||||
|
||||
const IGNORED_BUILDERS = new Set([
|
||||
"buildShareUrlFromEventId", // Method in js/app.js, not an event builder
|
||||
"buildShareUrlFromEvent", // Substring match or alias
|
||||
"buildListEvent", // Local helper in js/adminListStore.js wrapping buildAdminListEvent
|
||||
"buildProfileFromEvent", // Local helper in js/services/authService.js
|
||||
]);
|
||||
|
||||
const KNOWN_BUILDERS = {
|
||||
buildVideoPostEvent: {
|
||||
builder: buildVideoPostEvent,
|
||||
type: NOTE_TYPES.VIDEO_POST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
dTagValue: "test-video-id",
|
||||
content: {
|
||||
version: 3,
|
||||
title: "Test Video",
|
||||
videoRootId: "test-video-id",
|
||||
infoHash: "0123456789abcdef0123456789abcdef01234567",
|
||||
},
|
||||
}
|
||||
},
|
||||
buildHttpAuthEvent: {
|
||||
builder: buildHttpAuthEvent,
|
||||
type: NOTE_TYPES.HTTP_AUTH,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
url: "https://example.com/auth",
|
||||
method: "GET",
|
||||
payload: "hash",
|
||||
}
|
||||
},
|
||||
buildReportEvent: {
|
||||
builder: buildReportEvent,
|
||||
type: NOTE_TYPES.REPORT,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
eventId: "e".repeat(64),
|
||||
reportType: "nudity",
|
||||
}
|
||||
},
|
||||
buildVideoMirrorEvent: {
|
||||
builder: buildVideoMirrorEvent,
|
||||
type: NOTE_TYPES.VIDEO_MIRROR,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
tags: [["url", "https://example.com/video.mp4"], ["m", "video/mp4"]],
|
||||
content: "Mirroring video",
|
||||
}
|
||||
},
|
||||
buildRepostEvent: {
|
||||
builder: buildRepostEvent,
|
||||
type: NOTE_TYPES.REPOST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
eventId: "e".repeat(64),
|
||||
eventRelay: "wss://relay.example.com",
|
||||
}
|
||||
},
|
||||
buildShareEvent: {
|
||||
builder: buildShareEvent,
|
||||
type: NOTE_TYPES.SHARE,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
video: { id: "e".repeat(64), pubkey: PUBKEY },
|
||||
relays: ["wss://relay.example.com"],
|
||||
content: "Check this out",
|
||||
}
|
||||
},
|
||||
buildRelayListEvent: {
|
||||
builder: buildRelayListEvent,
|
||||
type: NOTE_TYPES.RELAY_LIST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
relays: [{ url: "wss://relay.example.com", read: true, write: true }],
|
||||
}
|
||||
},
|
||||
buildDmRelayListEvent: {
|
||||
builder: buildDmRelayListEvent,
|
||||
type: NOTE_TYPES.DM_RELAY_LIST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
relays: ["wss://relay.example.com"],
|
||||
}
|
||||
},
|
||||
buildProfileMetadataEvent: {
|
||||
builder: buildProfileMetadataEvent,
|
||||
type: NOTE_TYPES.PROFILE_METADATA,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
metadata: { name: "Test User", about: "Testing" },
|
||||
}
|
||||
},
|
||||
buildMuteListEvent: {
|
||||
builder: buildMuteListEvent,
|
||||
type: NOTE_TYPES.MUTE_LIST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
pTags: [PUBKEY],
|
||||
}
|
||||
},
|
||||
buildDeletionEvent: {
|
||||
builder: buildDeletionEvent,
|
||||
type: NOTE_TYPES.DELETION,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
eventIds: ["e".repeat(64)],
|
||||
reason: "mistake",
|
||||
}
|
||||
},
|
||||
buildLegacyDirectMessageEvent: {
|
||||
builder: buildLegacyDirectMessageEvent,
|
||||
type: NOTE_TYPES.LEGACY_DM,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
recipientPubkey: PUBKEY,
|
||||
ciphertext: "encrypted",
|
||||
}
|
||||
},
|
||||
buildDmAttachmentEvent: {
|
||||
builder: buildDmAttachmentEvent,
|
||||
type: NOTE_TYPES.DM_ATTACHMENT,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
recipientPubkey: PUBKEY,
|
||||
attachment: { url: "https://example.com/file", x: "hash", type: "image/jpeg" },
|
||||
}
|
||||
},
|
||||
buildDmReadReceiptEvent: {
|
||||
builder: buildDmReadReceiptEvent,
|
||||
type: NOTE_TYPES.DM_READ_RECEIPT,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
recipientPubkey: PUBKEY,
|
||||
eventId: "e".repeat(64),
|
||||
}
|
||||
},
|
||||
buildDmTypingIndicatorEvent: {
|
||||
builder: buildDmTypingIndicatorEvent,
|
||||
type: NOTE_TYPES.DM_TYPING,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
recipientPubkey: PUBKEY,
|
||||
expiresAt: CREATED_AT + 60,
|
||||
}
|
||||
},
|
||||
buildViewEvent: {
|
||||
builder: buildViewEvent,
|
||||
type: NOTE_TYPES.VIEW_EVENT,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
pointerValue: "e".repeat(64),
|
||||
pointerTag: ["e", "e".repeat(64)],
|
||||
}
|
||||
},
|
||||
buildZapRequestEvent: {
|
||||
builder: buildZapRequestEvent,
|
||||
type: NOTE_TYPES.ZAP_REQUEST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
recipientPubkey: PUBKEY,
|
||||
amountSats: 100,
|
||||
relays: ["wss://relay.example.com"],
|
||||
}
|
||||
},
|
||||
buildReactionEvent: {
|
||||
builder: buildReactionEvent,
|
||||
type: NOTE_TYPES.VIDEO_REACTION,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
pointerValue: "e".repeat(64),
|
||||
targetPointer: { type: "e", value: "e".repeat(64) },
|
||||
content: "+",
|
||||
}
|
||||
},
|
||||
buildCommentEvent: {
|
||||
builder: buildCommentEvent,
|
||||
type: NOTE_TYPES.VIDEO_COMMENT,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
videoEventId: "e".repeat(64),
|
||||
content: "Nice video",
|
||||
}
|
||||
},
|
||||
buildWatchHistoryEvent: {
|
||||
builder: buildWatchHistoryEvent,
|
||||
type: NOTE_TYPES.WATCH_HISTORY,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
monthIdentifier: "2023-01",
|
||||
content: { version: 2, month: "2023-01", items: [] },
|
||||
}
|
||||
},
|
||||
buildSubscriptionListEvent: {
|
||||
builder: buildSubscriptionListEvent,
|
||||
type: NOTE_TYPES.SUBSCRIPTION_LIST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
content: "encrypted-json",
|
||||
encryption: "nip44_v2",
|
||||
}
|
||||
},
|
||||
buildBlockListEvent: {
|
||||
builder: buildBlockListEvent,
|
||||
type: NOTE_TYPES.USER_BLOCK_LIST,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
content: "encrypted-json",
|
||||
encryption: "nip44_v2",
|
||||
}
|
||||
},
|
||||
buildHashtagPreferenceEvent: {
|
||||
builder: buildHashtagPreferenceEvent,
|
||||
type: NOTE_TYPES.HASHTAG_PREFERENCES,
|
||||
params: {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
content: "encrypted-json",
|
||||
}
|
||||
},
|
||||
buildAdminListEvent: {
|
||||
builder: buildAdminListEvent,
|
||||
type: NOTE_TYPES.ADMIN_MODERATION_LIST,
|
||||
// Special handling for args
|
||||
args: ["moderation", {
|
||||
pubkey: PUBKEY,
|
||||
created_at: CREATED_AT,
|
||||
hexPubkeys: [PUBKEY],
|
||||
}]
|
||||
},
|
||||
};
|
||||
|
||||
function getUsedBuilders() {
|
||||
console.log("Scanning repo for event builder usage...");
|
||||
try {
|
||||
const output = execSync('grep -r "build[A-Za-z]\\+Event" js/', { encoding: 'utf-8' });
|
||||
const lines = output.split('\n');
|
||||
const usedBuilders = new Set();
|
||||
const regex = /(build[A-Za-z]+Event)/g;
|
||||
|
||||
lines.forEach(line => {
|
||||
// Skip the schemas file itself
|
||||
if (line.includes('js/nostrEventSchemas.js')) return;
|
||||
|
||||
const matches = line.match(regex);
|
||||
if (matches) {
|
||||
matches.forEach(match => usedBuilders.add(match));
|
||||
}
|
||||
});
|
||||
return usedBuilders;
|
||||
} catch (error) {
|
||||
// Grep returns status 1 if no matches found, which might throw an error in execSync
|
||||
// depending on the version/platform, or just empty output.
|
||||
console.error("Grep failed or found nothing:", error.message);
|
||||
return new Set();
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const usedBuilders = getUsedBuilders();
|
||||
console.log(`Found ${usedBuilders.size} unique builder(s) used in the codebase.`);
|
||||
|
||||
// also check if we missed any exported builder in our KNOWN_BUILDERS list
|
||||
// by assuming KNOWN_BUILDERS contains all we want to support.
|
||||
|
||||
let failureCount = 0;
|
||||
const missingTests = [];
|
||||
|
||||
usedBuilders.forEach(builderName => {
|
||||
if (!KNOWN_BUILDERS[builderName] && !IGNORED_BUILDERS.has(builderName)) {
|
||||
missingTests.push(builderName);
|
||||
}
|
||||
});
|
||||
|
||||
if (missingTests.length > 0) {
|
||||
console.warn("\n[WARNING] The following builders are used in the repo but have no test case in this script:");
|
||||
missingTests.forEach(name => console.warn(` - ${name}`));
|
||||
// We don't fail the build for this yet, but we warn.
|
||||
// Or maybe we should fail? The prompt said "Check runtime event construction...".
|
||||
// Let's count it as a "gap" but allow passing if validation of known ones works.
|
||||
}
|
||||
|
||||
console.log("\nValidating builders...");
|
||||
|
||||
for (const [name, config] of Object.entries(KNOWN_BUILDERS)) {
|
||||
// If we want to be strict, we could check if it is used. But validation is good regardless.
|
||||
const isUsed = usedBuilders.has(name);
|
||||
const usageLabel = isUsed ? "(USED)" : "(UNUSED)";
|
||||
|
||||
try {
|
||||
let event;
|
||||
if (config.args) {
|
||||
event = config.builder(...config.args);
|
||||
} else {
|
||||
event = config.builder(config.params);
|
||||
}
|
||||
|
||||
const { valid, errors } = validateEventStructure(config.type, event);
|
||||
|
||||
if (valid) {
|
||||
console.log(`[PASS] ${name} ${usageLabel}`);
|
||||
} else {
|
||||
console.error(`[FAIL] ${name} ${usageLabel}`);
|
||||
errors.forEach((err) => console.error(` - ${err}`));
|
||||
failureCount++;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[ERROR] ${name} ${usageLabel} threw an exception:`, e);
|
||||
failureCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (failureCount > 0) {
|
||||
console.error(`\nValidation failed with ${failureCount} errors.`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log("\nAll known builders validated successfully.");
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -315,7 +315,7 @@ test("NIP-07 login falls back when structured permissions fail", async () => {
|
||||
// With Structured -> String -> Plain order, this succeeds at step 2 (String).
|
||||
// So we expect 2 calls.
|
||||
assert.ok(env.enableCalls.length >= 2, "should retry with alternate payloads");
|
||||
const [objectCall, stringCall] = env.enableCalls;
|
||||
const [objectCall, stringCall, plainCall] = env.enableCalls;
|
||||
assert.ok(Array.isArray(objectCall?.permissions));
|
||||
assert.equal(
|
||||
typeof objectCall.permissions[0],
|
||||
|
||||
@@ -7,12 +7,15 @@ test.describe("embed layout and styling", () => {
|
||||
await page.goto("/embed.html?pointer=nevent123", { waitUntil: "domcontentloaded" });
|
||||
|
||||
// 1. Verify CSS Variable
|
||||
const accentColor = await page.evaluate(() => {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue("--bitvid-accent").trim();
|
||||
});
|
||||
// The configured color is #540011 (from config/instance-config.js)
|
||||
const expectedAccent = THEME_ACCENT_OVERRIDES?.light?.accent || "#ff6b6b";
|
||||
expect(accentColor).toBe(expectedAccent);
|
||||
|
||||
// Wait for the accent color to be applied by js/embed.js
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue("--bitvid-accent").trim();
|
||||
});
|
||||
}).toBe(expectedAccent);
|
||||
|
||||
// 2. Verify Video Element Styling
|
||||
const video = page.locator("#embedVideo");
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{IS_DEV_MODE as Le,IS_VERBOSE_DEV_MODE as Ce,IS_LOCKDOWN_MODE as Ae,LOCKDOWN_TITLE as bt,LOCKDOWN_MESSAGE as Et,ADMIN_SUPER_NPUB as Tt,ADMIN_DM_IMAGE_URL as gt,BITVID_WEBSITE_URL as _t,BLOG_URL as St,COMMUNITY_URL as wt,NOSTR_URL as Lt,GITHUB_URL as Ct,BETA_URL as At,DNS_URL as xt,TIP_JAR_URL as vt,MAX_WALLET_DEFAULT_ZAP as It,PLATFORM_FEE_PERCENT as Ot,PLATFORM_LUD16_OVERRIDE as Nt,DEFAULT_RELAY_URLS_OVERRIDE as Bt,ADMIN_WHITELIST_MODE_STORAGE_KEY as Mt,DEFAULT_WHITELIST_MODE_ENABLED as Dt,ALLOW_NSFW_CONTENT as Rt,DEFAULT_TRUST_SEED_NPUBS as Ht,DEFAULT_BLUR_THRESHOLD as Ut,DEFAULT_AUTOPLAY_BLOCK_THRESHOLD as kt,DEFAULT_TRUSTED_MUTE_HIDE_THRESHOLD as Ft,DEFAULT_TRUSTED_SPAM_HIDE_THRESHOLD as Pt,WATCH_HISTORY_KIND as Vt,WATCH_HISTORY_LIST_IDENTIFIER as Wt,WATCH_HISTORY_MAX_ITEMS as qt,WATCH_HISTORY_BATCH_RESOLVE as jt,WATCH_HISTORY_BATCH_PAGE_SIZE as $t,WATCH_HISTORY_PAYLOAD_MAX_BYTES as Yt,WATCH_HISTORY_FETCH_EVENT_LIMIT as Gt,WATCH_HISTORY_CACHE_TTL_MS as zt,VIEW_COUNT_DEDUPE_WINDOW_SECONDS as Kt,VIEW_COUNT_BACKFILL_MAX_DAYS as Xt,VIEW_COUNT_CACHE_TTL_MS as Zt,ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS as Jt}from"../config/instance-config.js";var H=!!Le;var xe=!!Ce;var ve=!!Ae;typeof window<"u"&&(window.__BITVID_DEV_MODE__=H,window.__BITVID_VERBOSE_DEV_MODE__=xe,window.__BITVID_LOCKDOWN_MODE__=ve);var k=()=>{};function Ie(){return typeof console>"u"||console===null?null:console}function Oe(){let e=Ie();if(!e)return{log:k,info:k,debug:k,warn:k,error:k};let t=typeof e.log=="function"?e.log.bind(e):k;return{log:typeof e.log=="function"?e.log.bind(e):t,info:typeof e.info=="function"?e.info.bind(e):t,debug:typeof e.debug=="function"?e.debug.bind(e):t,warn:typeof e.warn=="function"?e.warn.bind(e):t,error:typeof e.error=="function"?e.error.bind(e):t}}var _=Oe(),M="[bitvid]";function ee(e){if(e.length===0)return{args:e,force:!1};let t=e[e.length-1];if(t&&typeof t=="object"&&!Array.isArray(t)&&Object.prototype.hasOwnProperty.call(t,"force")){let r=[...e],o=r.pop();return{args:r,force:!!o.force}}return{args:e,force:!1}}var S=Object.freeze({log:(...e)=>{H&&_.log(...e)},info:(...e)=>{H&&_.info(...e)},debug:(...e)=>{H&&_.debug(...e)},warn:(...e)=>{H&&_.warn(...e)},error:(...e)=>{H&&_.error(...e)}}),y=Object.freeze({log:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.log(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.log(`${M} ${o}`);return}o!==void 0&&_.log(M,o)},info:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.info(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.info(`${M} ${o}`);return}o!==void 0&&_.info(M,o)},warn:(...e)=>{_.warn(M,...e)},error:(...e)=>{_.error(M,...e)}}),te=Object.freeze({dev:S,user:y});function Ne(e){return!e||typeof e!="object"?!1:Object.entries({dev:["log","info","debug","warn","error"],user:["log","info","warn","error"]}).every(([r,o])=>{let n=e[r];return!n||typeof n!="object"?!1:o.every(c=>typeof n[c]=="function")})}typeof window<"u"&&(Ne(window.bitvidLogger)||(window.bitvidLogger=te));Object.freeze(te);import{THEME_ACCENT_OVERRIDES as re}from"../config/instance-config.js";var K="bitvid:theme",v="dark",Be=new Set(["light","dark"]),ne={dark:"#0f172a",light:"#f8fafc"},oe=["[data-theme-toggle]",'[data-action="toggle-theme"]',".js-theme-toggle","#themeToggle"],ie=Object.freeze({accent:"--color-accent",accentStrong:"--color-accent-strong",accentPressed:"--color-accent-pressed"}),ae=new WeakSet,W=new Set,D=null,se=!1,F=null,I=()=>typeof window<"u"&&typeof document<"u",q=e=>{if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t==="default"||t===""?v:Be.has(t)?t:null},Me=()=>{if(!I())return null;try{let e=window.localStorage.getItem(K);return q(e)}catch(e){return y.warn("Unable to read stored theme preference:",e),null}},De=e=>{if(I())try{window.localStorage.setItem(K,e)}catch(t){y.warn("Unable to persist theme preference:",t)}},G=()=>{if(!I())return null;let{documentElement:e}=document;return e instanceof HTMLElement?e:null},Re=e=>typeof e=="string"?e.trim():"",He=e=>{if(!e||typeof e!="object")return null;let t=Object.entries(e).reduce((r,[o,n])=>{if(!n||typeof n!="object")return r;let c=Object.entries(n).reduce((a,[u,d])=>(Object.prototype.hasOwnProperty.call(ie,u)&&(a[u]=d),a),{});return Object.keys(c).length>0&&(r[o]=c),r},{});return Object.keys(t).length>0?t:null},ce=e=>{F=He(e)};ce(typeof re<"u"?re:null);var le=(e,t)=>{if(!e)return;let r=F&&typeof F=="object"&&F[t]&&typeof F[t]=="object"?F[t]:null,o=!1;Object.entries(ie).forEach(([n,c])=>{let a=r?r[n]:null,u=Re(a);u?(e.style.setProperty(c,u),o=!0):e.style.removeProperty(c)}),o?e.dataset.themeAccent="override":e.removeAttribute("data-theme-accent")},Ue=e=>{if(!I())return;let t=document.querySelector('meta[name="theme-color"]');if(!t)return;let r=G();if(!r)return;let o="";try{typeof window.getComputedStyle=="function"&&(o=getComputedStyle(r).getPropertyValue("--color-page").trim())}catch(a){y.warn("Unable to compute theme color tokenLine truncated
|
||||
import{IS_DEV_MODE as Le,IS_VERBOSE_DEV_MODE as Ae,IS_LOCKDOWN_MODE as Ce,LOCKDOWN_TITLE as yt,LOCKDOWN_MESSAGE as Et,ADMIN_SUPER_NPUB as Tt,ADMIN_DM_IMAGE_URL as gt,BITVID_WEBSITE_URL as _t,BLOG_URL as St,COMMUNITY_URL as wt,NOSTR_URL as Lt,GITHUB_URL as At,BETA_URL as Ct,DNS_URL as xt,TIP_JAR_URL as vt,MAX_WALLET_DEFAULT_ZAP as It,PLATFORM_FEE_PERCENT as Ot,PLATFORM_LUD16_OVERRIDE as Nt,DEFAULT_RELAY_URLS_OVERRIDE as Bt,ADMIN_WHITELIST_MODE_STORAGE_KEY as Mt,DEFAULT_WHITELIST_MODE_ENABLED as Dt,ALLOW_NSFW_CONTENT as Rt,DEFAULT_TRUST_SEED_NPUBS as Ut,DEFAULT_BLUR_THRESHOLD as Ht,DEFAULT_AUTOPLAY_BLOCK_THRESHOLD as kt,DEFAULT_TRUSTED_MUTE_HIDE_THRESHOLD as Ft,DEFAULT_TRUSTED_SPAM_HIDE_THRESHOLD as Pt,WATCH_HISTORY_KIND as Vt,WATCH_HISTORY_LIST_IDENTIFIER as Wt,WATCH_HISTORY_MAX_ITEMS as qt,WATCH_HISTORY_BATCH_RESOLVE as jt,WATCH_HISTORY_BATCH_PAGE_SIZE as $t,WATCH_HISTORY_PAYLOAD_MAX_BYTES as Yt,WATCH_HISTORY_FETCH_EVENT_LIMIT as Kt,WATCH_HISTORY_CACHE_TTL_MS as Gt,VIEW_COUNT_DEDUPE_WINDOW_SECONDS as zt,VIEW_COUNT_BACKFILL_MAX_DAYS as Xt,VIEW_COUNT_CACHE_TTL_MS as Zt,ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS as Jt,DEFAULT_PLAYBACK_SOURCE as Qt,DEFAULT_PLAYBACK_START_TIMEOUT as er}from"../config/instance-config.js";var U=!!Le;var xe=!!Ae;var ve=!!Ce;typeof window<"u"&&(window.__BITVID_DEV_MODE__=U,window.__BITVID_VERBOSE_DEV_MODE__=xe,window.__BITVID_LOCKDOWN_MODE__=ve);var k=()=>{};function Ie(){return typeof console>"u"||console===null?null:console}function Oe(){let e=Ie();if(!e)return{log:k,info:k,debug:k,warn:k,error:k};let t=typeof e.log=="function"?e.log.bind(e):k;return{log:typeof e.log=="function"?e.log.bind(e):t,info:typeof e.info=="function"?e.info.bind(e):t,debug:typeof e.debug=="function"?e.debug.bind(e):t,warn:typeof e.warn=="function"?e.warn.bind(e):t,error:typeof e.error=="function"?e.error.bind(e):t}}var _=Oe(),M="[bitvid]";function ee(e){if(e.length===0)return{args:e,force:!1};let t=e[e.length-1];if(t&&typeof t=="object"&&!Array.isArray(t)&&Object.prototype.hasOwnProperty.call(t,"force")){let r=[...e],o=r.pop();return{args:r,force:!!o.force}}return{args:e,force:!1}}var S=Object.freeze({log:(...e)=>{U&&_.log(...e)},info:(...e)=>{U&&_.info(...e)},debug:(...e)=>{U&&_.debug(...e)},warn:(...e)=>{U&&_.warn(...e)},error:(...e)=>{U&&_.error(...e)}}),b=Object.freeze({log:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.log(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.log(`${M} ${o}`);return}o!==void 0&&_.log(M,o)},info:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.info(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.info(`${M} ${o}`);return}o!==void 0&&_.info(M,o)},warn:(...e)=>{_.warn(M,...e)},error:(...e)=>{_.error(M,...e)}}),te=Object.freeze({dev:S,user:b});function Ne(e){return!e||typeof e!="object"?!1:Object.entries({dev:["log","info","debug","warn","error"],user:["log","info","warn","error"]}).every(([r,o])=>{let n=e[r];return!n||typeof n!="object"?!1:o.every(c=>typeof n[c]=="function")})}typeof window<"u"&&(Ne(window.bitvidLogger)||(window.bitvidLogger=te));Object.freeze(te);import{THEME_ACCENT_OVERRIDES as re}from"../config/instance-config.js";var z="bitvid:theme",v="dark",Be=new Set(["light","dark"]),ne={dark:"rgb(15, 23, 42)",light:"rgb(248, 250, 252)"},oe=["[data-theme-toggle]",'[data-action="toggle-theme"]',".js-theme-toggle","#themeToggle"],ie=Object.freeze({accent:"--color-accent",accentStrong:"--color-accent-strong",accentPressed:"--color-accent-pressed"}),ae=new WeakSet,W=new Set,D=null,se=!1,F=null,I=()=>typeof window<"u"&&typeof document<"u",q=e=>{if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t==="default"||t===""?v:Be.has(t)?t:null},Me=()=>{if(!I())return null;try{let e=window.localStorage.getItem(z);return q(e)}catch(e){return b.warn("Unable to read stored theme preference:",e),null}},De=e=>{if(I())try{window.localStorage.setItem(z,e)}catch(t){b.warn("Unable to persist theme preference:",t)}},K=()=>{if(!I())return null;let{documentElement:e}=document;return e instanceof HTMLElement?e:null},Re=e=>typeof e=="string"?e.trim():"",Ue=e=>{if(!e||typeof e!="object")return null;let t=Object.entries(e).reduce((r,[o,n])=>{if(!n||typeof n!="object")return r;let c=Object.entries(n).reduce((a,[u,d])=>(Object.prototype.hasOwnProperty.call(ie,u)&&(a[u]=d),a),{});return Object.keys(c).length>0&&(r[o]=c),r},{});return Object.keys(t).length>0?t:null},ce=e=>{F=Ue(e)};ce(typeof re<"u"?re:null);var le=(e,t)=>{if(!e)return;let r=F&&typeof F=="object"&&F[t]&&typeof F[t]=="object"?F[t]:null,o=!1;Object.entries(ie).forEach(([n,c])=>{let a=r?r[n]:null,u=Re(a);u?(e.style.setProperty(c,u),o=!0):e.style.removeProperty(c)}),o?e.dataset.themeAccent="override":e.removeAttribute("data-theme-accent")},He=e=>{if(!I())return;let t=document.querySelector('meta[name="theme-color"]');if(!t)return;let r=K();if(!r)return;let o="";try{typeof window.getComputedStyle=="function"&&(o=getComputedStyle(r).getPropLine truncated
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
var H=Math.min,B=Math.max,ot=Math.round,it=Math.floor,L=t=>({x:t,y:t}),qt={left:"right",right:"left",bottom:"top",top:"bottom"},Ut={start:"end",end:"start"};function lt(t,e,n){return B(t,H(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function V(t){return t.split("-")[0]}function K(t){return t.split("-")[1]}function pt(t){return t==="x"?"y":"x"}function at(t){return t==="y"?"height":"width"}var Kt=new Set(["top","bottom"]);function W(t){return Kt.has(V(t))?"y":"x"}function ft(t){return pt(W(t))}function Ot(t,e,n){n===void 0&&(n=!1);let o=K(t),i=ft(t),r=at(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=nt(s)),[s,nt(s)]}function Rt(t){let e=nt(t);return[ct(t),e,ct(e)]}function ct(t){return t.replace(/start|end/g,e=>Ut[e])}var bt=["left","right"],At=["right","left"],Gt=["top","bottom"],Jt=["bottom","top"];function Qt(t,e,n){switch(t){case"top":case"bottom":return n?e?At:bt:e?bt:At;case"left":case"right":return e?Gt:Jt;default:return[]}}function St(t,e,n,o){let i=K(t),r=Qt(V(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(ct)))),r}function nt(t){return t.replace(/left|right|bottom|top/g,e=>qt[e])}function Zt(t){return{top:0,right:0,bottom:0,left:0,...t}}function wt(t){return typeof t!="number"?Zt(t):{top:t,right:t,bottom:t,left:t}}function X(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Ct(t,e,n){let{reference:o,floating:i}=t,r=W(e),s=ft(e),c=at(s),a=V(e),l=r==="y",d=o.x+o.width/2-i.width/2,u=o.y+o.height/2-i.height/2,g=o[c]/2-i[c]/2,f;switch(a){case"top":f={x:d,y:o.y-i.height};break;case"bottom":f={x:d,y:o.y+o.height};break;case"right":f={x:o.x+o.width,y:u};break;case"left":f={x:o.x-i.width,y:u};break;default:f={x:o.x,y:o.y}}switch(K(e)){case"start":f[s]-=g*(n&&l?-1:1);break;case"end":f[s]+=g*(n&&l?-1:1);break}return f}var Pt=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,c=r.filter(Boolean),a=await(s.isRTL==null?void 0:s.isRTL(e)),l=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:u}=Ct(l,o,a),g=o,f={},m=0;for(let h=0;h<c.length;h++){let{name:w,fn:p}=c[h],{x,y,data:b,reset:v}=await p({x:d,y:u,initialPlacement:o,placement:g,strategy:i,middlewareData:f,rects:l,platform:s,elements:{reference:t,floating:e}});d=x??d,u=y??u,f={...f,[w]:{...f[w],...b}},v&&m<=50&&(m++,typeof v=="object"&&(v.placement&&(g=v.placement),v.rects&&(l=v.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):v.rects),{x:d,y:u}=Ct(l,g,a)),h=-1)}return{x:d,y:u,placement:g,strategy:i,middlewareData:f}};async function xt(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:c,strategy:a}=t,{boundary:l="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:g=!1,padding:f=0}=U(e,t),m=wt(f),w=c[g?u==="floating"?"reference":"floating":u],p=X(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(w)))==null||n?w:w.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(c.floating)),boundary:l,rootBoundary:d,strategy:a})),x=u==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,y=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c.floating)),b=await(r.isElement==null?void 0:r.isElement(y))?await(r.getScale==null?void 0:r.getScale(y))||{x:1,y:1}:{x:1,y:1},v=X(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:x,offsetParent:y,strategy:a}):x);return{top:(p.top-v.top+m.top)/b.y,bottom:(v.bottom-p.bottom+m.bottom)/b.y,left:(p.left-v.left+m.left)/b.x,right:(v.right-p.right+m.right)/b.x}}var Tt=t=>({name:"arrow",options:t,async fn(e){let{x:n,y:o,placement:i,rects:r,platform:s,elements:c,middlewareData:a}=e,{element:l,padding:d=0}=U(t,e)||{};if(l==null)return{};let u=wt(d),g={x:n,y:o},f=ft(i),m=at(f),h=await s.getDimensions(l),w=f==="y",p=w?"top":"left",x=w?"bottom":"right",y=w?"clientHeight":"clientWidth",b=r.reference[m]+r.reference[f]-g[f]-r.floating[m],v=g[f]-r.reference[f],M=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l)),R=M?M[y]:0;(!R||!await(s.isElement==null?void 0:s.isElement(M)))&&(R=c.floating[y]||r.floating[m]);let Z=b/2-v/2,_=R/2-h[m]/2-1,F=H(u[p],_),tt=H(u[x],_),z=F,et=R-h[m]-tt,A=R/2-h[m]/2+Z,I=lt(z,A,et),k=!a.arrow&&K(i)!=null&&A!==I&&r.reference[m]/2-(A<z?F:tt)-h[m]/2<0,P=k?A<z?A-z:A-et:0;return{[f]:g[f]+P,data:{[f]:I,centerOffset:A-I-P,...k&&{alignmentOffset:P}},reset:k}}});var Lt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:c,platform:a,elements:l}=e,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:g,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:h=!0,...w}=U(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let p=V(i),x=W(c),y=V(c)===c,b=await(a.iLine truncated
|
||||
var $=Math.min,B=Math.max,ot=Math.round,it=Math.floor,E=t=>({x:t,y:t}),qt={left:"right",right:"left",bottom:"top",top:"bottom"},Ut={start:"end",end:"start"};function lt(t,e,n){return B(t,$(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function V(t){return t.split("-")[0]}function K(t){return t.split("-")[1]}function pt(t){return t==="x"?"y":"x"}function at(t){return t==="y"?"height":"width"}var Kt=new Set(["top","bottom"]);function W(t){return Kt.has(V(t))?"y":"x"}function ft(t){return pt(W(t))}function At(t,e,n){n===void 0&&(n=!1);let o=K(t),i=ft(t),r=at(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=nt(s)),[s,nt(s)]}function Ot(t){let e=nt(t);return[ct(t),e,ct(e)]}function ct(t){return t.replace(/start|end/g,e=>Ut[e])}var vt=["left","right"],bt=["right","left"],Gt=["top","bottom"],Jt=["bottom","top"];function Qt(t,e,n){switch(t){case"top":case"bottom":return n?e?bt:vt:e?vt:bt;case"left":case"right":return e?Gt:Jt;default:return[]}}function Rt(t,e,n,o){let i=K(t),r=Qt(V(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(ct)))),r}function nt(t){return t.replace(/left|right|bottom|top/g,e=>qt[e])}function Zt(t){return{top:0,right:0,bottom:0,left:0,...t}}function wt(t){return typeof t!="number"?Zt(t):{top:t,right:t,bottom:t,left:t}}function X(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function St(t,e,n){let{reference:o,floating:i}=t,r=W(e),s=ft(e),c=at(s),l=V(e),a=r==="y",d=o.x+o.width/2-i.width/2,u=o.y+o.height/2-i.height/2,m=o[c]/2-i[c]/2,f;switch(l){case"top":f={x:d,y:o.y-i.height};break;case"bottom":f={x:d,y:o.y+o.height};break;case"right":f={x:o.x+o.width,y:u};break;case"left":f={x:o.x-i.width,y:u};break;default:f={x:o.x,y:o.y}}switch(K(e)){case"start":f[s]-=m*(n&&a?-1:1);break;case"end":f[s]+=m*(n&&a?-1:1);break}return f}async function Ct(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:c,strategy:l}=t,{boundary:a="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:m=!1,padding:f=0}=U(e,t),g=wt(f),w=c[m?u==="floating"?"reference":"floating":u],h=X(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(w)))==null||n?w:w.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(c.floating)),boundary:a,rootBoundary:d,strategy:l})),x=u==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,y=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c.floating)),v=await(r.isElement==null?void 0:r.isElement(y))?await(r.getScale==null?void 0:r.getScale(y))||{x:1,y:1}:{x:1,y:1},O=X(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:x,offsetParent:y,strategy:l}):x);return{top:(h.top-O.top+g.top)/v.y,bottom:(O.bottom-h.bottom+g.bottom)/v.y,left:(h.left-O.left+g.left)/v.x,right:(O.right-h.right+g.right)/v.x}}var Pt=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,c=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),a=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:u}=St(a,o,l),m=o,f={},g=0;for(let w=0;w<c.length;w++){var p;let{name:h,fn:x}=c[w],{x:y,y:v,data:O,reset:b}=await x({x:d,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:f,rects:a,platform:{...s,detectOverflow:(p=s.detectOverflow)!=null?p:Ct},elements:{reference:t,floating:e}});d=y??d,u=v??u,f={...f,[h]:{...f[h],...O}},b&&g<=50&&(g++,typeof b=="object"&&(b.placement&&(m=b.placement),b.rects&&(a=b.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):b.rects),{x:d,y:u}=St(a,m,l)),w=-1)}return{x:d,y:u,placement:m,strategy:i,middlewareData:f}},Tt=t=>({name:"arrow",options:t,async fn(e){let{x:n,y:o,placement:i,rects:r,platform:s,elements:c,middlewareData:l}=e,{element:a,padding:d=0}=U(t,e)||{};if(a==null)return{};let u=wt(d),m={x:n,y:o},f=ft(i),g=at(f),p=await s.getDimensions(a),w=f==="y",h=w?"top":"left",x=w?"bottom":"right",y=w?"clientHeight":"clientWidth",v=r.reference[g]+r.reference[f]-m[f]-r.floating[g],O=m[f]-r.reference[f],b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a)),S=b?b[y]:0;(!S||!await(s.isElement==null?void 0:s.isElement(b)))&&(S=c.floating[y]||r.floating[g]);let Z=v/2-O/2,z=S/2-p[g]/2-1,F=$(u[h],z),tt=$(u[x],z),_=F,et=S-p[g]-tt,A=S/2-p[g]/2+Z,I=lt(_,A,et),k=!l.arrow&&K(i)!=null&&A!==I&&r.reference[g]/2-(A<_?F:tt)-p[g]/2<0,T=k?A<_?A-_:A-et:0;return{[f]:m[f]+T,data:{[f]:I,centerOffset:A-I-T,...k&&{alignmentOffset:T}},reset:k}}});var Lt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:c,platform:l,elements:a}=e,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:p=!0,...w}=U(t,e);if((n=r.arrow)!=null&&n.alignmeLine truncated
|
||||
Reference in new issue
Block a user