"use strict";(self.webpackChunknodebb=self.webpackChunknodebb||[]).push([[1091,34271,36159,49897,62441,88189,98463,99127],{24187:(S,A,a)=>{var g,E;g=[a(64061)],E=function(){const c={};c.show=function(e,r){const s=e.hasOwnProperty("fileSize")&&e.fileSize!==void 0?parseInt(e.fileSize,10):!1;app.parseAndTranslate("modals/upload-file",{showHelp:e.hasOwnProperty("showHelp")&&e.showHelp!==void 0?e.showHelp:!0,fileSize:s,title:e.title||"[[global:upload-file]]",description:e.description||"",button:e.button||"[[global:upload]]",accept:e.accept?e.accept.replace(/,/g,", "):""},function(n){n.modal("show"),n.on("hidden.bs.modal",function(){n.remove()});const l=n.find("#uploadForm");l.attr("action",e.route),l.find("#params").val(JSON.stringify(e.params)),n.find("#fileUploadSubmitBtn").on("click",function(){$(this).addClass("disabled"),l.submit()}),l.submit(function(){return P(n,s,r),!1})})},c.hideAlerts=function(e){$(e).find("#alert-status, #alert-success, #alert-error, #upload-progress-box").addClass("hide")};function P(e,r,s){p(e,"status","[[uploads:uploading-file]]"),e.find("#upload-progress-bar").css("width","0%"),e.find("#upload-progress-box").show().removeClass("hide");const n=e.find("#fileInput");if(!n.val())return p(e,"error","[[uploads:select-file-to-upload]]");if(!b(n[0],r))return p(e,"error","[[error:file-too-big, "+r+"]]");c.ajaxSubmit(e,s)}function p(e,r,s){c.hideAlerts(e),r==="error"&&e.find("#fileUploadSubmitBtn").removeClass("disabled"),s=s.replace(/&#44/g,","),e.find("#alert-"+r).translateText(s).removeClass("hide")}c.ajaxSubmit=function(e,r){e.find("#uploadForm").ajaxSubmit({headers:{"x-csrf-token":config.csrf_token},error:function(n){n=h(n),p(e,"error",n.responseJSON?.status?.message||n.responseJSON?.error||`[[error:upload-error-fallback, ${n.status} ${n.statusText}]]`)},uploadProgress:function(n,l,u,t){e.find("#upload-progress-bar").css("width",t+"%")},success:function(n){let l=h(n);n.hasOwnProperty("response")&&n.hasOwnProperty("status")&&n.status.code==="ok"&&(l=n.response.images),r(l[0].url),p(e,"success","[[uploads:upload-success]]"),setTimeout(function(){c.hideAlerts(e),e.modal("hide")},750)}})};function h(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return{error:"[[error:parse-error]]"}}return e}function b(e,r){return window.FileReader&&r?e.files[0].size<=r*1e3:!0}return c}.apply(A,g),E!==void 0&&(S.exports=E)},36159:(S,A,a)=>{var g,E;g=[a(49897),a(40027),a(29930),a(24187),a(81335),a(17459),a(65285)],E=function(c,P,p,h,b,e){const r={};return r.get=s=>c.get(`/topics/${s}/thumbs`,{thumbsOnly:1}),r.getByPid=s=>c.get(`/posts/${encodeURIComponent(s)}`,{}).then(n=>r.get(n.tid)),r.delete=(s,n)=>c.del(`/topics/${s}/thumbs`,{path:n}),r.deleteAll=s=>{r.get(s).then(n=>{Promise.all(n.map(l=>r.delete(s,l.url)))})},r.upload=s=>new Promise(n=>{h.show({title:"[[topic:composer.thumb-title]]",method:"put",route:config.relative_path+`/api/v3/topics/${s}/thumbs`},function(l){n(l)})}),r.modal={},r.modal.open=function(s){const{id:n,pid:l}=s;let{modal:u}=s,t;return new Promise(i=>{Promise.all([r.get(n),l?r.getByPid(l):[]]).then(o=>new Promise(d=>{const m=o.reduce((y,f)=>y.concat(f));t=m.length,d(m)})).then(o=>b.render("modals/topic-thumbs",{thumbs:o})).then(o=>{u?e.translate(o,function(d){u.find(".bootbox-body").html(d),r.modal.handleSort({modal:u,numThumbs:t})}):(u=P.dialog({title:"[[modules:thumbs.modal.title]]",message:o,onEscape:!0,backdrop:!0,buttons:{add:{label:' [[modules:thumbs.modal.add]]',className:"btn-success",callback:()=>(r.upload(n).then(()=>{r.modal.open({...s,modal:u}),Promise.all([a.e(20056),a.e(40559),a.e(449),a.e(5785),a.e(52185)]).then(function(){var d=[a(71431)];(m=>{m.updateThumbCount(n,$(`[component="composer"][data-uuid="${n}"]`)),i()}).apply(null,d)}).catch(a.oe)}),!1)},close:{label:"[[global:close]]",className:"btn-primary"}}}),r.modal.handleDelete({...s,modal:u}),r.modal.handleSort({modal:u,numThumbs:t}))})})},r.modal.handleDelete=s=>{const n=s.modal.get(0),{id:l}=s;n.addEventListener("click",u=>{u.target.closest('button[data-action="remove"]')&&P.confirm("[[modules:thumbs.modal.confirm-remove]]",t=>{if(!t)return;const i=u.target.closest("[data-id]").getAttribute("data-id"),o=u.target.closest("[data-path]").getAttribute("data-path");c.del(`/topics/${i}/thumbs`,{path:o}).then(()=>{r.modal.open(s),Promise.all([a.e(20056),a.e(40559),a.e(449),a.e(5785),a.e(52185)]).then(function(){var d=[a(71431)];(m=>{m.updateThumbCount(l,$(`[component="composer"][data-uuid="${l}"]`))}).apply(null,d)}).catch(a.oe)}).catch(p.error)})})},r.modal.handleSort=({modal:s,numThumbs:n})=>{if(n>1){const l=s.find(".topic-thumbs-modal");l.sortable({items:"[data-id]"}),l.on("sortupdate",r.modal.handleSortChange)}},r.modal.handleSortChange=(s,n)=>{const l=n.item.get(0).parentNode.querySelectorAll("[data-id]");Array.from(l).forEach((u,t)=>{const i=u.getAttribute("data-id");let o=u.getAttribute("data-path");o=o.replace(new RegExp(`^${config.upload_url}`),""),c.put(`/topics/${i}/thumbs/order`,{path:o,order:t}).catch(p.error)})},r}.apply(A,g),E!==void 0&&(S.exports=E)},49897:(S,A,a)=>{a.r(A),a.d(A,{del:()=>u,get:()=>e,head:()=>r,patch:()=>n,post:()=>s,put:()=>l});var g=a(91749),E=a.n(g),c=a(40027),P=a.n(c);const p=config.relative_path+"/api/v3";async function h(t,i){if(t.url=t.url.startsWith("/api")?config.relative_path+t.url:p+t.url,typeof i=="function"){b(t).then(o=>i(null,o),o=>i(o));return}try{return await b(t)}catch(o){if(o.message==="A valid login session was not found. Please log in and try again."){const{url:d}=await(0,g.fire)("filter:admin.reauth",{url:"login"});return(0,c.confirm)("[[error:api.reauth-required]]",m=>{m&&ajaxify.go(d)})}throw o}}async function b(t){const{url:i}=t;delete t.url,t.data&&!(t.data instanceof FormData)&&(t.data=JSON.stringify(t.data||{}),t.headers["content-type"]="application/json; charset=utf-8"),{options:t}=await(0,g.fire)("filter:api.options",{options:t}),t.data&&(t.body=t.data,delete t.data);const o=await fetch(i,t),{headers:d}=o;if(d.get("x-redirect"))return b({url:d.get("x-redirect"),...t});const m=d.get("content-type"),y=m&&m.startsWith("application/json");let f;if(t.method!=="HEAD"&&(y?f=await o.json():f=await o.text()),!o.ok)throw f?new Error(y?f.status.message:f):new Error(o.statusText);return y&&f&&f.hasOwnProperty("status")&&f.hasOwnProperty("response")?f.response:f}function e(t,i,o){return h({url:t+(i&&Object.keys(i).length?"?"+$.param(i):"")},o)}function r(t,i,o){return h({url:t+(i&&Object.keys(i).length?"?"+$.param(i):""),method:"HEAD"},o)}function s(t,i,o){return h({url:t,method:"POST",data:i,headers:{"x-csrf-token":config.csrf_token}},o)}function n(t,i,o){return h({url:t,method:"PATCH",data:i,headers:{"x-csrf-token":config.csrf_token}},o)}function l(t,i,o){return h({url:t,method:"PUT",data:i,headers:{"x-csrf-token":config.csrf_token}},o)}function u(t,i,o){return h({url:t,method:"DELETE",data:i,headers:{"x-csrf-token":config.csrf_token}},o)}}}]);