{{ title }}
Various tools related to managing the site
diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index ddedfda0a..fc21d5c6b 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -1,33 +1,23 @@ action !== 'DELETE') + CoreUtils::notAllowed(); + + clearstatcache(); + Response::done(); + } } diff --git a/app/Controllers/DiscordAuthController.php b/app/Controllers/DiscordAuthController.php index 2586dcccb..2950c877c 100644 --- a/app/Controllers/DiscordAuthController.php +++ b/app/Controllers/DiscordAuthController.php @@ -130,6 +130,8 @@ private function _setTarget($params){ } public function sync($params){ + Response::fail('The Discord account link got severed, you will need to re-link your account.', ['segway' => true]); + $this->_setTarget($params); $discordUser = $this->_target->discord_member; diff --git a/app/Models/Post.php b/app/Models/Post.php index 741883d46..99581d82a 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -128,7 +128,7 @@ public function get_approval_entry(){ FROM log__post_lock pl LEFT JOIN log l ON l.reftype = 'post_lock' AND l.refid = pl.entryid WHERE $where_query - ORDER BY pl.entryid ASC + ORDER BY pl.entryid LIMIT 1", $where_bind ); } @@ -327,9 +327,9 @@ public function getLi(bool $view_only = false, bool $cachebust_url = false, bool $HTML .= $post_label.$posted_at.$post_type.$reserved_at.$finished_at.$locked_at; if (!empty($this->fullsize)) - $HTML .= " Original image"; + $HTML .= " Original image"; if (!$approved && Permission::sufficient('staff')) - $HTML .= " View open submissions"; + $HTML .= " View open submissions"; } else $HTML .= $post_label.$posted_at.$reserved_at; } @@ -403,7 +403,7 @@ public function getActionsHTML($view_only, bool $hide_reserver_status, bool $ena } if (!empty($Buttons)){ if ($view_only !== false) - $HTML .= "
"; + $HTML .= ""; else { $regularButton = \count($Buttons) < 3; foreach ($Buttons as $b){ diff --git a/assets/js/global.jsx b/assets/js/global.jsx index a9440a057..35f5635ea 100644 --- a/assets/js/global.jsx +++ b/assets/js/global.jsx @@ -163,7 +163,7 @@ } if (!cdExists || diff.past){ clearCD(); - $.API.get('/about/upcoming', $.mkAjaxHandler(function(){ + $.API.get('/about/upcoming', function(){ if (!this.status) return console.error(`Failed to load upcoming event list: ${this.message}`); const $uc = $('#upcoming'); @@ -172,7 +172,7 @@ $uc.addClass('hidden'); else $uc.removeClass('hidden'); window.setUpcomingCountdown(); - })); + }); return; } let text; @@ -540,11 +540,11 @@ $.Dialog.wait(title,'Signing out'); - $.API.post('/da-auth/sign-out',$.mkAjaxHandler(function(){ + $.API.post('/da-auth/sign-out', function(){ if (!this.status) return $.Dialog.fail(title,this.message); $.Navigation.reload(); - })); + }); }); }); @@ -556,7 +556,7 @@ if ($sessionUpdating === null) return; - $.API.get('/da-auth/status', $.mkAjaxHandler(function(){ + $.API.get('/da-auth/status', function(){ if ($sessionUpdating === null) return; @@ -568,7 +568,7 @@ if (this.deleted === true) $.Dialog.fail(sessionRefTitle, "We couldn't refresh your DeviantArt session automatically so you have been signed out. Due to elements on the page assuming you are signed in some actions will not work as expected until the page is reloaded."); $sessionUpdating.html(this.loggedIn).removeClass('updating-session'); - })); + }); }, pollInterval); } diff --git a/assets/js/jquery.ponycolorpalette.js b/assets/js/jquery.ponycolorpalette.js index fb20e6bbd..1b8ecc1b8 100644 --- a/assets/js/jquery.ponycolorpalette.js +++ b/assets/js/jquery.ponycolorpalette.js @@ -43,13 +43,13 @@ waitingList[this.appearanceId] = [this]; - $.API.post(`/cg/appearance/${this.appearanceId}/link-targets?hex`, $.mkAjaxHandler(data => { + $.API.post(`/cg/appearance/${this.appearanceId}/link-targets?hex`, data => { if (!data.status) return this.displayError(data.message); $.each(waitingList[this.appearanceId], (_, picker) => { picker.fillSwatchBox(data.list); }); - })); + }); } fillSwatchBox(list){ this.$swatchBox.removeClass('loading').children().first().nextAll().remove(); diff --git a/assets/js/pages/admin/index.js b/assets/js/pages/admin/index.js index 02b8d2f6c..a847c508d 100644 --- a/assets/js/pages/admin/index.js +++ b/assets/js/pages/admin/index.js @@ -80,7 +80,7 @@ const ids = deviationIDArray.join(','); - $.API.post('/admin/mass-approve', { ids }, $.mkAjaxHandler(function(){ + $.API.post('/admin/mass-approve', { ids }, function(){ if (!this.status) return $.Dialog.fail(false, this.message); if (this.html){ @@ -91,10 +91,24 @@ if (this.message) $.Dialog.success(false, this.message, true); else $.Dialog.close(); - })); + }); } })(); + $('#clear-stat-cache').on('click', e => { + e.preventDefault(); + + $.Dialog.wait('Clearing file stat cache'); + + $.API.delete('/admin/stat-cache', function () { + if (!this.status) return $.Dialog.fail(false, this.message); + + if (this.message) + $.Dialog.success(false, this.message, true); + else $.Dialog.close(); + }); + }); + const deviationIO = new IntersectionObserver(entries => { entries.forEach(entry => { if (!entry.isIntersecting) @@ -107,13 +121,13 @@ postID = el.dataset.postId, viewonly = el.dataset.viewonly; - $.API.get(`/post/${postID}/lazyload`,{viewonly},$.mkAjaxHandler(function(){ + $.API.get(`/post/${postID}/lazyload`,{viewonly},function(){ if (!this.status) return $.Dialog.fail(`Cannot load post ${postID}`, this.message); $.loadImages(this.html).then(function(resp){ $(el).closest('.image').replaceWith(resp.$el); }); - })); + }); }); }); const imageIO = new IntersectionObserver(entries => { diff --git a/assets/js/pages/admin/log.js b/assets/js/pages/admin/log.js index 511e5a33c..8a6222043 100644 --- a/assets/js/pages/admin/log.js +++ b/assets/js/pages/admin/log.js @@ -32,7 +32,7 @@ $this.addClass('typcn-times color-red').css('cursor','not-allowed').off('click'); }; - $.API.get(`/admin/logs/details/${EntryID}`,$.mkAjaxHandler(function(){ + $.API.get(`/admin/logs/details/${EntryID}`, function(){ if (!this.status){ if (this.unclickable === true) $this.replaceWith($this.text().trim()); @@ -61,7 +61,7 @@ $dataDiv.insertAfter($this).slideDown(); Time.update(); $this.addClass('typcn-minus color-darkblue'); - })).always(function(){ + }).always(function(){ requesting = false; $this.removeClass('typcn-refresh'); }).fail(fail); diff --git a/assets/js/pages/admin/useful-links.js b/assets/js/pages/admin/useful-links.js index e901341f4..d0106be64 100644 --- a/assets/js/pages/admin/useful-links.js +++ b/assets/js/pages/admin/useful-links.js @@ -13,7 +13,7 @@ $.Dialog.wait(`Editing link #${linkid}`, 'Retrieving link information from server'); - $.API.get(`/admin/usefullinks/${linkid}`,$.mkAjaxHandler(function(){ + $.API.get(`/admin/usefullinks/${linkid}`, function(){ if (!this.status) return $.Dialog.fail(false, this.message); let data = this; @@ -23,7 +23,7 @@ $form.find('input[name=title]').val(data.title); $form.find('select[name=minrole]').val(data.minrole); }); - })); + }); }); $uflol.on('click','.delete-link',function(){ let $li = $(this).closest('[id^=ufl-]'), @@ -34,7 +34,7 @@ $.Dialog.wait(false, 'Removing link'); - $.API.delete(`/admin/usefullinks/${linkId}`,$.mkAjaxHandler(function(){ + $.API.delete(`/admin/usefullinks/${linkId}`, function(){ if (!this.status) return $.Dialog.fail(false, this.message); $li.remove(); @@ -42,7 +42,7 @@ if ($sbUflContainer.is(':empty')) $sbUflContainer.hide(); $.Dialog.close(); - })); + }); }); }); $('#add-link').on('click',function(){ @@ -113,11 +113,11 @@ list.push($(this).find('.typcn-arrow-move').remove().end().attr('id').split('-').pop()); }); - $.API.post('/admin/usefullinks/reorder', {list:list.join(',')}, $.mkAjaxHandler(function(){ + $.API.post('/admin/usefullinks/reorder', {list:list.join(',')}, function(){ if (!this.status) return $.Dialog.fail(false, this.message); $.Navigation.reload(true); - })); + }); } }); })(); diff --git a/assets/js/pages/admin/wsdiag.js b/assets/js/pages/admin/wsdiag.js index 7f38f0da0..5cede35b3 100644 --- a/assets/js/pages/admin/wsdiag.js +++ b/assets/js/pages/admin/wsdiag.js @@ -131,7 +131,7 @@ $.Dialog.success(false, 'Hello response received', true); }); - $.API.get('/admin/wsdiag/hello', { priv, clientid }, $.mkAjaxHandler(function(){ + $.API.get('/admin/wsdiag/hello', { priv, clientid }, function(){ if (!this.status) return $.Dialog.fail(false, this.message); if (!responseReceived) @@ -146,6 +146,6 @@ $w.off('ws-hello'); $.Dialog.fail(false, 'Hello response timed out'); }, timeout); - })); + }); }); })(); diff --git a/assets/js/pages/colorguide/full-list.js b/assets/js/pages/colorguide/full-list.js index 834283c3d..4cd76093c 100644 --- a/assets/js/pages/colorguide/full-list.js +++ b/assets/js/pages/colorguide/full-list.js @@ -84,7 +84,7 @@ if (EQG) data.eqg = true; - $.API.post('/cg/full/reorder', data, $.mkAjaxHandler(function(){ + $.API.post('/cg/full/reorder', data, function(){ if (!this.status) return $.Dialog.fail(false, this.message); $fullList.removeClass('sorting').html(this.html); @@ -92,7 +92,7 @@ $ReorderBtn.removeClass('typcn-tick green').addClass('typcn-arrow-unsorted darkblue').html('Re-order'); $ReorderCancelBtn.addClass('hidden'); $.Dialog.close(); - })); + }); } }); diff --git a/assets/js/pages/colorguide/guide.js b/assets/js/pages/colorguide/guide.js index 59aa13b9c..12091416a 100644 --- a/assets/js/pages/colorguide/guide.js +++ b/assets/js/pages/colorguide/guide.js @@ -151,9 +151,9 @@ source: (q, callback) => { if (appearanceAutocompleteCache.has(q)) return callback(appearanceAutocompleteCache.get(q)); - $.API.get(`/cg/appearances`, { q, EQG }, $.mkAjaxHandler(data => { + $.API.get(`/cg/appearances`, { q, EQG }, data => { callback(appearanceAutocompleteCache.set(q, data)); - })); + }); }, templates: { header: () => `Choose how many points you want to give. Enter a negative number to take points. You cannot take more points than what the user has, and the free slot cannot be taken away.
Remember, 10 points = 1 slot!
`, @@ -186,15 +186,15 @@ $.Dialog.wait(false, 'Giving points'); - $.API.post(`/user/${userId}/pcg/points`, data, $.mkAjaxHandler(function(){ + $.API.post(`/user/${userId}/pcg/points`, data, function(){ if (!this.status) return $.Dialog.fail(false, this.message); $.Dialog.segway(false, this.message); - })); + }); }); }); }); - })); + }); }); } @@ -225,7 +225,7 @@ $.Dialog.wait(title,`Signing out of ${browser}${platform}`); - $.API.delete(`/user/session/${sessionID}`, $.mkAjaxHandler(function(){ + $.API.delete(`/user/session/${sessionID}`, function(){ if (!this.status) return $.Dialog.fail(title,this.message); if ($li.siblings().length !== 0){ @@ -234,7 +234,7 @@ } $.Navigation.reload(true); - })); + }); }); }); $sessionList.find('button.useragent').on('click', function(e){ @@ -249,11 +249,11 @@ $.Dialog.wait(false, 'Signing out'); - $.API.post('/da-auth/signout?everywhere',{name: username},$.mkAjaxHandler(function(){ + $.API.post('/da-auth/signout?everywhere',{name: username},function(){ if (!this.status) return $.Dialog.fail(false, this.message); $.Navigation.reload(true); - })); + }); }); }); @@ -321,7 +321,7 @@ const { postId, viewonly } = el.dataset; - $.API.get(`/post/${postId}/lazyload`, { viewonly }, $.mkAjaxHandler(({ status, message, html }) => { + $.API.get(`/post/${postId}/lazyload`, { viewonly }, ({ status, message, html }) => { const $el = $(el); if (!status){ $el.trigger('error'); @@ -335,7 +335,7 @@ if (title) $li.children('.label').removeClass('hidden').find('a').text(title); }); - })); + }); }); }); @@ -350,12 +350,12 @@ $.Dialog.wait('Deviation acceptance status', 'Checking'); - $.API.post(`/post/${id}/approval`, $.mkAjaxHandler(function(){ + $.API.post(`/post/${id}/approval`, function(){ if (!this.status) return $.Dialog.fail(false, this.message); $li.remove(); $.Dialog.success(false, this.message, true); - })); + }); }); function settingChanged(which,from,to_what){ @@ -395,7 +395,7 @@ $(`.provider-${from}:not(.avatar-wrap)`).removeClass('provider-'+from).addClass('provider-'+to_what); let error = false; $.each(forUser, (forId, elements) => { - $.API.get(`/user/${forId}/avatar-wrap`, $.mkAjaxHandler(function(){ + $.API.get(`/user/${forId}/avatar-wrap`, function(){ if (!this.status){ error = true; return $.Dialog.fail(`Update avatar elements for ${forId}`, false); @@ -404,7 +404,7 @@ $.each(elements, (_, $el) => { $el.replaceWith(this.html); }); - })); + }); }); if (!error) $.Dialog.close(); @@ -440,7 +440,7 @@ $.Dialog.wait('Saving setting','Please wait'); - $.API.put(endpoint,data,$.mkAjaxHandler(function(){ + $.API.put(endpoint,data,function(){ if (!this.status) return $.Dialog.fail(false, this.message); if ($input.is('[type=number]')) @@ -452,7 +452,7 @@ $input.data('orig', this.value).triggerHandler('change'); settingChanged(endpoint.split('/').pop(), orig, this.value); - })); + }); }); $slbl.children('input[type=number]').each(function(){ let $el = $(this); diff --git a/assets/js/pages/user/suggestion.js b/assets/js/pages/user/suggestion.js index e826f40ac..1616a705e 100644 --- a/assets/js/pages/user/suggestion.js +++ b/assets/js/pages/user/suggestion.js @@ -21,7 +21,7 @@ $btn.disable(); - $.API.get('/post/request/suggestion',{already_loaded: already_loaded.join(',')},$.mkAjaxHandler(function(){ + $.API.get('/post/request/suggestion',{already_loaded: already_loaded.join(',')},function(){ if (!this.status){ $btn.enable(); return $.Dialog.fail(false, this.message); @@ -42,16 +42,16 @@ }); $result.find('.reserve-request').on('click',function(){ let $this = $(this); - $.API.post(`/post/${postID}/reservation`,{from:'suggestion'},$.mkAjaxHandler(function(){ + $.API.post(`/post/${postID}/reservation`,{from:'suggestion'},function(){ if (!this.status) return $.Dialog.fail(false, this.message); $this.replaceWith(this.button); $pendingReservations.html($(this.pendingReservations).children()); - })); + }); }); $output.html($result); $btn.enable(); - })).fail(function(){ + }).fail(function(){ $btn.enable(); }); }); diff --git a/assets/js/react-components.jsx b/assets/js/react-components.jsx index 9e57e5537..b919d2070 100644 --- a/assets/js/react-components.jsx +++ b/assets/js/react-components.jsx @@ -59,11 +59,11 @@ $.Dialog.wait(false, 'Saving changes'); - $.API.put(this.props.endpoint, { ids }, $.mkAjaxHandler(data => { + $.API.put(this.props.endpoint, { ids }, data => { if (!data.status) return $.Dialog.fail(false, data.message); this.props.onSuccess(data); - })); + }); } handleSearch(e){ diff --git a/assets/js/shared-utils.js b/assets/js/shared-utils.js index 6f5ab9610..1ca3b6179 100644 --- a/assets/js/shared-utils.js +++ b/assets/js/shared-utils.js @@ -924,12 +924,12 @@ return; } - $.API.get(this._endpoint.replace('%d', id),this._params,$.mkAjaxHandler(data => { + $.API.get(this._endpoint.replace('%d', id),this._params,data => { if (!data.status) return $.Dialog.fail('Cache entry retrieval', data.message); this._list[id] = data.list; res(this._list[id]); - })).fail(() => rej()); + }).fail(() => rej()); }); } } @@ -963,7 +963,11 @@ $.each(['get','post','put','delete'], (i, el) => { ((method) => { $.API[method] = function(url, ...args) { - return $[method]($.API.API_PATH+url, ...args); + const lastArg = args.slice(-1)[0]; + if (typeof lastArg === 'function'){ + args.splice(-1, 1, $.mkAjaxHandler(lastArg)); + } + return $[method]($.API.API_PATH + url, ...args); }; })(el); }); diff --git a/assets/js/websocket.js b/assets/js/websocket.js index 11aabb6ff..655ef9e2e 100644 --- a/assets/js/websocket.js +++ b/assets/js/websocket.js @@ -3,8 +3,7 @@ "use strict"; const $scriptTag = $('#wss'); - let conn, - connpath = $scriptTag.attr('src').replace(/^(.*?:\d+\/).*$/,'$1'), + let connpath = $scriptTag.attr('src').replace(/^(.*?:\d+\/).*$/,'$1'), wsdecoder = f => data => { if (typeof data === 'string'){ @@ -69,13 +68,13 @@ $notifCnt.empty(); }); } - else $.API.get('/notif',$.mkAjaxHandler(data => { + else $.API.get('/notif', data => { $notifCnt.text(cnt); $notifSbList.html(data.list); Time.update(); this.bindMarkRead(); $notifSb.stop().slideDown(); - })); + }); })); this.conn.on('post-delete', wsdecoder(data => { if (!data.id) @@ -113,7 +112,7 @@ if ($(`.posts #post-${data.id}`).length > 0) return; - $.API.get(`/post/${data.id}/reload`,$.mkAjaxHandler(resp => { + $.API.get(`/post/${data.id}/reload`, resp => { if (!resp.status) return; if ($(`.posts #post-${data.id}`).length > 0) @@ -124,7 +123,7 @@ Time.update(); $newli.rebindHandlers().parent().reorderPosts(); console.log(`[WS] Post added (id=${data.id}) to container ${this.section}`); - })); + }); })); this.conn.on('post-update', wsdecoder(data => { if (!data.id) @@ -281,14 +280,14 @@ send = () => { $el.siblings('.mark-read').addBack().addClass('disabled'); - $.API.post(`/notif/${nid}/mark-read`,data,$.mkAjaxHandler(data => { + $.API.post(`/notif/${nid}/mark-read`,data, data => { if (!data.status) return $.Dialog.fail(title, data.message); if (data.message) return $.Dialog.success(title, data.message, true); $.Dialog.close(); - })).always(() => { + }).always(() => { $el.siblings('.mark-read').addBack().removeClass('disabled'); }); }; diff --git a/config/routes/private_api.php b/config/routes/private_api.php index a4d5a22e0..121fd6275 100644 --- a/config/routes/private_api.php +++ b/config/routes/private_api.php @@ -17,6 +17,7 @@ $private_api_endpoint('/admin/wsdiag/hello', 'AdminController#wshello'); $private_api_endpoint('/admin/mass-approve', 'AdminController#massApprove'); $private_api_endpoint('/admin/notices/[i:id]?', 'AdminController#noticesApi'); +$private_api_endpoint('/admin/stat-cache', 'AdminController#statCacheApi'); $private_api_endpoint('/cg/appearances', 'AppearanceController#autocomplete'); $private_api_endpoint('/cg/appearances/list', 'AppearanceController#listApi'); $private_api_endpoint('/cg/appearance/[i:id]?', 'AppearanceController#api'); diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig index 98c2d02a6..5645d1a64 100644 --- a/templates/admin/index.html.twig +++ b/templates/admin/index.html.twig @@ -7,17 +7,21 @@ {% extends "layout/base.html.twig" %} {% block content %} +{% set is_dev = permission('developer') %}Various tools related to managing the site