Skip to content

Commit

Permalink
fix decompression order
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhniebergall committed Dec 29, 2024
1 parent 292913b commit 5eae753
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions frontend/src/operators/FeedOperator.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
import axios from 'axios';
import { BaseOperator } from './BaseOperator';
import compression from '../utils/compression';

class FeedOperator extends BaseOperator {
async getFeedItems(page) {
try {
const data = await this.retryApiCall(
() => axios.get(`${this.baseURL}/api/feed`, {
params: { page }
})
);
const response = await axios.get(`${this.baseURL}/api/feed`, {
params: { page }
});

// Parse the stringified JSON items
if (data?.items) {
const parsedItems = data.items.map(item => {
try {
return typeof item === 'string' ? JSON.parse(item) : item;
} catch (e) {
console.error('Error parsing feed item:', e);
return null;
// Check if we got compressed data
if (response.headers['x-data-compressed'] === 'true') {
const decompressedData = await compression.decompress(response.data);
return {
success: true,
data: {
page,
items: decompressedData.items.map(item => {
try {
return typeof item === 'string' ? JSON.parse(item) : item;
} catch (e) {
console.error('Error parsing feed item:', e);
return null;
}
}).filter(Boolean)
}
}).filter(Boolean); // Remove any null items from parsing errors
};
}

// Handle uncompressed data
if (response.data?.items) {
return {
success: true,
data: {
...data,
items: parsedItems
...response.data,
items: response.data.items.map(item => {
try {
return typeof item === 'string' ? JSON.parse(item) : item;
} catch (e) {
console.error('Error parsing feed item:', e);
return null;
}
}).filter(Boolean)
}
};
}

return { success: true, data };
return { success: true, data: response.data };
} catch (error) {
console.error('Error fetching feed items:', error);
return {
Expand Down

0 comments on commit 5eae753

Please sign in to comment.