mirror of
https://github.com/dpnmw/community-landing.git
synced 2026-03-18 09:27:16 +00:00
Video Uploads Resolved
This commit is contained in:
@@ -440,6 +440,7 @@ let currentTab = "settings";
|
|||||||
let filterActive = false;
|
let filterActive = false;
|
||||||
let isActive = false;
|
let isActive = false;
|
||||||
let recheckTimer = null;
|
let recheckTimer = null;
|
||||||
|
let _siteSettings = null;
|
||||||
|
|
||||||
function getContainer() {
|
function getContainer() {
|
||||||
return (
|
return (
|
||||||
@@ -907,9 +908,8 @@ function injectVideoUploadNotice(container) {
|
|||||||
toggleRow.dataset.clVideoNoticeInjected = "1";
|
toggleRow.dataset.clVideoNoticeInjected = "1";
|
||||||
|
|
||||||
// Check Discourse site settings for file attachment support
|
// Check Discourse site settings for file attachment support
|
||||||
const siteSettings = window.Discourse && window.Discourse.SiteSettings;
|
|
||||||
const authorizedExtensions = (
|
const authorizedExtensions = (
|
||||||
(siteSettings && siteSettings.authorized_extensions) || ""
|
(_siteSettings && _siteSettings.authorized_extensions) || ""
|
||||||
).toLowerCase();
|
).toLowerCase();
|
||||||
const attachmentsAllowed =
|
const attachmentsAllowed =
|
||||||
authorizedExtensions.includes("mp4") ||
|
authorizedExtensions.includes("mp4") ||
|
||||||
@@ -928,7 +928,7 @@ function injectVideoUploadNotice(container) {
|
|||||||
const uploadBtn = toggleRow.querySelector(".cl-upload-btn");
|
const uploadBtn = toggleRow.querySelector(".cl-upload-btn");
|
||||||
if (uploadBtn) uploadBtn.disabled = true;
|
if (uploadBtn) uploadBtn.disabled = true;
|
||||||
} else {
|
} else {
|
||||||
const maxSize = siteSettings && siteSettings.max_attachment_size_kb;
|
const maxSize = _siteSettings && _siteSettings.max_attachment_size_kb;
|
||||||
const maxMB = maxSize ? (maxSize / 1024).toFixed(0) : "?";
|
const maxMB = maxSize ? (maxSize / 1024).toFixed(0) : "?";
|
||||||
notice.textContent =
|
notice.textContent =
|
||||||
`Check allowed video file types and max upload size (${maxMB} MB) in Settings \u2192 Files before uploading.`;
|
`Check allowed video file types and max upload size (${maxMB} MB) in Settings \u2192 Files before uploading.`;
|
||||||
@@ -961,17 +961,23 @@ function getCsrfToken() {
|
|||||||
return meta ? meta.getAttribute("content") : "";
|
return meta ? meta.getAttribute("content") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile(file) {
|
async function uploadFile(file, { isVideo = false } = {}) {
|
||||||
console.log("[CL Upload] Starting upload:", {
|
console.log("[CL Upload] Starting upload:", {
|
||||||
name: file.name,
|
name: file.name,
|
||||||
type: file.type,
|
type: file.type,
|
||||||
size: `${(file.size / 1024 / 1024).toFixed(2)} MB`,
|
size: `${(file.size / 1024 / 1024).toFixed(2)} MB`,
|
||||||
|
isVideo,
|
||||||
});
|
});
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
formData.append("upload_type", "site_setting");
|
if (isVideo) {
|
||||||
formData.append("for_site_setting", "true");
|
// Discourse rejects non-image files when for_site_setting is true
|
||||||
|
formData.append("upload_type", "composer");
|
||||||
|
} else {
|
||||||
|
formData.append("upload_type", "site_setting");
|
||||||
|
formData.append("for_site_setting", "true");
|
||||||
|
}
|
||||||
formData.append("synchronous_uploads", "true");
|
formData.append("synchronous_uploads", "true");
|
||||||
|
|
||||||
const csrfToken = getCsrfToken();
|
const csrfToken = getCsrfToken();
|
||||||
@@ -1218,7 +1224,8 @@ function injectUploadButtons() {
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await uploadFile(file);
|
const isVideo = (cfg.accept || "").includes("video");
|
||||||
|
const data = await uploadFile(file, { isVideo });
|
||||||
await pinUpload(data.id, settingName);
|
await pinUpload(data.id, settingName);
|
||||||
setSettingValue(row, data.url, cfg.multi);
|
setSettingValue(row, data.url, cfg.multi);
|
||||||
updatePreviewThumbnail(wrapper, settingName);
|
updatePreviewThumbnail(wrapper, settingName);
|
||||||
@@ -1298,6 +1305,7 @@ export default {
|
|||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
withPluginApi("1.0", (api) => {
|
withPluginApi("1.0", (api) => {
|
||||||
|
_siteSettings = api.container.lookup("service:site-settings");
|
||||||
api.onPageChange((url) => {
|
api.onPageChange((url) => {
|
||||||
if (
|
if (
|
||||||
url.includes("community-landing") ||
|
url.includes("community-landing") ||
|
||||||
|
|||||||
@@ -385,13 +385,16 @@ html, .cl-body {
|
|||||||
font-size: 1.05rem;
|
font-size: 1.05rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FontAwesome icon spacing inside buttons */
|
/* FontAwesome icon spacing inside buttons & nav links */
|
||||||
.cl-btn i.fa-solid {
|
.cl-btn i.fa-solid,
|
||||||
|
.cl-navbar__link i.fa-solid {
|
||||||
margin: 0 0.35em;
|
margin: 0 0.35em;
|
||||||
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Google Material Symbols icon spacing inside buttons */
|
/* Google Material Symbols icon spacing inside buttons & nav links */
|
||||||
.cl-btn .material-symbols-outlined {
|
.cl-btn .material-symbols-outlined,
|
||||||
|
.cl-navbar__link .material-symbols-outlined {
|
||||||
margin: 0 0.35em;
|
margin: 0 0.35em;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|||||||
Reference in New Issue
Block a user