Skip to content

Commit

Permalink
for review update
Browse files Browse the repository at this point in the history
  • Loading branch information
rbi-aap committed Sep 13, 2024
1 parent bb82ebe commit 1019cb7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 48 deletions.
24 changes: 8 additions & 16 deletions assets/ui/components/ArticleBodyHtml.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ import {formatHTML} from 'utils';
import {connect} from 'react-redux';
import {selectCopy} from '../../wire/actions';
import DOMPurify from 'dompurify';
// import fallbackDefault from 'images/poster_default.jpg'
const fallbackDefault = '/static/poster_default.jpg';

class ArticleBodyHtml extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
sanitizedHtml: '',
memoryUsage: null
};
this.copyClicked = this.copyClicked.bind(this);
this.clickClicked = this.clickClicked.bind(this);
this.preventContextMenu = this.preventContextMenu.bind(this);
this.getBodyHTML = memoize(this._getBodyHTML.bind(this));
this.bodyRef = React.createRef();
this.players = new Map();
this.memoryInterval = null;
}

componentDidMount() {
Expand Down Expand Up @@ -53,9 +50,9 @@ class ArticleBodyHtml extends React.PureComponent {
this.players.forEach(player => player.destroy());
this.players.clear();

if (this.memoryInterval) {
clearInterval(this.memoryInterval);
}
// if (this.memoryInterval) {
// clearInterval(this.memoryInterval);
// }
}

startMemoryUsageTracking() {
Expand Down Expand Up @@ -232,8 +229,6 @@ class ArticleBodyHtml extends React.PureComponent {
return;
}
const loadHandler = () => {
// eslint-disable-next-line no-console
console.log('Initial dimensions:', player.media.videoWidth, player.media.videoHeight);
const checkVideoContent = () => {
if (player.media.videoWidth > 0 && player.media.videoHeight > 0) {
const canvas = document.createElement('canvas');
Expand All @@ -245,12 +240,10 @@ class ArticleBodyHtml extends React.PureComponent {
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
// loop for none blank pixel
let stepSize = 4; // Adjust the step size as needed
let stepSize = 8; // Adjust the step size
for (let i = 0; i < data.length; i += stepSize * 4) {
if (data[i] > 0 || data[i + 1] > 0 || data[i + 2] > 0) {

// eslint-disable-next-line no-console
console.log('Pixel content detected, poster not needed');
console.warn('Pixel content detected, poster not needed');
return true;
}
}
Expand All @@ -261,15 +254,14 @@ class ArticleBodyHtml extends React.PureComponent {
const attemptContentCheck = () => {
if (checkVideoContent()) {
player.poster = null;
// eslint-disable-next-line no-console
console.log('Pixel content detected, poster removed');
console.warn('Pixel content detected, poster removed');
return true;
}
return false;
};

let attemptCount = 0;
const maxAttempts = 2;
const maxAttempts = 1;
const checkInterval = setInterval(() => {
if (attemptContentCheck() || attemptCount >= maxAttempts) {
clearInterval(checkInterval);
Expand All @@ -285,7 +277,7 @@ class ArticleBodyHtml extends React.PureComponent {
};

player.on('error', (error) => {
console.error('Error details:', {
console.error('Error details and location:', {
message: error.message,
code: error.code,
type: error.type,
Expand Down
2 changes: 1 addition & 1 deletion newsroom/companies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def update_company(data, _id):
@account_manager_only
def save_company_permissions(_id):
csrf_token = request.headers.get('X-CSRF-Token')
expected_csrf_token = session.get('csrf_token')
expected_csrf_token = session.pop('csrf_token')
orig = get_entity_or_404(_id, 'companies')
data = get_json_or_400()
if not csrf_token or csrf_token != expected_csrf_token:
Expand Down
17 changes: 17 additions & 0 deletions newsroom/wire/block_media/download_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@


def filter_items_download(func):
"""
A decorator that filters downloaded items based on a given filter function.
:param func: The function to be decorated. It should take _ids and item_type as parameters
and return a list of items.
:return: A wrapper function that adds filtering capability to the decorated function.
"""
def wrapper(_ids, item_type, filter_func=None):
"""
Wrapper function that calls the decorated function and applies optional filtering.
:param _ids: List of IDs to download items for.
:param item_type: Type of items to download .
:param filter_func: Optional function to filter the downloaded items.
default is None, no filtering is applied.
:return: A list of downloaded items, potentially filtered if a filter_func is provided
and the item_type is not 'agenda'.
"""
items = func(_ids, item_type)
if filter_func and items and (item_type != 'agenda'):
items = filter_func(items)
Expand Down
29 changes: 0 additions & 29 deletions newsroom/wire/block_media/permission_media.py

This file was deleted.

4 changes: 2 additions & 2 deletions newsroom/wire/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime, timedelta
from copy import deepcopy
from eve.utils import ParsedRequest, config
Expand All @@ -18,9 +19,8 @@
from newsroom.companies import get_user_company
from newsroom.products.products import get_products_by_company
from newsroom.wire.block_media.filter_media import filter_media
from superdesk.logging import logger

# logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


def get_bookmarks_count(user_id, product_type):
Expand Down

0 comments on commit 1019cb7

Please sign in to comment.