mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
fix(electron): recorded audio is not correctly rendered after saved as attachment (#12232)
fix AF-2611 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the process for adding audio attachments after a recording is ready, ensuring all details (name, type, size, source, embed) are included at creation for a smoother and more reliable user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -51,33 +51,35 @@ export function setupRecordingEvents(frameworkProvider: FrameworkProvider) {
|
|||||||
const docProps: DocProps = {
|
const docProps: DocProps = {
|
||||||
onStoreLoad: (doc, { noteId }) => {
|
onStoreLoad: (doc, { noteId }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
// name + timestamp(readable) + extension
|
if (status.filepath) {
|
||||||
const attachmentName =
|
|
||||||
(status.appName ?? 'System Audio') + ' ' + timestamp + '.opus';
|
|
||||||
|
|
||||||
// add size and sourceId to the attachment later
|
|
||||||
const attachmentId = doc.addBlock(
|
|
||||||
'affine:attachment',
|
|
||||||
{
|
|
||||||
name: attachmentName,
|
|
||||||
type: 'audio/opus',
|
|
||||||
},
|
|
||||||
noteId
|
|
||||||
);
|
|
||||||
|
|
||||||
const model = doc.getBlock(attachmentId)
|
|
||||||
?.model as AttachmentBlockModel;
|
|
||||||
|
|
||||||
if (model && status.filepath) {
|
|
||||||
// it takes a while to save the blob, so we show the attachment first
|
// it takes a while to save the blob, so we show the attachment first
|
||||||
const { blobId, blob } = await saveRecordingBlob(
|
const { blobId, blob } = await saveRecordingBlob(
|
||||||
doc.workspace.blobSync,
|
doc.workspace.blobSync,
|
||||||
status.filepath
|
status.filepath
|
||||||
);
|
);
|
||||||
|
|
||||||
model.props.size = blob.size;
|
// name + timestamp(readable) + extension
|
||||||
model.props.sourceId = blobId;
|
const attachmentName =
|
||||||
model.props.embed = true;
|
(status.appName ?? 'System Audio') +
|
||||||
|
' ' +
|
||||||
|
timestamp +
|
||||||
|
'.opus';
|
||||||
|
|
||||||
|
// add size and sourceId to the attachment later
|
||||||
|
const attachmentId = doc.addBlock(
|
||||||
|
'affine:attachment',
|
||||||
|
{
|
||||||
|
name: attachmentName,
|
||||||
|
type: 'audio/opus',
|
||||||
|
size: blob.size,
|
||||||
|
sourceId: blobId,
|
||||||
|
embed: true,
|
||||||
|
},
|
||||||
|
noteId
|
||||||
|
);
|
||||||
|
|
||||||
|
const model = doc.getBlock(attachmentId)
|
||||||
|
?.model as AttachmentBlockModel;
|
||||||
|
|
||||||
if (!aiEnabled) {
|
if (!aiEnabled) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user