mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-03-07 15:16:40 +08:00
Add missing feedback function
This commit is contained in:
parent
7103d52a6e
commit
7b8b9dc379
@ -1,52 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
$.extend(true, $.fn.dataTable.defaults, {
|
||||
language: trans('vendor.datatables'),
|
||||
scrollX: true,
|
||||
pageLength: 25,
|
||||
autoWidth: false,
|
||||
processing: true,
|
||||
serverSide: true
|
||||
});
|
||||
|
||||
$.fn.dataTable.ext.errMode = 'none';
|
||||
|
||||
function handleDataTablesAjaxError(event, settings, json, xhr) {
|
||||
if (json === null) {
|
||||
showModal(xhr.responseText, trans('general.fatalError'), 'danger');
|
||||
}
|
||||
}
|
||||
|
||||
async function sendFeedback() {
|
||||
if (document.cookie.replace(/(?:(?:^|.*;\s*)feedback_sent\s*=\s*([^;]*).*$)|^.*$/, '$1') !== '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { errno } = await fetch({
|
||||
url: 'https://work.prinzeugen.net/statistics/feedback',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
site_name: blessing.site_name,
|
||||
site_url: blessing.base_url,
|
||||
version: blessing.version
|
||||
}
|
||||
});
|
||||
if (errno === 0) {
|
||||
// It will be expired when current session ends
|
||||
document.cookie = 'feedback_sent=' + Date.now();
|
||||
|
||||
console.log('Feedback sent. Thank you!');
|
||||
}
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
module.exports = {
|
||||
sendFeedback,
|
||||
handleDataTablesAjaxError,
|
||||
};
|
||||
}
|
34
resources/assets/src/js/feedback.js
Normal file
34
resources/assets/src/js/feedback.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { queryStringify } from './utils';
|
||||
|
||||
async function sendFeedback() {
|
||||
if (document.cookie.replace(/(?:(?:^|.*;\s*)feedback_sent\s*=\s*([^;]*).*$)|^.*$/, '$1') !== '') {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch('https://work.prinzeugen.net/statistics/feedback', {
|
||||
body: queryStringify({
|
||||
site_name: blessing.site_name,
|
||||
site_url: blessing.base_url,
|
||||
version: blessing.version
|
||||
}),
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const { errno } = await response.json();
|
||||
|
||||
if (errno === 0) {
|
||||
// It will be expired when current session ends
|
||||
document.cookie = 'feedback_sent=' + Date.now();
|
||||
|
||||
console.info('Feedback sent. Thank you!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.sendFeedback = sendFeedback;
|
@ -3,6 +3,7 @@ import './i18n';
|
||||
import './net';
|
||||
import './layout';
|
||||
import './logout';
|
||||
import './feedback';
|
||||
|
||||
console.log(
|
||||
`%c Blessing Skin %c v${blessing.version} %c Made with %c<3%c by printempw.%c https://blessing.studio`,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Vue from 'vue';
|
||||
import { queryStringify } from './utils';
|
||||
import { showAjaxError } from './notify';
|
||||
|
||||
const csrfField = document.querySelector('meta[name="csrf-token"]');
|
||||
@ -27,10 +28,7 @@ export async function walkFetch(request) {
|
||||
}
|
||||
|
||||
export async function get(url, params = empty) {
|
||||
const qs = Object
|
||||
.keys(params)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
||||
.join('&');
|
||||
const qs = queryStringify(params);
|
||||
|
||||
return walkFetch(new Request(`${blessing.base_url}${url}${qs && '?' + qs}`, init));
|
||||
}
|
||||
|
@ -26,3 +26,16 @@ export function queryString(key, defaultValue) {
|
||||
return result[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize data to URL query string
|
||||
*
|
||||
* @param {object} data
|
||||
* @returns {string}
|
||||
*/
|
||||
export function queryStringify(params) {
|
||||
return Object
|
||||
.keys(params)
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
||||
.join('&');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user