mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Compare commits
11 Commits
781e1af9e0
...
d7ffdb0997
Author | SHA1 | Date | |
---|---|---|---|
d7ffdb0997 | |||
0971745615 | |||
27f94be56d | |||
98227e562e | |||
5244718e0f | |||
ac64c1ca50 | |||
ff788a5e30 | |||
0acc522bfc | |||
a5cf49a94a | |||
374f4a5fa9 | |||
3875ec173f |
@ -36,6 +36,7 @@ $button-disabled-background-color = #CCC
|
||||
$post-thumbnail-border-color = $main-color
|
||||
$post-thumbnail-no-tags-border-color = #F44
|
||||
$default-tag-category-background-color = $active-tab-background-color
|
||||
$default-pool-category-background-color = $active-tab-background-color
|
||||
$new-tag-background-color = #DFC
|
||||
$new-tag-text-color = black
|
||||
$implied-tag-background-color = #FFC
|
||||
|
@ -31,12 +31,12 @@
|
||||
outline: none
|
||||
border-right: 20px solid transparent
|
||||
&:before
|
||||
content: ' ';
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
bottom: 20px;
|
||||
content: ' '
|
||||
display: block
|
||||
position: relative
|
||||
width: 100%
|
||||
height: 20px
|
||||
bottom: 20px
|
||||
|
||||
.thumbnail
|
||||
width: 100%
|
||||
@ -47,6 +47,7 @@
|
||||
background-position: 50% 30%
|
||||
position: absolute
|
||||
display: inline-block
|
||||
box-shadow: 0 0 0 1px rgba(0,0,0,0.2)
|
||||
|
||||
.thumbnail-1, .thumbnail.empty
|
||||
right: -4px
|
||||
|
@ -14,24 +14,24 @@
|
||||
background: $top-navigation-color
|
||||
|
||||
.pool-name
|
||||
flex: 1 1;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
-o-text-overflow: ellipsis;
|
||||
text-overflow: ellipsis;
|
||||
flex: 1 1
|
||||
text-align: center
|
||||
overflow: hidden
|
||||
white-space: nowrap
|
||||
-o-text-overflow: ellipsis
|
||||
text-overflow: ellipsis
|
||||
|
||||
.first, .last
|
||||
flex-basis: 1em;
|
||||
flex-basis: 1em
|
||||
|
||||
.first, .prev, .next, .last
|
||||
flex: 0 1;
|
||||
white-space: nowrap;
|
||||
flex: 0 1
|
||||
white-space: nowrap
|
||||
|
||||
>span
|
||||
padding-top: 2px
|
||||
padding-bottom: 2px
|
||||
margin: 0 .25em;
|
||||
margin: 0 .25em
|
||||
|
||||
|
||||
.darktheme .pool-navigator-container .pool-info-wrapper
|
||||
|
@ -14,7 +14,6 @@ const EmptyView = require("../views/empty_view.js");
|
||||
const fields = [
|
||||
"id",
|
||||
"names",
|
||||
"posts",
|
||||
"creationTime",
|
||||
"postCount",
|
||||
"category",
|
||||
@ -101,11 +100,13 @@ class PoolListController {
|
||||
return uri.formatClientLink("pools", parameters);
|
||||
},
|
||||
requestPage: (offset, limit) => {
|
||||
const canEditPosts = api.hasPrivilege("pools:edit") || api.hasPrivilege("pools:edit:posts");
|
||||
const effectiveFields = fields.concat([canEditPosts ? "posts": "postsMicro"]);
|
||||
return PoolList.search(
|
||||
this._ctx.parameters.query,
|
||||
offset,
|
||||
limit,
|
||||
fields
|
||||
effectiveFields
|
||||
);
|
||||
},
|
||||
pageRenderer: (pageCtx) => {
|
||||
|
@ -17,11 +17,6 @@ class PostMainController extends BasePostController {
|
||||
constructor(ctx, editMode) {
|
||||
super(ctx);
|
||||
|
||||
let poolPostsNearby = Promise.resolve({results: []});
|
||||
if (api.hasPrivilege("pools:list") && api.hasPrivilege("pools:view")) {
|
||||
poolPostsNearby = PostList.getNearbyPoolPosts(ctx.parameters.id);
|
||||
}
|
||||
|
||||
let parameters = ctx.parameters;
|
||||
Promise.all([
|
||||
Post.get(ctx.parameters.id),
|
||||
@ -29,10 +24,9 @@ class PostMainController extends BasePostController {
|
||||
ctx.parameters.id,
|
||||
parameters ? parameters.query : null
|
||||
),
|
||||
poolPostsNearby
|
||||
]).then(
|
||||
(responses) => {
|
||||
const [post, aroundResponse, poolPostsNearby] = responses;
|
||||
const [post, aroundResponse] = responses;
|
||||
let aroundPool = null;
|
||||
|
||||
// remove junk from query, but save it into history so that it can
|
||||
@ -47,13 +41,13 @@ class PostMainController extends BasePostController {
|
||||
)
|
||||
: uri.formatClientLink("post", ctx.parameters.id);
|
||||
router.replace(url, ctx.state, false);
|
||||
parameters.query.split(" ").forEach((item) => {
|
||||
misc.splitByWhitespace(parameters.query).forEach((item) => {
|
||||
const found = item.match(/^pool:([0-9]+)/i);
|
||||
if (found) {
|
||||
const activePool = parseInt(found[1]);
|
||||
poolPostsNearby.forEach((nearbyPosts) => {
|
||||
if (nearbyPosts.pool.id == activePool) {
|
||||
aroundPool = nearbyPosts
|
||||
post.pools.map((pool) => {
|
||||
if (pool.id == activePool) {
|
||||
aroundPool = pool;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -63,7 +57,6 @@ class PostMainController extends BasePostController {
|
||||
this._post = post;
|
||||
this._view = new PostMainView({
|
||||
post: post,
|
||||
poolPostsNearby: poolPostsNearby,
|
||||
editMode: editMode,
|
||||
prevPostId: aroundPool
|
||||
? (aroundPool.previousPost ? aroundPool.previousPost.id : null)
|
||||
|
@ -16,9 +16,9 @@ class PoolNavigatorControl extends events.EventTarget {
|
||||
views.replaceContent(
|
||||
this._hostNode,
|
||||
template({
|
||||
pool: poolPostNearby.pool,
|
||||
parameters: { query: `pool:${poolPostNearby.pool.id}` },
|
||||
linkClass: misc.makeCssName(poolPostNearby.pool.category, "pool"),
|
||||
pool: poolPostNearby,
|
||||
parameters: { query: `pool:${poolPostNearby.id}` },
|
||||
linkClass: misc.makeCssName(poolPostNearby.category, "pool"),
|
||||
canViewPosts: api.hasPrivilege("posts:view"),
|
||||
canViewPools: api.hasPrivilege("pools:view"),
|
||||
firstPost: poolPostNearby.firstPost,
|
||||
|
@ -13,8 +13,8 @@ class PoolNavigatorListControl extends events.EventTarget {
|
||||
this._poolPostNearby = poolPostNearby;
|
||||
this._indexToNode = {};
|
||||
|
||||
for (let [i, entry] of this._poolPostNearby.entries()) {
|
||||
this._installPoolNavigatorNode(entry, i);
|
||||
for (const entry of this._poolPostNearby) {
|
||||
this._installPoolNavigatorNode(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class PoolNavigatorListControl extends events.EventTarget {
|
||||
return this._hostNode;
|
||||
}
|
||||
|
||||
_installPoolNavigatorNode(poolPostNearby, i) {
|
||||
_installPoolNavigatorNode(poolPostNearby) {
|
||||
const poolListItemNode = document.createElement("div");
|
||||
const poolControl = new PoolNavigatorControl(
|
||||
poolListItemNode,
|
||||
|
@ -36,7 +36,7 @@ class Pool extends events.EventTarget {
|
||||
}
|
||||
|
||||
get posts() {
|
||||
return this._posts;
|
||||
return this._postsMicro || this._posts;
|
||||
}
|
||||
|
||||
get postCount() {
|
||||
@ -51,6 +51,22 @@ class Pool extends events.EventTarget {
|
||||
return this._lastEditTime;
|
||||
}
|
||||
|
||||
get firstPost() {
|
||||
return this._firstPost;
|
||||
}
|
||||
|
||||
get lastPost() {
|
||||
return this._lastPost;
|
||||
}
|
||||
|
||||
get previousPost() {
|
||||
return this._previousPost;
|
||||
}
|
||||
|
||||
get nextPost() {
|
||||
return this._nextPost;
|
||||
}
|
||||
|
||||
set names(value) {
|
||||
this._names = value;
|
||||
}
|
||||
@ -169,10 +185,15 @@ class Pool extends events.EventTarget {
|
||||
_creationTime: response.creationTime,
|
||||
_lastEditTime: response.lastEditTime,
|
||||
_postCount: response.postCount || 0,
|
||||
_postsMicro: response.postsMicro,
|
||||
_firstPost: response.firstPost || null,
|
||||
_lastPost: response.lastPost || null,
|
||||
_previousPost: response.previousPost || null,
|
||||
_nextPost: response.nextPost || null,
|
||||
};
|
||||
|
||||
for (let obj of [this, this._orig]) {
|
||||
obj._posts.sync(response.posts);
|
||||
obj._posts.sync(response.posts || []);
|
||||
}
|
||||
|
||||
Object.assign(this, map);
|
||||
|
@ -16,14 +16,6 @@ class PostList extends AbstractList {
|
||||
);
|
||||
}
|
||||
|
||||
static getNearbyPoolPosts(id) {
|
||||
return api.get(
|
||||
uri.formatApiLink("post", id, "pools-nearby", {
|
||||
fields: "id",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
static search(text, offset, limit, fields) {
|
||||
return api
|
||||
.get(
|
||||
|
@ -30,7 +30,7 @@ class PoolCreateView extends events.EventTarget {
|
||||
}
|
||||
|
||||
for (let node of this._formNode.querySelectorAll(
|
||||
"input, select, textarea, posts"
|
||||
"input, select, textarea"
|
||||
)) {
|
||||
node.addEventListener("change", (e) => {
|
||||
this.dispatchEvent(new CustomEvent("change"));
|
||||
|
@ -58,7 +58,7 @@ class PostMainView {
|
||||
this._installSidebar(ctx);
|
||||
this._installCommentForm();
|
||||
this._installComments(ctx.post.comments);
|
||||
this._installPoolNavigators(ctx.poolPostsNearby);
|
||||
this._installPoolNavigators(ctx);
|
||||
|
||||
const showPreviousImage = () => {
|
||||
if (ctx.prevPostId) {
|
||||
@ -139,7 +139,7 @@ class PostMainView {
|
||||
}
|
||||
}
|
||||
|
||||
_installPoolNavigators(poolPostsNearby) {
|
||||
_installPoolNavigators(ctx) {
|
||||
const poolNavigatorsContainerNode = document.querySelector(
|
||||
"#content-holder .pool-navigators-container"
|
||||
);
|
||||
@ -149,7 +149,7 @@ class PostMainView {
|
||||
|
||||
this.poolNavigatorsControl = new PoolNavigatorListControl(
|
||||
poolNavigatorsContainerNode,
|
||||
poolPostsNearby,
|
||||
ctx.post.pools,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -281,19 +281,6 @@ def get_posts_around(
|
||||
ctx, post_id, lambda post: _serialize_post(ctx, post)
|
||||
)
|
||||
|
||||
@rest.routes.get("/post/(?P<post_id>[^/]+)/pools-nearby/?")
|
||||
def get_pools_around(
|
||||
ctx: rest.Context, params: Dict[str, str]
|
||||
) -> rest.Response:
|
||||
auth.verify_privilege(ctx.user, "posts:list")
|
||||
auth.verify_privilege(ctx.user, "posts:view")
|
||||
auth.verify_privilege(ctx.user, "pools:list")
|
||||
_search_executor_config.user = ctx.user
|
||||
post = _get_post(params)
|
||||
results = posts.get_pools_nearby(post)
|
||||
return posts.serialize_pool_posts_nearby(results)
|
||||
|
||||
|
||||
|
||||
@rest.routes.post("/posts/reverse-search/?")
|
||||
def get_posts_by_image(
|
||||
|
@ -108,6 +108,7 @@ class PoolSerializer(serialization.BaseSerializer):
|
||||
"lastEditTime": self.serialize_last_edit_time,
|
||||
"postCount": self.serialize_post_count,
|
||||
"posts": self.serialize_posts,
|
||||
"postsMicro": self.serialize_posts_micro,
|
||||
}
|
||||
|
||||
def serialize_id(self) -> Any:
|
||||
@ -143,6 +144,14 @@ class PoolSerializer(serialization.BaseSerializer):
|
||||
]
|
||||
]
|
||||
|
||||
def serialize_posts_micro(self) -> Any:
|
||||
posts_micro = []
|
||||
for i, rel in enumerate(self.pool.posts):
|
||||
posts_micro.append(posts.serialize_micro_post(rel, None))
|
||||
if i == 2:
|
||||
break
|
||||
return posts_micro
|
||||
|
||||
|
||||
def serialize_pool(
|
||||
pool: model.Pool, options: List[str] = []
|
||||
|
@ -9,6 +9,7 @@ import sqlalchemy as sa
|
||||
|
||||
from szurubooru import config, db, errors, model, rest
|
||||
from szurubooru.func import (
|
||||
auth,
|
||||
comments,
|
||||
files,
|
||||
image_hash,
|
||||
@ -345,8 +346,10 @@ class PostSerializer(serialization.BaseSerializer):
|
||||
]
|
||||
|
||||
def serialize_pools(self) -> List[Any]:
|
||||
if not auth.has_privilege(self.auth_user, "pools:list"):
|
||||
return []
|
||||
return [
|
||||
pools.serialize_micro_pool(pool)
|
||||
{**pools.serialize_micro_pool(pool), **get_pool_posts_nearby(self.post, pool)} if auth.has_privilege(self.auth_user, "pools:view") else pools.serialize_micro_pool(pool)
|
||||
for pool in sorted(
|
||||
self.post.pools, key=lambda pool: pool.creation_time
|
||||
)
|
||||
@ -977,14 +980,21 @@ def search_by_image(image_content: bytes) -> List[Tuple[float, model.Post]]:
|
||||
else:
|
||||
return []
|
||||
|
||||
PoolPostsNearby = namedtuple('PoolPostsNearby', 'pool first_post prev_post next_post last_post')
|
||||
def get_pools_nearby(
|
||||
post: model.Post
|
||||
) -> List[PoolPostsNearby]:
|
||||
response = []
|
||||
pools = post.pools
|
||||
def serialize_safe_post(
|
||||
post: Optional[model.Post]
|
||||
) -> rest.Response:
|
||||
return {"id": getattr(post, "post_id", None)} if post else None
|
||||
|
||||
for pool in pools:
|
||||
|
||||
def serialize_id_post(
|
||||
post_id: Optional[int]
|
||||
) -> rest.Response:
|
||||
return serialize_safe_post(try_get_post_by_id(post_id)) if post_id else None
|
||||
|
||||
|
||||
def get_pool_posts_nearby(
|
||||
post: model.Post, pool: model.Pool
|
||||
) -> rest.Response:
|
||||
prev_post_id = None
|
||||
next_post_id = None
|
||||
first_post_id = pool.posts[0].post_id,
|
||||
@ -998,25 +1008,9 @@ def get_pools_nearby(
|
||||
next_post_id = next_item.post_id
|
||||
break
|
||||
|
||||
resp_entry = PoolPostsNearby(
|
||||
pool=pool,
|
||||
first_post=first_post_id,
|
||||
last_post=last_post_id,
|
||||
prev_post=prev_post_id,
|
||||
next_post=next_post_id,
|
||||
)
|
||||
response.append(resp_entry)
|
||||
return response
|
||||
|
||||
def serialize_pool_posts_nearby(
|
||||
nearby: List[PoolPostsNearby]
|
||||
) -> Optional[rest.Response]:
|
||||
return [
|
||||
{
|
||||
"pool": pools.serialize_micro_pool(entry.pool),
|
||||
"firstPost": {"id": getattr(try_get_post_by_id(entry.first_post), "post_id", None)} if entry.first_post else None,
|
||||
"lastPost": {"id": getattr(try_get_post_by_id(entry.last_post), "post_id", None)} if entry.last_post else None,
|
||||
"previousPost": {"id": getattr(try_get_post_by_id(entry.prev_post), "post_id", None)} if entry.prev_post else None,
|
||||
"nextPost": {"id": getattr(try_get_post_by_id(entry.next_post), "post_id", None)} if entry.next_post else None,
|
||||
} for entry in nearby
|
||||
]
|
||||
return {
|
||||
"firstPost": serialize_id_post(first_post_id),
|
||||
"lastPost": serialize_id_post(last_post_id),
|
||||
"previousPost": serialize_id_post(prev_post_id),
|
||||
"nextPost": serialize_id_post(next_post_id),
|
||||
}
|
||||
|
@ -127,7 +127,8 @@ def test_trying_to_retrieve_single_without_privileges(
|
||||
{"post_id": 999},
|
||||
)
|
||||
|
||||
def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
||||
|
||||
def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_post_factory):
|
||||
p1 = post_factory(id=1)
|
||||
p2 = post_factory(id=2)
|
||||
p3 = post_factory(id=3)
|
||||
@ -139,42 +140,11 @@ def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_pos
|
||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
||||
db.session.add_all(pool_posts)
|
||||
|
||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 2})
|
||||
assert result[0]["previousPost"]["id"] == 1 and result[0]["nextPost"]["id"] == 3
|
||||
result = posts.get_pool_posts_nearby(p1, pool)
|
||||
assert result["previousPost"] == None and result["nextPost"]["id"] == 2
|
||||
|
||||
def test_get_pool_post_around_start(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
||||
p1 = post_factory(id=1)
|
||||
p2 = post_factory(id=2)
|
||||
p3 = post_factory(id=3)
|
||||
db.session.add_all([p1, p2, p3])
|
||||
result = posts.get_pool_posts_nearby(p2, pool)
|
||||
assert result["previousPost"]["id"] == 1 and result["nextPost"]["id"] == 3
|
||||
|
||||
pool = pool_factory(id=1)
|
||||
db.session.add(pool)
|
||||
|
||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
||||
db.session.add_all(pool_posts)
|
||||
|
||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 1})
|
||||
assert result[0]["previousPost"] == None and result[0]["nextPost"]["id"] == 2
|
||||
|
||||
def test_get_pool_post_around_end(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
||||
p1 = post_factory(id=1)
|
||||
p2 = post_factory(id=2)
|
||||
p3 = post_factory(id=3)
|
||||
db.session.add_all([p1, p2, p3])
|
||||
|
||||
pool = pool_factory(id=1)
|
||||
db.session.add(pool)
|
||||
|
||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
||||
db.session.add_all(pool_posts)
|
||||
|
||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 3})
|
||||
assert result[0]["previousPost"]["id"] == 2 and result[0]["nextPost"] == None
|
||||
|
||||
def test_get_pool_post_around_no_pool(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
||||
p1 = post_factory(id=1)
|
||||
db.session.add(p1)
|
||||
|
||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 1})
|
||||
assert result == []
|
||||
result = posts.get_pool_posts_nearby(p3, pool)
|
||||
assert result["previousPost"]["id"] == 2 and result["nextPost"] == None
|
||||
|
@ -105,7 +105,14 @@ def test_serialize_post(
|
||||
pool_category_factory,
|
||||
config_injector,
|
||||
):
|
||||
config_injector({"data_url": "http://example.com/", "secret": "test"})
|
||||
config_injector({
|
||||
"privileges": {
|
||||
"pools:list": model.User.RANK_REGULAR,
|
||||
"pools:view": model.User.RANK_REGULAR,
|
||||
},
|
||||
"data_url": "http://example.com/",
|
||||
"secret": "test"
|
||||
})
|
||||
with patch("szurubooru.func.comments.serialize_comment"), patch(
|
||||
"szurubooru.func.users.serialize_micro_user"
|
||||
), patch("szurubooru.func.posts.files.has"):
|
||||
@ -249,6 +256,10 @@ def test_serialize_post(
|
||||
"description": "desc",
|
||||
"category": "test-cat1",
|
||||
"postCount": 1,
|
||||
"firstPost": {"id": 1},
|
||||
"lastPost": {"id": 1},
|
||||
"previousPost": None,
|
||||
"nextPost": None,
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@ -256,6 +267,10 @@ def test_serialize_post(
|
||||
"description": "desc2",
|
||||
"category": "test-cat2",
|
||||
"postCount": 1,
|
||||
"firstPost": {"id": 1},
|
||||
"lastPost": {"id": 1},
|
||||
"previousPost": None,
|
||||
"nextPost": None,
|
||||
},
|
||||
],
|
||||
"user": "post author",
|
||||
|
@ -866,9 +866,9 @@ def test_tumbleweed(
|
||||
verify_unpaged("-special:tumbleweed", [1, 2, 3])
|
||||
|
||||
|
||||
def test_sort_pool(
|
||||
def test_sort_pool(
|
||||
post_factory, pool_factory, pool_category_factory, verify_unpaged
|
||||
):
|
||||
):
|
||||
post1 = post_factory(id=1)
|
||||
post2 = post_factory(id=2)
|
||||
post3 = post_factory(id=3)
|
||||
|
Reference in New Issue
Block a user