fix score calculation at upload page (fix #174)

This commit is contained in:
Pig Fang 2020-05-29 10:34:48 +08:00
parent 6f55045f9e
commit 46223eba4f
5 changed files with 24 additions and 13 deletions

View File

@ -171,10 +171,11 @@ class SkinlibController extends Controller
'skinlib.upload.private-score-notice',
['score' => option('private_score_per_storage')]
),
'scorePublic' => intval(option('score_per_storage')),
'scorePrivate' => intval(option('private_score_per_storage')),
'closetItemCost' => intval(option('score_per_closet_item')),
'award' => intval(option('score_award_per_texture')),
'score' => (int) auth()->user()->score,
'scorePublic' => (int) option('score_per_storage'),
'scorePrivate' => (int) option('private_score_per_storage'),
'closetItemCost' => (int) option('score_per_closet_item'),
'award' => (int) option('score_award_per_texture'),
'contentPolicy' => $parsedown->text(option_localized('content_policy')),
]);
}

View File

@ -24,6 +24,7 @@ const Upload: React.FC = () => {
const contentPolicy = useBlessingExtra<string>('contentPolicy')
const privacyNotice = useBlessingExtra<string>('privacyNotice')
const award = useBlessingExtra<number>('award')
const currentScore = useBlessingExtra<number>('score', 0)
const scorePublic = useBlessingExtra<number>('scorePublic')
const scorePrivate = useBlessingExtra<number>('scorePrivate')
const closetItemCost = useBlessingExtra<number>('closetItemCost')
@ -108,7 +109,7 @@ const Upload: React.FC = () => {
const costRatio = isPrivate ? scorePrivate : scorePublic
const size = file?.size ?? 0
const scoreCost = (~~(size / 1024) || 1) * costRatio + closetItemCost
const scoreCost = Math.ceil(size / 1024) * costRatio + closetItemCost
return (
<>
@ -209,18 +210,24 @@ const Upload: React.FC = () => {
</button>
</div>
{file && (
<div className="callout callout-success mt-3">
<p>{t('skinlib.upload.cost', { score: scoreCost })}</p>
<div
className={`callout callout-${
currentScore > scoreCost ? 'success' : 'danger'
} mt-3`}
>
<div>{t('skinlib.upload.cost', { score: scoreCost })}</div>
<div>
{t('user.cur-score')}
<span className="ml-1">{currentScore}</span>
</div>
</div>
)}
{isPrivate && (
<div className="callout callout-info mt-3">
<p>{privacyNotice}</p>
</div>
<div className="callout callout-info mt-3">{privacyNotice}</div>
)}
{!isPrivate && award > 0 && (
<div className="callout callout-success mt-3">
<p>{t('skinlib.upload.award', { score: award })}</p>
{t('skinlib.upload.award', { score: award })}
</div>
)}
</div>

View File

@ -16,6 +16,7 @@ beforeEach(() => {
window.blessing.extra = {
rule: 'rule',
privacyNotice: 'privacy notice',
score: 15,
scorePrivate: 10,
scorePublic: 1,
closetItemCost: 10,
@ -132,7 +133,7 @@ describe('score cost', () => {
it('public texture', () => {
const { getByTitle, queryByText } = render(<Upload />)
const file = new File([], 't.png')
const file = new File(['content'], 't.png')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})
@ -145,7 +146,7 @@ describe('score cost', () => {
it('private texture', () => {
const { getByTitle, getByLabelText, queryByText } = render(<Upload />)
const file = new File([], 't.png')
const file = new File(['content'], 't.png')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})

View File

@ -75,6 +75,7 @@
- Fixed that duplicated player name is not detected when updating player name in administration panel.
- Fixed that normal administrator can set other user as administrator.
- Fixed that texture file won't be deleted when deleting texture in reports management.
- Fixed that score calculation at upload page isn't consistent with that at back-end.
## Removed

View File

@ -75,6 +75,7 @@
- 修复在管理面板中修改角色名时不检测角色名是否重复的问题
- 修复普通管理员可设置其他用户为管理员的问题
- 修复处理举报中删除材质时不删除材质文件的问题
- 修复「材质上传」页面的积分计算与后端不一致的问题
## 移除