From review: sanitizeFilename now denylists only path-hostile + control chars (preserving Unicode room names instead of collapsing CJK/emoji names to "room"), converts whitespace to dashes, trims separator runs, and caps length. Also surface an inline error when canvas.toBlob returns null so a failed PNG encode isn't a silent no-op. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
147 lines
5.2 KiB
TypeScript
147 lines
5.2 KiB
TypeScript
import React, { useCallback, useRef, useState } from 'react';
|
|
import { Box, Button, color, config, Icon, Icons, Text } from 'folds';
|
|
import { QRCodeSVG, QRCodeCanvas } from 'qrcode.react';
|
|
import { SequenceCard } from '../../../components/sequence-card';
|
|
import { SequenceCardStyle } from '../../room-settings/styles.css';
|
|
import { SettingTile } from '../../../components/setting-tile';
|
|
import { CutoutCard } from '../../../components/cutout-card';
|
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
|
import { useRoom } from '../../../hooks/useRoom';
|
|
import { getMatrixToRoom } from '../../../plugins/matrix-to';
|
|
import { useSaveFile } from '../../../hooks/useSaveFile';
|
|
|
|
// Filesystem-safe basename from an arbitrary room name. Denylist only the
|
|
// path-hostile / control characters so Unicode names (CJK, Cyrillic, emoji, …)
|
|
// survive instead of being stripped to the 'room' fallback. Collapse whitespace,
|
|
// trim separator runs, and cap length to stay under filesystem name limits.
|
|
// eslint-disable-next-line no-control-regex
|
|
const UNSAFE_FILENAME = /[/\\:*?"<>| |