nodebb-plugin-ezoic-infinite 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/admin.js +17 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
5
5
  "main": "library.js",
6
6
  "keywords": [
package/public/admin.js CHANGED
@@ -1,13 +1,26 @@
1
- /* globals app */
1
+ /* globals app, ajaxify, config */
2
2
  'use strict';
3
3
 
4
+ function getCsrfToken() {
5
+ return (ajaxify?.data?.csrf_token) || (config?.csrf_token) || '';
6
+ }
7
+
4
8
  $(document).ready(() => {
5
9
  $('#save').on('click', function (e) {
6
10
  e.preventDefault();
7
11
 
12
+ const csrf = getCsrfToken();
13
+ if (!csrf) {
14
+ app.alertError('CSRF token introuvable');
15
+ return;
16
+ }
17
+
8
18
  $.ajax({
9
19
  method: 'PUT',
10
20
  url: '/api/admin/settings/ezoic-infinite',
21
+ headers: {
22
+ 'x-csrf-token': csrf
23
+ },
11
24
  data: {
12
25
  placeholderIds: $('#placeholderIds').val(),
13
26
  intervalPosts: $('#intervalPosts').val(),
@@ -15,6 +28,8 @@ $(document).ready(() => {
15
28
  }
16
29
  })
17
30
  .done(() => app.alertSuccess('Paramètres enregistrés'))
18
- .fail(() => app.alertError('Erreur lors de la sauvegarde'));
31
+ .fail((xhr) => {
32
+ app.alertError(xhr?.responseJSON?.error || 'Erreur lors de la sauvegarde');
33
+ });
19
34
  });
20
35
  });