mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 16:23:50 +08:00
65481858c2
For consistency this PR introduces using custom markdown and short upload:// URLs for video and audio uploads, rather than just treating them as links and relying on the oneboxer. The markdown syntax for videos is ![file text|video](upload://123456.mp4) and for audio it is ![file text|audio](upload://123456.mp3). This is achieved in discourse-markdown-it by modifying the rules for images in mardown-it via md.renderer.rules.image. We return HTML instead of the token when we encounter audio or video after | and the preview renders that HTML. Also when uploading an audio or video file we insert the relevant markdown into the composer.
108 lines
2.8 KiB
JavaScript
108 lines
2.8 KiB
JavaScript
import {
|
|
lookupCachedUploadUrl,
|
|
resolveAllShortUrls,
|
|
resetCache
|
|
} from "pretty-text/upload-short-url";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { fixture } from "helpers/qunit-helpers";
|
|
|
|
QUnit.module("lib:pretty-text/upload-short-url", {
|
|
beforeEach() {
|
|
const response = object => {
|
|
return [200, { "Content-Type": "application/json" }, object];
|
|
};
|
|
|
|
const imageSrcs = [
|
|
{
|
|
short_url: "upload://a.jpeg",
|
|
url: "/uploads/default/original/3X/c/b/1.jpeg",
|
|
short_path: "/uploads/short-url/a.jpeg"
|
|
},
|
|
{
|
|
short_url: "upload://b.jpeg",
|
|
url: "/uploads/default/original/3X/c/b/2.jpeg",
|
|
short_path: "/uploads/short-url/b.jpeg"
|
|
}
|
|
];
|
|
|
|
const attachmentSrcs = [
|
|
{
|
|
short_url: "upload://c.pdf",
|
|
url: "/uploads/default/original/3X/c/b/3.pdf",
|
|
short_path: "/uploads/short-url/c.pdf"
|
|
}
|
|
];
|
|
|
|
const otherMediaSrcs = [
|
|
{
|
|
short_url: "upload://d.mp4",
|
|
url: "/uploads/default/original/3X/c/b/4.mp4",
|
|
short_path: "/uploads/short-url/d.mp4"
|
|
},
|
|
{
|
|
short_url: "upload://e.mp3",
|
|
url: "/uploads/default/original/3X/c/b/5.mp3",
|
|
short_path: "/uploads/short-url/e.mp3"
|
|
}
|
|
];
|
|
|
|
// prettier-ignore
|
|
server.post("/uploads/lookup-urls", () => { //eslint-disable-line
|
|
return response(imageSrcs.concat(attachmentSrcs.concat(otherMediaSrcs)));
|
|
});
|
|
|
|
fixture().html(
|
|
imageSrcs.map(src => `<img data-orig-src="${src.url}">`).join("") +
|
|
attachmentSrcs.map(src => `<a data-orig-href="${src.url}">`).join("")
|
|
);
|
|
},
|
|
|
|
afterEach() {
|
|
resetCache();
|
|
}
|
|
});
|
|
|
|
QUnit.test("resolveAllShortUrls", async assert => {
|
|
let lookup;
|
|
|
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
|
assert.deepEqual(lookup, {});
|
|
|
|
await resolveAllShortUrls(ajax);
|
|
|
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
|
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/1.jpeg",
|
|
short_path: "/uploads/short-url/a.jpeg"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://b.jpeg");
|
|
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/2.jpeg",
|
|
short_path: "/uploads/short-url/b.jpeg"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://c.jpeg");
|
|
assert.deepEqual(lookup, {});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://c.pdf");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/3.pdf",
|
|
short_path: "/uploads/short-url/c.pdf"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://d.mp4");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/4.mp4",
|
|
short_path: "/uploads/short-url/d.mp4"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://e.mp3");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/5.mp3",
|
|
short_path: "/uploads/short-url/e.mp3"
|
|
});
|
|
});
|