59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import type { PlatformBrowseHistoryEntry } from '../../../packages/shared/src/contracts/runtime';
|
|
import type { PlatformPublicGalleryCard } from '../rpg-entry/rpgEntryWorldPresentation';
|
|
|
|
export const EDUTAINMENT_WORK_TAG = '寓教于乐';
|
|
export const EDUTAINMENT_HIDDEN_MESSAGE = '该内容暂不可见。';
|
|
|
|
const EDUTAINMENT_ENTRY_DISABLED_VALUES = new Set(['false', '0', 'off', 'no']);
|
|
|
|
// 中文注释:入口默认开启;只有明确写入关闭值时才完全隐藏寓教于乐内容。
|
|
export function isEdutainmentEntryEnabled(
|
|
rawValue = import.meta.env.VITE_ENABLE_EDUTAINMENT_ENTRY,
|
|
) {
|
|
const normalized = (rawValue ?? '').trim().toLowerCase();
|
|
return !EDUTAINMENT_ENTRY_DISABLED_VALUES.has(normalized);
|
|
}
|
|
|
|
function getPlatformPublicWorkTags(entry: PlatformPublicGalleryCard) {
|
|
if ('themeTags' in entry) {
|
|
return entry.themeTags;
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
export function isEdutainmentPublicWork(entry: PlatformPublicGalleryCard) {
|
|
return getPlatformPublicWorkTags(entry).some(
|
|
(tag) => tag === EDUTAINMENT_WORK_TAG,
|
|
);
|
|
}
|
|
|
|
export function canExposePublicWork(entry: PlatformPublicGalleryCard) {
|
|
return isEdutainmentEntryEnabled() || !isEdutainmentPublicWork(entry);
|
|
}
|
|
|
|
export function filterGeneralPublicWorks(entries: PlatformPublicGalleryCard[]) {
|
|
return entries.filter((entry) => !isEdutainmentPublicWork(entry));
|
|
}
|
|
|
|
export function filterEdutainmentPublicWorks(
|
|
entries: PlatformPublicGalleryCard[],
|
|
) {
|
|
return entries.filter(isEdutainmentPublicWork);
|
|
}
|
|
|
|
export function filterVisiblePublicWorks(entries: PlatformPublicGalleryCard[]) {
|
|
return entries.filter(canExposePublicWork);
|
|
}
|
|
|
|
export function findPublicWorkForHistoryEntry(
|
|
historyEntry: PlatformBrowseHistoryEntry,
|
|
entries: PlatformPublicGalleryCard[],
|
|
) {
|
|
return entries.find(
|
|
(entry) =>
|
|
entry.ownerUserId === historyEntry.ownerUserId &&
|
|
entry.profileId === historyEntry.profileId,
|
|
);
|
|
}
|