Added georestriction with SFW mode.
This commit is contained in:
@@ -3,29 +3,36 @@ import redis from './redis.js';
|
||||
import initLogger from './logger.js';
|
||||
import entityPrefixes from './entities-prefixes.js';
|
||||
import { getAffiliateEntityUrl } from './affiliates.js';
|
||||
import { censor } from './censor.js';
|
||||
|
||||
const logger = initLogger();
|
||||
|
||||
export function curateEntity(entity, context) {
|
||||
export function curateEntity(entity, context = {}) {
|
||||
if (!entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const curatedEntity = {
|
||||
id: entity.id,
|
||||
name: entity.name,
|
||||
name: censor(entity.name, context.restriction),
|
||||
slug: entity.slug,
|
||||
type: entity.type,
|
||||
url: entity.url,
|
||||
isIndependent: entity.independent,
|
||||
hasLogo: entity.has_logo,
|
||||
hasLogo: context.restriction ? false : entity.has_logo,
|
||||
parent: curateEntity(entity.parent, context),
|
||||
tags: context?.tags?.map((tag) => ({
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
slug: tag.slug,
|
||||
})),
|
||||
children: context?.children?.filter((child) => child.parent_id === entity.id).map((child) => curateEntity({ ...child, parent: entity }, { parent: entity })) || [],
|
||||
children: context?.children?.filter((child) => child.parent_id === entity.id).map((child) => curateEntity({
|
||||
...child,
|
||||
parent: entity,
|
||||
}, {
|
||||
parent: entity,
|
||||
restriction: context.restriction,
|
||||
})) || [],
|
||||
affiliate: entity.affiliate ? {
|
||||
id: entity.affiliate.id,
|
||||
entityId: entity.affiliate.entity_id,
|
||||
@@ -44,7 +51,7 @@ export function curateEntity(entity, context) {
|
||||
return curatedEntity;
|
||||
}
|
||||
|
||||
export async function fetchEntities(options = {}) {
|
||||
export async function fetchEntities(options = {}, context) {
|
||||
const entities = await knex('entities')
|
||||
.select('entities.*', knex.raw('row_to_json(parents) as parent'))
|
||||
.modify((builder) => {
|
||||
@@ -93,11 +100,12 @@ export async function fetchEntities(options = {}) {
|
||||
.whereIn('entity_id', entities.map((entity) => entity.id));
|
||||
|
||||
return entities.map((entityEntry) => curateEntity(entityEntry, {
|
||||
...context,
|
||||
tags: entitiesTags.filter((tag) => tag.entity_id === entityEntry.id),
|
||||
}));
|
||||
}
|
||||
|
||||
export async function fetchEntitiesById(entityIds, options = {}, reqUser) {
|
||||
export async function fetchEntitiesById(entityIds, options = {}, reqUser, context) {
|
||||
const [entities, children, tags, alerts] = await Promise.all([
|
||||
knex('entities')
|
||||
.select(
|
||||
@@ -136,6 +144,7 @@ export async function fetchEntitiesById(entityIds, options = {}, reqUser) {
|
||||
|
||||
if (options.order) {
|
||||
return entities.map((entityEntry) => curateEntity(entityEntry, {
|
||||
...context,
|
||||
append: options.append,
|
||||
children: children.filter((channel) => channel.parent_id === entityEntry.id),
|
||||
alerts: alerts.filter((alert) => alert.entity_id === entityEntry.id),
|
||||
@@ -151,6 +160,7 @@ export async function fetchEntitiesById(entityIds, options = {}, reqUser) {
|
||||
}
|
||||
|
||||
return curateEntity(entity, {
|
||||
...context,
|
||||
append: options.append,
|
||||
children: children.filter((channel) => channel.parent_id === entity.id),
|
||||
tags: tags.filter((tag) => tag.entity_id === entity.id),
|
||||
|
||||
Reference in New Issue
Block a user