mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Merge c7f0298a3d
into ee7e9ef2a3
This commit is contained in:
@ -439,14 +439,18 @@ class Api extends events.EventTarget {
|
|||||||
|
|
||||||
abortFunction = () => {
|
abortFunction = () => {
|
||||||
req.abort(); // does *NOT* call the callback passed in .end()
|
req.abort(); // does *NOT* call the callback passed in .end()
|
||||||
|
if (!options.noProgress) {
|
||||||
progress.done();
|
progress.done();
|
||||||
|
}
|
||||||
reject(
|
reject(
|
||||||
new Error("The request was aborted due to user cancel.")
|
new Error("The request was aborted due to user cancel.")
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
req.end((error, response) => {
|
req.end((error, response) => {
|
||||||
|
if (!options.noProgress) {
|
||||||
progress.done();
|
progress.done();
|
||||||
|
}
|
||||||
abortFunction = () => {};
|
abortFunction = () => {};
|
||||||
if (error) {
|
if (error) {
|
||||||
if (response && response.body) {
|
if (response && response.body) {
|
||||||
|
@ -41,16 +41,29 @@ class PostMainController extends BasePostController {
|
|||||||
router.replace(url, ctx.state, false);
|
router.replace(url, ctx.state, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prevPostId = aroundResponse.prev
|
||||||
|
? aroundResponse.prev.id
|
||||||
|
: null;
|
||||||
|
const nextPostId = aroundResponse.next
|
||||||
|
? aroundResponse.next.id
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// preload nearby posts
|
||||||
|
if (prevPostId) {
|
||||||
|
Post.get(prevPostId, { noProgress: true }).then(misc.preloadPostImages);
|
||||||
|
PostList.getAround(prevPostId, parameters ? parameters.query : null, { noProgress: true });
|
||||||
|
}
|
||||||
|
if (nextPostId) {
|
||||||
|
Post.get(nextPostId, { noProgress: true }).then(misc.preloadPostImages);
|
||||||
|
PostList.getAround(nextPostId, parameters ? parameters.query : null, { noProgress: true });
|
||||||
|
}
|
||||||
|
|
||||||
this._post = post;
|
this._post = post;
|
||||||
this._view = new PostMainView({
|
this._view = new PostMainView({
|
||||||
post: post,
|
post: post,
|
||||||
editMode: editMode,
|
editMode: editMode,
|
||||||
prevPostId: aroundResponse.prev
|
prevPostId: prevPostId,
|
||||||
? aroundResponse.prev.id
|
nextPostId: nextPostId,
|
||||||
: null,
|
|
||||||
nextPostId: aroundResponse.next
|
|
||||||
? aroundResponse.next.id
|
|
||||||
: null,
|
|
||||||
canEditPosts: api.hasPrivilege("posts:edit"),
|
canEditPosts: api.hasPrivilege("posts:edit"),
|
||||||
canDeletePosts: api.hasPrivilege("posts:delete"),
|
canDeletePosts: api.hasPrivilege("posts:delete"),
|
||||||
canFeaturePosts: api.hasPrivilege("posts:feature"),
|
canFeaturePosts: api.hasPrivilege("posts:feature"),
|
||||||
|
@ -199,8 +199,8 @@ class Post extends events.EventTarget {
|
|||||||
return returnedPromise;
|
return returnedPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get(id) {
|
static get(id, options) {
|
||||||
return api.get(uri.formatApiLink("post", id)).then((response) => {
|
return api.get(uri.formatApiLink("post", id), options).then((response) => {
|
||||||
return Promise.resolve(Post.fromResponse(response));
|
return Promise.resolve(Post.fromResponse(response));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,13 @@ const AbstractList = require("./abstract_list.js");
|
|||||||
const Post = require("./post.js");
|
const Post = require("./post.js");
|
||||||
|
|
||||||
class PostList extends AbstractList {
|
class PostList extends AbstractList {
|
||||||
static getAround(id, searchQuery) {
|
static getAround(id, searchQuery, options) {
|
||||||
return api.get(
|
return api.get(
|
||||||
uri.formatApiLink("post", id, "around", {
|
uri.formatApiLink("post", id, "around", {
|
||||||
query: PostList._decorateSearchQuery(searchQuery || ""),
|
query: PostList._decorateSearchQuery(searchQuery || ""),
|
||||||
fields: "id",
|
fields: "id",
|
||||||
})
|
}),
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,6 +211,15 @@ function getPrettyName(tag) {
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function preloadPostImages(post) {
|
||||||
|
if (!["image", "animation"].includes(post.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const img = new Image()
|
||||||
|
img.fetchPriority = "low";
|
||||||
|
img.src = post.contentUrl;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
range: range,
|
range: range,
|
||||||
formatRelativeTime: formatRelativeTime,
|
formatRelativeTime: formatRelativeTime,
|
||||||
@ -229,4 +238,5 @@ module.exports = {
|
|||||||
escapeSearchTerm: escapeSearchTerm,
|
escapeSearchTerm: escapeSearchTerm,
|
||||||
dataURItoBlob: dataURItoBlob,
|
dataURItoBlob: dataURItoBlob,
|
||||||
getPrettyName: getPrettyName,
|
getPrettyName: getPrettyName,
|
||||||
|
preloadPostImages: preloadPostImages,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user