Video Uploads Resolved

This commit is contained in:
2026-03-08 20:40:53 -04:00
parent 2473c5990d
commit 5d86c0fa94
2 changed files with 22 additions and 11 deletions

View File

@@ -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);
if (isVideo) {
// 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("upload_type", "site_setting");
formData.append("for_site_setting", "true"); 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") ||

View File

@@ -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;