Resolved merge conflict

This commit is contained in:
GigiaJ
2025-05-22 20:28:19 -05:00
21 changed files with 481 additions and 119 deletions

View File

@@ -1,4 +1,4 @@
import { encode } from 'blurhash';
import { encode, isBlurhashValid } from 'blurhash';
export const encodeBlurHash = (
img: HTMLImageElement | HTMLVideoElement,
@@ -17,3 +17,13 @@ export const encodeBlurHash = (
const data = context.getImageData(0, 0, canvas.width, canvas.height);
return encode(data.data, data.width, data.height, 4, 4);
};
export const validBlurHash = (hash?: string): string | undefined => {
if (typeof hash === 'string') {
const validity = isBlurhashValid(hash);
return validity.result ? hash : undefined;
}
return undefined;
};

View File

@@ -125,3 +125,9 @@ export const suffixRename = (name: string, validator: (newName: string) => boole
};
export const replaceSpaceWithDash = (str: string): string => str.replace(/ /g, '-');
export const splitWithSpace = (content: string): string[] => {
const trimmedContent = content.trim();
if (trimmedContent === '') return [];
return trimmedContent.split(' ');
};

View File

@@ -13,11 +13,16 @@ import {
UploadProgress,
UploadResponse,
} from 'matrix-js-sdk';
import to from 'await-to-js';
import { IImageInfo, IThumbnailContent, IVideoInfo } from '../../types/matrix/common';
import { AccountDataEvent } from '../../types/matrix/accountData';
import { getStateEvent } from './room';
import { StateEvent } from '../../types/matrix/room';
const DOMAIN_REGEX = /\b(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\b/;
export const isServerName = (serverName: string): boolean => DOMAIN_REGEX.test(serverName);
export const matchMxId = (id: string): RegExpMatchArray | null => id.match(/^([@!$+#])(.+):(\S+)$/);
export const validMxId = (id: string): boolean => !!matchMxId(id);
@@ -292,3 +297,35 @@ export const downloadEncryptedMedia = async (
return decryptedContent;
};
export const rateLimitedActions = async <T, R = void>(
data: T[],
callback: (item: T) => Promise<R>,
maxRetryCount?: number
) => {
let retryCount = 0;
const performAction = async (dataItem: T) => {
const [err] = await to<R, MatrixError>(callback(dataItem));
if (err?.httpStatus === 429) {
if (retryCount === maxRetryCount) {
return;
}
const waitMS = err.getRetryAfterMs() ?? 200;
await new Promise((resolve) => {
setTimeout(resolve, waitMS);
});
retryCount += 1;
await performAction(dataItem);
}
};
for (let i = 0; i < data.length; i += 1) {
const dataItem = data[i];
retryCount = 0;
// eslint-disable-next-line no-await-in-loop
await performAction(dataItem);
}
};