mirror of
https://github.com/docmost/docmost.git
synced 2026-05-19 16:04:17 +08:00
support audio imports
This commit is contained in:
@@ -335,6 +335,28 @@ export class ImportAttachmentService {
|
|||||||
unwrapFromParagraph($, $vid);
|
unwrapFromParagraph($, $vid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// audio
|
||||||
|
for (const audEl of $('audio').toArray()) {
|
||||||
|
const $aud = $(audEl);
|
||||||
|
const src = cleanUrlString($aud.attr('src') ?? '')!;
|
||||||
|
if (!src || src.startsWith('http')) continue;
|
||||||
|
|
||||||
|
const relPath = resolveRelativeAttachmentPath(
|
||||||
|
src,
|
||||||
|
pageDir,
|
||||||
|
attachmentCandidates,
|
||||||
|
);
|
||||||
|
if (!relPath) continue;
|
||||||
|
|
||||||
|
const { attachmentId, apiFilePath } = processFile(relPath);
|
||||||
|
|
||||||
|
$aud
|
||||||
|
.attr('src', apiFilePath)
|
||||||
|
.attr('data-attachment-id', attachmentId);
|
||||||
|
|
||||||
|
unwrapFromParagraph($, $aud);
|
||||||
|
}
|
||||||
|
|
||||||
// <div data-type="attachment">
|
// <div data-type="attachment">
|
||||||
for (const el of $('div[data-type="attachment"]').toArray()) {
|
for (const el of $('div[data-type="attachment"]').toArray()) {
|
||||||
const $oldDiv = $(el);
|
const $oldDiv = $(el);
|
||||||
@@ -401,6 +423,8 @@ export class ImportAttachmentService {
|
|||||||
const { attachmentId, apiFilePath, abs } = processFile(relPath);
|
const { attachmentId, apiFilePath, abs } = processFile(relPath);
|
||||||
const ext = path.extname(relPath).toLowerCase();
|
const ext = path.extname(relPath).toLowerCase();
|
||||||
|
|
||||||
|
const audioExtensions = new Set(['.mp3', '.wav', '.ogg', '.m4a', '.webm', '.flac', '.aac']);
|
||||||
|
|
||||||
if (ext === '.mp4') {
|
if (ext === '.mp4') {
|
||||||
const $video = $('<video>')
|
const $video = $('<video>')
|
||||||
.attr('src', apiFilePath)
|
.attr('src', apiFilePath)
|
||||||
@@ -409,6 +433,12 @@ export class ImportAttachmentService {
|
|||||||
.attr('data-align', 'center');
|
.attr('data-align', 'center');
|
||||||
$a.replaceWith($video);
|
$a.replaceWith($video);
|
||||||
unwrapFromParagraph($, $video);
|
unwrapFromParagraph($, $video);
|
||||||
|
} else if (audioExtensions.has(ext)) {
|
||||||
|
const $audio = $('<audio>')
|
||||||
|
.attr('src', apiFilePath)
|
||||||
|
.attr('data-attachment-id', attachmentId);
|
||||||
|
$a.replaceWith($audio);
|
||||||
|
unwrapFromParagraph($, $audio);
|
||||||
} else {
|
} else {
|
||||||
const confAliasName = $a.attr('data-linked-resource-default-alias');
|
const confAliasName = $a.attr('data-linked-resource-default-alias');
|
||||||
let attachmentName = path.basename(abs);
|
let attachmentName = path.basename(abs);
|
||||||
|
|||||||
Reference in New Issue
Block a user