diff --git a/client/html/post_edit_sidebar.tpl b/client/html/post_edit_sidebar.tpl index d36a0e4..4283c25 100644 --- a/client/html/post_edit_sidebar.tpl +++ b/client/html/post_edit_sidebar.tpl @@ -4,7 +4,7 @@
- <% if (ctx.canEditPostSafety) { %> + <% if (ctx.enableSafety && ctx.canEditPostSafety) { %>
diff --git a/client/html/post_readonly_sidebar.tpl b/client/html/post_readonly_sidebar.tpl index f29c8b6..a03347e 100644 --- a/client/html/post_readonly_sidebar.tpl +++ b/client/html/post_readonly_sidebar.tpl @@ -20,10 +20,12 @@ <%= ctx.makeRelativeTime(ctx.post.creationTime) %>
-
- <%- ctx.post.safety[0].toUpperCase() + ctx.post.safety.slice(1) %> -
+ <% if (ctx.enableSafety) { %> +
+ <%- ctx.post.safety[0].toUpperCase() + ctx.post.safety.slice(1) %> +
+ <% } %>
Original zoom · diff --git a/client/html/post_upload_row.tpl b/client/html/post_upload_row.tpl index d62ecaf..a1ea46b 100644 --- a/client/html/post_upload_row.tpl +++ b/client/html/post_upload_row.tpl @@ -41,16 +41,18 @@
-
- <% for (let safety of ['safe', 'sketchy', 'unsafe']) { %> - <%= ctx.makeRadio({ - name: 'safety-' + ctx.uploadable.key, - value: safety, - text: safety[0].toUpperCase() + safety.substr(1), - selectedValue: ctx.uploadable.safety, - }) %> - <% } %> -
+ <% if (ctx.enableSafety) { %> +
+ <% for (let safety of ['safe', 'sketchy', 'unsafe']) { %> + <%= ctx.makeRadio({ + name: 'safety-' + ctx.uploadable.key, + value: safety, + text: safety[0].toUpperCase() + safety.substr(1), + selectedValue: ctx.uploadable.safety, + }) %> + <% } %> +
+ <% } %>
<% if (ctx.canUploadAnonymously) { %> diff --git a/client/html/posts_header.tpl b/client/html/posts_header.tpl index 29efd52..e0ba0ea 100644 --- a/client/html/posts_header.tpl +++ b/client/html/posts_header.tpl @@ -4,9 +4,11 @@ %><% %><% %><% - %>'/><% - %>'/><% - %>'/><% + %><% if (ctx.enableSafety) { %><% + %>'/><% + %>'/><% + %>'/><% + %><% } %><% %><% %>'>Syntax help<% %><% @@ -20,7 +22,7 @@ %>Stop tagging<% %><% %><% } %><% - %><% if (ctx.canBulkEditSafety) { %><% + %><% if (ctx.enableSafety && ctx.canBulkEditSafety) { %><% %>
<% %>Mass edit safety<% %>Stop editing safety<% diff --git a/client/js/controllers/post_list_controller.js b/client/js/controllers/post_list_controller.js index 12b354f..c857742 100644 --- a/client/js/controllers/post_list_controller.js +++ b/client/js/controllers/post_list_controller.js @@ -1,5 +1,6 @@ 'use strict'; +const config = require('../config.js'); const api = require('../api.js'); const settings = require('../models/settings.js'); const uri = require('../util/uri.js'); @@ -31,6 +32,7 @@ class PostListController { this._headerView = new PostsHeaderView({ hostNode: this._pageController.view.pageHeaderHolderNode, parameters: ctx.parameters, + enableSafety: config.enableSafety, canBulkEditTags: api.hasPrivilege('posts:bulkEdit:tags'), canBulkEditSafety: api.hasPrivilege('posts:bulkEdit:safety'), bulkEdit: { @@ -79,20 +81,6 @@ class PostListController { e.detail.post.save().catch(error => window.alert(error.message)); } - _decorateSearchQuery(text) { - const browsingSettings = settings.get(); - let disabledSafety = []; - for (let key of Object.keys(browsingSettings.listPosts)) { - if (browsingSettings.listPosts[key] === false) { - disabledSafety.push(key); - } - } - if (disabledSafety.length) { - text = `-rating:${disabledSafety.join(',')} ${text}`; - } - return text.trim(); - } - _syncPageController() { this._pageController.run({ parameters: this._ctx.parameters, @@ -104,9 +92,7 @@ class PostListController { }, requestPage: (offset, limit) => { return PostList.search( - this._decorateSearchQuery( - this._ctx.parameters.query || ''), - offset, limit, fields); + this._ctx.parameters.query, offset, limit, fields); }, pageRenderer: pageCtx => { Object.assign(pageCtx, { diff --git a/client/js/controllers/post_main_controller.js b/client/js/controllers/post_main_controller.js index c672a0f..bb1fd59 100644 --- a/client/js/controllers/post_main_controller.js +++ b/client/js/controllers/post_main_controller.js @@ -20,8 +20,8 @@ class PostMainController extends BasePostController { Promise.all([ Post.get(ctx.parameters.id), PostList.getAround( - ctx.parameters.id, this._decorateSearchQuery( - parameters ? parameters.query || '' : '')), + ctx.parameters.id, + parameters ? parameters.query : null), ]).then(responses => { const [post, aroundResponse] = responses; @@ -91,20 +91,6 @@ class PostMainController extends BasePostController { }); } - _decorateSearchQuery(text) { - const browsingSettings = settings.get(); - let disabledSafety = []; - for (let key of Object.keys(browsingSettings.listPosts)) { - if (browsingSettings.listPosts[key] === false) { - disabledSafety.push(key); - } - } - if (disabledSafety.length) { - text = `-rating:${disabledSafety.join(',')} ${text}`; - } - return text.trim(); - } - _evtFitModeChange(e) { const browsingSettings = settings.get(); browsingSettings.fitMode = e.detail.mode; diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index 977ac2b..3c32641 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -1,6 +1,7 @@ 'use strict'; const api = require('../api.js'); +const config = require('../config.js'); const router = require('../router.js'); const uri = require('../util/uri.js'); const misc = require('../util/misc.js'); @@ -29,6 +30,7 @@ class PostUploadController { this._view = new PostUploadView({ canUploadAnonymously: api.hasPrivilege('posts:create:anonymous'), canViewPosts: api.hasPrivilege('posts:view'), + enableSafety: config.enableSafety, }); this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtSubmit(e)); diff --git a/client/js/controllers/user_list_controller.js b/client/js/controllers/user_list_controller.js index 5cf4b2b..16f3b9b 100644 --- a/client/js/controllers/user_list_controller.js +++ b/client/js/controllers/user_list_controller.js @@ -57,7 +57,7 @@ class UserListController { }, requestPage: (offset, limit) => { return UserList.search( - this._ctx.parameters.query || '', offset, limit); + this._ctx.parameters.query, offset, limit); }, pageRenderer: pageCtx => { Object.assign(pageCtx, { diff --git a/client/js/controls/post_edit_sidebar_control.js b/client/js/controls/post_edit_sidebar_control.js index 3da2fa4..3c3f59d 100644 --- a/client/js/controls/post_edit_sidebar_control.js +++ b/client/js/controls/post_edit_sidebar_control.js @@ -1,6 +1,7 @@ 'use strict'; const api = require('../api.js'); +const config = require('../config.js'); const events = require('../events.js'); const misc = require('../util/misc.js'); const views = require('../util/views.js'); @@ -23,6 +24,7 @@ class PostEditSidebarControl extends events.EventTarget { views.replaceContent(this._hostNode, template({ post: this._post, + enableSafety: config.enableSafety, canEditPostSafety: api.hasPrivilege('posts:edit:safety'), canEditPostSource: api.hasPrivilege('posts:edit:source'), canEditPostTags: api.hasPrivilege('posts:edit:tags'), diff --git a/client/js/controls/post_readonly_sidebar_control.js b/client/js/controls/post_readonly_sidebar_control.js index 2be4d6b..30edd41 100644 --- a/client/js/controls/post_readonly_sidebar_control.js +++ b/client/js/controls/post_readonly_sidebar_control.js @@ -1,6 +1,7 @@ 'use strict'; const api = require('../api.js'); +const config = require('../config.js'); const events = require('../events.js'); const tags = require('../tags.js'); const views = require('../util/views.js'); @@ -23,6 +24,7 @@ class PostReadonlySidebarControl extends events.EventTarget { post: this._post, getTagCategory: this._getTagCategory, getTagUsages: this._getTagUsages, + enableSafety: config.enableSafety, canListPosts: api.hasPrivilege('posts:list'), canEditPosts: api.hasPrivilege('posts:edit'), canViewTags: api.hasPrivilege('tags:view'), diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 244e781..2e3c6fc 100644 --- a/client/js/models/post_list.js +++ b/client/js/models/post_list.js @@ -1,5 +1,7 @@ 'use strict'; +const settings = require('../models/settings.js'); +const config = require('../config.js'); const api = require('../api.js'); const uri = require('../util/uri.js'); const AbstractList = require('./abstract_list.js'); @@ -9,14 +11,17 @@ class PostList extends AbstractList { static getAround(id, searchQuery) { return api.get( uri.formatApiLink( - 'post', id, 'around', {query: searchQuery, fields: 'id'})); + 'post', id, 'around', { + query: PostList._decorateSearchQuery(searchQuery || ''), + fields: 'id', + })); } static search(text, offset, limit, fields) { return api.get( uri.formatApiLink( 'posts', { - query: text, + query: PostList._decorateSearchQuery(text || ''), offset: offset, limit: limit, fields: fields.join(','), @@ -28,6 +33,23 @@ class PostList extends AbstractList { {results: PostList.fromResponse(response.results)})); }); } + + static _decorateSearchQuery(text) { + const browsingSettings = settings.get(); + const disabledSafety = []; + if (config.enableSafety) { + for (let key of Object.keys(browsingSettings.listPosts)) { + if (browsingSettings.listPosts[key] === false) { + disabledSafety.push(key); + } + } + if (disabledSafety.length) { + text = `-rating:${disabledSafety.join(',')} ${text}`; + } + } + return text.trim(); + } + } PostList._itemClass = Post; diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index f80135f..32b10bd 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -277,14 +277,20 @@ class PostUploadView extends events.EventTarget { _updateUploadableFromDom(uploadable) { const rowNode = uploadable.rowNode; - uploadable.safety = - rowNode.querySelector('.safety input:checked').value; + + const safetyNode = rowNode.querySelector('.safety input:checked'); + if (safetyNode) { + uploadable.safety = safetyNode.value; + } + uploadable.anonymous = rowNode.querySelector('.anonymous input').checked; + uploadable.flags = []; if (rowNode.querySelector('.loop-video input:checked')) { uploadable.flags.push('loop'); } + uploadable.tags = []; uploadable.relations = []; for (let [i, lookalike] of uploadable.lookalikes.entries()) { diff --git a/config.yaml.dist b/config.yaml.dist index 780597c..b4d8832 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -46,6 +46,8 @@ elasticsearch: index: szurubooru +enable_safety: yes + tag_name_regex: ^\S+$ tag_category_name_regex: ^[^\s%+#/]+$