feat(mobile): share history as Markdown or original audio and harden the E2E gate

Adds history share (Markdown file / original audio) with 12-locale strings, pins Maestro to
the target device with --udid, allows cleartext only for explicit local E2E artifacts, and
fixes small-screen scroll/keyboard races in the Maestro flows.
Evidence: docs/evidence/2026-11-17-backlog-operations.md.
This commit is contained in:
Yun Chan 2026-11-20 15:16:13 +09:00
parent e0b1ceaa75
commit 8d8aaf5794
29 changed files with 627 additions and 26 deletions

View file

@ -224,7 +224,7 @@ export interface PreparedPortableFile {
uri: string;
fileName: string;
mimeType: string;
format: PortableTextFormat | MeetingDocumentFormat;
format: PortableTextFormat | MeetingDocumentFormat | 'binary';
textContent: string | null;
dispose: () => Promise<void>;
}

View file

@ -74,7 +74,7 @@ async function disposeExport(path: string): Promise<void> {
if (await FileSystem.exists(path)) await FileSystem.unlink(path);
}
async function persistExport(options: {
export async function persistExport(options: {
baseName: string;
extension: string;
mimeType: string;

View file

@ -0,0 +1,94 @@
import type { AudioFile, HistoryEntry } from '@d3ro/api-client';
import { persistExport } from '../data-portability/portable-file';
import type { PreparedPortableFile } from '../data-portability/portability-types';
export const MAX_SHARED_AUDIO_BYTES = 50 * 1024 * 1024;
export type TranscriptShareFormat = 'txt' | 'md';
type TranscriptShareEntry = Pick<
HistoryEntry,
'title' | 'original_text' | 'polished_text' | 'summary_text'
>;
export function buildTranscriptShareText(
entry: TranscriptShareEntry,
format: TranscriptShareFormat,
summaryLabel: string,
): string {
const title = entry.title?.replace(/\s*\r?\n\s*/g, ' ').trim() ?? '';
const transcript = entry.polished_text?.trim() || entry.original_text.trim();
const summary = entry.summary_text?.trim() ?? '';
const sections = [
format === 'md' && title !== '' ? `# ${title}` : title,
transcript,
];
if (summary !== '') {
sections.push(`${format === 'md' ? '## ' : ''}${summaryLabel}`, summary);
}
return sections.filter(section => section !== '').join('\n\n');
}
export function prepareTranscriptShareFile(
entry: TranscriptShareEntry,
format: TranscriptShareFormat,
summaryLabel: string,
): Promise<PreparedPortableFile> {
return persistExport({
baseName: entry.title?.trim() || 'd3ro-transcript',
extension: format,
mimeType: format === 'md' ? 'text/markdown' : 'text/plain',
format,
text: buildTranscriptShareText(entry, format, summaryLabel),
bytes: null,
});
}
const AUDIO_EXTENSIONS: Readonly<Record<string, string>> = {
'audio/aac': 'aac',
'audio/flac': 'flac',
'audio/mp4': 'm4a',
'audio/mpeg': 'mp3',
'audio/ogg': 'ogg',
'audio/wav': 'wav',
'audio/wave': 'wav',
'audio/webm': 'webm',
'audio/x-m4a': 'm4a',
'audio/x-wav': 'wav',
'video/mp4': 'mp4',
};
export async function prepareAudioShareFile(
audioFile: Pick<AudioFile, 'mime_type' | 'original_name' | 'size_bytes'>,
signedUrl: string,
fetchAudio: typeof fetch = fetch,
): Promise<PreparedPortableFile> {
const mimeType = audioFile.mime_type.toLowerCase().split(';')[0].trim();
const extension = AUDIO_EXTENSIONS[mimeType];
if (extension === undefined) throw new Error('Unsupported audio share format');
if (audioFile.size_bytes > MAX_SHARED_AUDIO_BYTES) throw new Error('Audio share exceeds 50 MiB');
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 30_000);
try {
const response = await fetchAudio(signedUrl, { signal: controller.signal });
if (!response.ok) throw new Error(`Audio download failed with HTTP ${response.status}`);
const declaredLength = Number(response.headers.get('content-length'));
if (Number.isFinite(declaredLength) && declaredLength > MAX_SHARED_AUDIO_BYTES) {
throw new Error('Audio share exceeds 50 MiB');
}
const bytes = new Uint8Array(await response.arrayBuffer());
if (bytes.byteLength === 0) throw new Error('Audio share is empty');
if (bytes.byteLength > MAX_SHARED_AUDIO_BYTES) throw new Error('Audio share exceeds 50 MiB');
return await persistExport({
baseName: audioFile.original_name?.replace(/\.[^.]+$/, '') || 'd3ro-audio',
extension,
mimeType,
format: 'binary',
text: null,
bytes,
});
} finally {
clearTimeout(timeout);
}
}

View file

@ -30,6 +30,14 @@ import {
type HistoryDetail,
} from '../features/history/history-service'
import { loadHistoryCache } from '../features/history/history-cache'
import {
prepareAudioShareFile,
prepareTranscriptShareFile,
} from '../features/history/history-share'
import {
sharePreparedPortableFile,
} from '../features/data-portability/portable-file'
import type { PreparedPortableFile } from '../features/data-portability/portability-types'
import { useMobilePreferences } from '../lib/preferences-context'
const HISTORY_MODE_KEYS: Record<HistoryEntry['mode'], TranslationKey> = {
@ -104,6 +112,8 @@ export default function HistoryDetailScreen({
const [activeAudioId, setActiveAudioId] = useState<string | null>(null)
const [paused, setPaused] = useState(false)
const [audioBusy, setAudioBusy] = useState(false)
const [sharingFile, setSharingFile] = useState(false)
const [sharingAudioId, setSharingAudioId] = useState<string | null>(null)
useEffect(() => {
mountedRef.current = true
@ -306,6 +316,48 @@ export default function HistoryDetailScreen({
}
}
const shareTranscriptFile = async (): Promise<void> => {
if (detail === null || sharingFile) return
setSharingFile(true)
setError(null)
let file: PreparedPortableFile | null = null
try {
file = await prepareTranscriptShareFile(detail.entry, 'md', t('mobile.hist.summaryLabel'))
if (!mountedRef.current) {
await file.dispose().catch(() => undefined)
return
}
await sharePreparedPortableFile(file, t('mobile.hist.shareMarkdown'))
} catch {
if (file !== null) await file.dispose().catch(() => undefined)
if (mountedRef.current) setError(t('mobile.hist.shareFailed'))
} finally {
if (mountedRef.current) setSharingFile(false)
}
}
const shareAudio = async (audioFile: AudioFile): Promise<void> => {
if (user === null || sharingAudioId !== null || offline || audioFile.upload_status !== 'uploaded') return
setSharingAudioId(audioFile.id)
setError(null)
let file: PreparedPortableFile | null = null
try {
const signedUrl = await createAudioPlaybackUrl(user.id, audioFile)
if (!mountedRef.current) return
file = await prepareAudioShareFile(audioFile, signedUrl)
if (!mountedRef.current) {
await file.dispose().catch(() => undefined)
return
}
await sharePreparedPortableFile(file, t('mobile.hist.shareAudio'))
} catch {
if (file !== null) await file.dispose().catch(() => undefined)
if (mountedRef.current) setError(t('mobile.hist.audioError'))
} finally {
if (mountedRef.current) setSharingAudioId(null)
}
}
const controlAudio = async (audioFile: AudioFile): Promise<void> => {
if (user === null || audioBusy) return
const playbackGeneration = ++playbackGenerationRef.current
@ -478,6 +530,16 @@ export default function HistoryDetailScreen({
>
<PhosphorText variant="small" color="primary">{t('mobile.hist.share')}</PhosphorText>
</Pressable>
<Pressable
accessibilityRole="button"
accessibilityLabel={t('mobile.hist.shareMarkdown')}
disabled={sharingFile || saving || editing}
onPress={() => { void shareTranscriptFile() }}
style={styles.compactButton}
testID="history-detail-share-markdown"
>
<PhosphorText variant="small" color="primary">{t('mobile.hist.shareMarkdown')}</PhosphorText>
</Pressable>
</View>
<FieldLabel label={t('mobile.hist.titleLabel')} />
@ -611,6 +673,16 @@ export default function HistoryDetailScreen({
: t('mobile.hist.audioPlay')}
</PhosphorText>
</Pressable>
<Pressable
accessibilityRole="button"
accessibilityLabel={t('mobile.hist.shareAudio')}
disabled={audioBusy || sharingAudioId !== null || audioFile.upload_status !== 'uploaded' || offline}
onPress={() => { void shareAudio(audioFile) }}
style={styles.compactButton}
testID={`history-audio-share-${audioFile.id}`}
>
<PhosphorText variant="small" color="primary">{t('mobile.hist.share')}</PhosphorText>
</Pressable>
</View>
))}
{activeAudioId !== null && (
@ -729,7 +801,7 @@ function createStyles(palette: Palette) {
},
inlineButton: { minHeight: 48, justifyContent: 'center' },
primaryCard: { gap: 8 },
actionRow: { flexDirection: 'row', justifyContent: 'flex-end', gap: 8, marginBottom: 4 },
actionRow: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8, marginBottom: 4 },
compactButton: {
minWidth: 48,
minHeight: 48,