Skip to content

Commit

Permalink
Merge pull request #9 from IronBlood/hotfix/audio-video
Browse files Browse the repository at this point in the history
audio video 标签及 mp4 魔数
  • Loading branch information
IronBlood committed Apr 21, 2021
2 parents 676fd2c + 8c5c036 commit 4c94ae9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bmybbs/bmybbs-content-parser",
"version": "0.3.0",
"version": "0.3.1",
"description": "This is a library to convert bmybbs content, including articles and mails, to HTML format.",
"main": "dist/index.js",
"types": "dist/index.d.js",
Expand Down
9 changes: 6 additions & 3 deletions src/parsers/attachParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ const getFileType = (signature: number[], filename: string): AttachClass => {
break;
}

if (isArrayEqual(signature, 4, [0x66, 0x74, 0x79, 0x70, 0x69, 0x73])) {
if (isArrayEqual(signature, 4, [0x66, 0x74, 0x79, 0x70, 0x69, 0x73])
|| isArrayEqual(signature, 4, [0x66, 0x74, 0x79, 0x70, 0x4D, 0x53, 0x4E, 0x56])
|| isArrayEqual(signature, 4, [0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34, 0x32])
) {
file_type.category = AttachCategory.VIDEO;
file_type.type = AttachType.MP4;
}
Expand All @@ -270,11 +273,11 @@ const attachParser: LineParser = (line, config) => {

switch (attach_type.category) {
case AttachCategory.VIDEO:
return `视频: <a href="${attach.link}" target="_blank">${attach.name}</a> (${size})<br><video controls src="${attach.link}" />`;
return `视频: <a href="${attach.link}" target="_blank">${attach.name}</a> (${size})<br><video controls src="${attach.link}"></video>`;
case AttachCategory.IMAGE:
return `图片: <a href="${attach.link}" target="_blank">${attach.name}</a> (${size})<br><img src="${attach.link}">`;
case AttachCategory.AUDIO:
return `音频: <a href="${attach.link}" target="_blank">${attach.name}</a> (${size})<br><audio controls src="${attach.link}" />`;
return `音频: <a href="${attach.link}" target="_blank">${attach.name}</a> (${size})<br><audio controls src="${attach.link}"></audio>`;
default:
let icon = "text";
switch (attach_type.type) {
Expand Down
4 changes: 2 additions & 2 deletions test/02-attachParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Attachment Parser Test", () => {
"<article>视频: <a href=\"http://example.com\" target=\"_blank\">",
"foo.mp4",
"</a> (1.26 MB)<br>",
"<video controls src=\"http://example.com\" />",
"<video controls src=\"http://example.com\"></video>",
"</article>",
];

Expand Down Expand Up @@ -95,7 +95,7 @@ describe("Attachment Parser Test", () => {
"<article>音频: <a href=\"http://example.com\" target=\"_blank\">",
"foo.mp3",
"</a> (100 B)<br>",
"<audio controls src=\"http://example.com\" />",
"<audio controls src=\"http://example.com\"></audio>",
"</article>",
];

Expand Down

0 comments on commit 4c94ae9

Please sign in to comment.