MM-53764 - Fix: Improve limits on Opengraph Data Cache (#24177)

* enforce strict opengraph cache entry size limit

* move json marshalling and error checking into parsOpenGraphMetadata fn

* fix linting

* fix potential nil deref

* Revert "fix potential nil deref"

This reverts commit 095bcd496e9b8d97ca63d3a99e2e46eec58ef7ae.

* Revert "fix linting"

This reverts commit f3e1f7b27634ca0567fd0fef01ac23f5e39009a7.

* Revert "move json marshalling and error checking into parsOpenGraphMetadata fn"

This reverts commit ba9a1e13b0fb9d4579077b7b37666e950a5fb6ed.

* Revert "enforce strict opengraph cache entry size limit"

This reverts commit d1de4a8fa40e58ac85c85f66de27ec5aca884b18.

* remove /opengraph api endpoint

* i18n

* removing unneeded action and reducer
Этот коммит содержится в:
Christopher Poile
2023-08-17 18:23:39 -04:00
коммит произвёл GitHub
родитель ad142c958e
Коммит 7b0b0d8609
12 изменённых файлов: 0 добавлений и 253 удалений

Просмотреть файл

@@ -47,7 +47,6 @@ export default keyMirror({
RECEIVED_REACTION: null,
RECEIVED_REACTIONS: null,
REACTION_DELETED: null,
RECEIVED_OPEN_GRAPH_METADATA: null,
ADD_MESSAGE_INTO_HISTORY: null,
RESET_HISTORY_INDEX: null,

Просмотреть файл

@@ -1335,36 +1335,6 @@ describe('Actions.Posts', () => {
expect(state.entities.emojis.nonExistentEmoji.has(missingEmojiName)).toBeTruthy();
});
it('getOpenGraphMetadata', async () => {
const {dispatch, getState} = store;
const url = 'https://mattermost.com';
const docs = 'https://docs.mattermost.com/';
nock(Client4.getBaseRoute()).
post('/opengraph').
reply(200, {type: 'article', url: 'https://mattermost.com/', title: 'Mattermost private cloud messaging', description: 'Open source, private cloud\nSlack-alternative, \nWorkplace messaging for web, PCs and phones.'});
await dispatch(Actions.getOpenGraphMetadata(url));
nock(Client4.getBaseRoute()).
post('/opengraph').
reply(200, {type: '', url: '', title: '', description: ''});
await dispatch(Actions.getOpenGraphMetadata(docs));
nock(Client4.getBaseRoute()).
post('/opengraph').
reply(200, undefined);
await dispatch(Actions.getOpenGraphMetadata(docs));
const state = getState();
const metadata = state.entities.posts.openGraph;
expect(metadata).toBeTruthy();
expect(metadata[url]).toBeTruthy();
if (metadata[docs]) {
throw new Error('unexpected metadata[docs]');
}
});
it('doPostAction', async () => {
nock(Client4.getBaseRoute()).
post('/posts/posth67ja7ntdkek6g13dp3wka/actions/action7ja7ntdkek6g13dp3wka').

Просмотреть файл

@@ -1269,29 +1269,6 @@ export function addPostReminder(userId: string, postId: string, timestamp: numbe
};
}
export function getOpenGraphMetadata(url: string) {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
let data;
try {
data = await Client4.getOpenGraphMetadata(url);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(logError(error));
return {error};
}
if (data && (data.url || data.type || data.title || data.description)) {
dispatch({
type: PostTypes.RECEIVED_OPEN_GRAPH_METADATA,
data,
url,
});
}
return {data};
};
}
export function doPostAction(postId: string, actionId: string, selectedOption = '') {
return doPostActionWithCookie(postId, actionId, '', selectedOption);
}

Просмотреть файл

@@ -1357,13 +1357,6 @@ function storeAcknowledgementsForPost(state: any, post: Post) {
export function openGraph(state: RelationOneToOne<Post, Record<string, OpenGraphMetadata>> = {}, action: GenericAction) {
switch (action.type) {
case PostTypes.RECEIVED_OPEN_GRAPH_METADATA: {
const nextState = {...state};
nextState[action.url] = action.data;
return nextState;
}
case PostTypes.RECEIVED_NEW_POST:
case PostTypes.RECEIVED_POST: {
const post = action.data;

Просмотреть файл

@@ -2214,13 +2214,6 @@ export default class Client4 {
return this.searchFilesWithParams(teamId, {terms, is_or_search: isOrSearch});
};
getOpenGraphMetadata = (url: string) => {
return this.doFetch<OpenGraphMetadata>(
`${this.getBaseRoute()}/opengraph`,
{method: 'post', body: JSON.stringify({url})},
);
};
doPostAction = (postId: string, actionId: string, selectedOption = '') => {
return this.doPostActionWithCookie(postId, actionId, '', selectedOption);
};