Merge branch 'isekai-main'

isekai-main
落雨楓 2 years ago
commit 8ac3b073de

9
.gitignore vendored

@ -20,6 +20,9 @@ provision.sh
feeds/recent.rss feeds/recent.rss
.eslintcache .eslintcache
.svn .svn
cordova/
plugins/
config-*
logs/ logs/
@ -69,4 +72,8 @@ package-lock.json
/package.json /package.json
*.mongodb *.mongodb
link-plugins.sh link-plugins.sh
test.sh
# Isekai addition
makeCordova.sh
rebuild.sh
test.sh

@ -192,4 +192,4 @@
"url": "https://github.com/barisusakli" "url": "https://github.com/barisusakli"
} }
] ]
} }

@ -12,10 +12,30 @@ ajaxify.widgets = { render: render };
let retry = true; let retry = true;
let previousBodyClass = ''; let previousBodyClass = '';
ajaxify.loading = false;
ajaxify.count = 0; ajaxify.count = 0;
ajaxify.currentPage = null; ajaxify.currentPage = null;
var _throttleTimer = null;
var _cachedRequest = null;
function startThrottle(...args) {
if (typeof args[0] === "string") {
_cachedRequest = args;
}
if (_cachedRequest && !_throttleTimer) {
_throttleTimer = setTimeout(() => {
if (_cachedRequest) {
ajaxify.go.apply(ajaxify, _cachedRequest);
_cachedRequest = null;
}
_throttleTimer = null;
}, 500);
}
}
ajaxify.go = function (url, callback, quiet) { ajaxify.go = function (url, callback, quiet) {
ajaxify.loading = true;
// Automatically reconnect to socket and re-ajaxify on success // Automatically reconnect to socket and re-ajaxify on success
if (!socket.connected) { if (!socket.connected) {
app.reconnect(); app.reconnect();
@ -32,11 +52,13 @@ ajaxify.widgets = { render: render };
// Abort subsequent requests if clicked multiple times within a short window of time // Abort subsequent requests if clicked multiple times within a short window of time
if (ajaxifyTimer && (Date.now() - ajaxifyTimer) < 500) { if (ajaxifyTimer && (Date.now() - ajaxifyTimer) < 500) {
startThrottle(url, callback, quiet);
return true; return true;
} }
ajaxifyTimer = Date.now(); ajaxifyTimer = Date.now();
if (ajaxify.handleRedirects(url)) { if (ajaxify.handleRedirects(url)) {
ajaxify.loading = false;
return true; return true;
} }
@ -59,6 +81,7 @@ ajaxify.widgets = { render: render };
// If any listeners alter url and set it to an empty string, abort the ajaxification // If any listeners alter url and set it to an empty string, abort the ajaxification
if (url === null) { if (url === null) {
hooks.fire('action:ajaxify.end', { url: url, tpl_url: ajaxify.data.template.name, title: ajaxify.data.title }); hooks.fire('action:ajaxify.end', { url: url, tpl_url: ajaxify.data.template.name, title: ajaxify.data.title });
ajaxify.loading = false;
return false; return false;
} }
@ -72,6 +95,7 @@ ajaxify.widgets = { render: render };
(parseInt(err.data.status, 10) !== 302 && parseInt(err.data.status, 10) !== 308) (parseInt(err.data.status, 10) !== 302 && parseInt(err.data.status, 10) !== 308)
)) { )) {
ajaxify.updateHistory(url, quiet); ajaxify.updateHistory(url, quiet);
ajaxify.loading = false;
} }
if (err) { if (err) {
@ -138,6 +162,8 @@ ajaxify.widgets = { render: render };
const data = err.data; const data = err.data;
const textStatus = err.textStatus; const textStatus = err.textStatus;
ajaxify.loading = false;
if (data) { if (data) {
let status = parseInt(data.status, 10); let status = parseInt(data.status, 10);
if ([400, 403, 404, 500, 502, 504].includes(status)) { if ([400, 403, 404, 500, 502, 504].includes(status)) {
@ -307,6 +333,18 @@ ajaxify.widgets = { render: render };
hooks.fire('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url }); hooks.fire('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url });
app.processPage(); app.processPage();
ajaxify.loading = false;
if (_cachedRequest) {
if (_throttleTimer) {
clearTimeout(_throttleTimer);
_throttleTimer = null;
}
ajaxifyTimer = 0;
ajaxify.go(_cachedRequest[0], _cachedRequest[1], true);
_cachedRequest = null;
}
}; };
ajaxify.parseData = () => { ajaxify.parseData = () => {
@ -516,8 +554,12 @@ $(document).ready(function () {
// Special handling for urls with hashes // Special handling for urls with hashes
if (window.location.pathname === this.pathname && this.hash.length) { if (window.location.pathname === this.pathname && this.hash.length) {
window.location.hash = this.hash; window.location.hash = this.hash;
} else if (ajaxify.go(pathname)) { } else {
e.preventDefault(); var isReplaceLink = $this.parent('li').parent('.nav.nav-pills').length > 0 ||
$this.parent('li').parent('.pagination').length > 0
if (ajaxify.go(pathname, null, isReplaceLink)) {
e.preventDefault();
}
} }
} else if (window.location.pathname !== config.relative_path + '/outgoing') { } else if (window.location.pathname !== config.relative_path + '/outgoing') {
if (config.openOutgoingLinksInNewTab && $.contains(contentEl, this)) { if (config.openOutgoingLinksInNewTab && $.contains(contentEl, this)) {

@ -50,7 +50,7 @@ categoryController.get = async function (req, res, next) {
return helpers.notAllowed(req, res); return helpers.notAllowed(req, res);
} }
if (!res.locals.isAPI && !req.params.slug && (categoryFields.slug && categoryFields.slug !== `${cid}/`)) { if (!res.locals.isAPI && !req.params.slug && (categoryFields.slug && categoryFields.slug !== `${cid}`)) {
return helpers.redirect(res, `/category/${categoryFields.slug}?${qs.stringify(req.query)}`, true); return helpers.redirect(res, `/category/${categoryFields.slug}?${qs.stringify(req.query)}`, true);
} }

@ -62,7 +62,7 @@ topicsController.get = async function getTopic(req, res, next) {
postIndex = await topics.getUserBookmark(tid, req.uid); postIndex = await topics.getUserBookmark(tid, req.uid);
} }
if (!res.locals.isAPI && (!req.params.slug || topicData.slug !== `${tid}/${req.params.slug}`) && (topicData.slug && topicData.slug !== `${tid}/`)) { if (!res.locals.isAPI && (!req.params.slug || topicData.slug !== `${tid}/${req.params.slug}`) && (topicData.slug && topicData.slug !== `${tid}`)) {
return helpers.redirect(res, `/topic/${topicData.slug}${postIndex ? `/${postIndex}` : ''}${generateQueryString(req.query)}`, true); return helpers.redirect(res, `/topic/${topicData.slug}${postIndex ? `/${postIndex}` : ''}${generateQueryString(req.query)}`, true);
} }

@ -173,13 +173,13 @@ module.exports = function (User) {
} }
function isFullnameValid(data) { function isFullnameValid(data) {
if (data.fullname && (validator.isURL(data.fullname) || data.fullname.length > 255)) { if (data.fullname && data.fullname.length > 255) {
throw new Error('[[error:invalid-fullname]]'); throw new Error('[[error:invalid-fullname]]');
} }
} }
function isLocationValid(data) { function isLocationValid(data) {
if (data.location && (validator.isURL(data.location) || data.location.length > 255)) { if (data.location && data.location.length > 255) {
throw new Error('[[error:invalid-location]]'); throw new Error('[[error:invalid-location]]');
} }
} }

Loading…
Cancel
Save