Skip to content

Commit b816c38

Browse files
committed
BREAKING CHANGE: remove name history length limit
1 parent 42b26bf commit b816c38

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

config.example.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ render:
2525

2626
api:
2727
ratelimit: 2 # set to 1 request per sec as per mojang api rate limit
28-
max-name-history: 3 # Maximum history will be recorded
2928

3029
# Set advancements progresses
3130
# Details: http://minecraft.gamepedia.com/Advancements

utils.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,16 @@ export default class Utils {
183183

184184
async getNameHistory(uuid) {
185185
const apiNameHistory = `https://api.mojang.com/user/profiles/${uuid}/names`;
186-
const history = [];
187-
let res;
186+
let history;
188187
try {
189-
res = await this.getMojangAPI(apiNameHistory);
188+
history = await this.getMojangAPI(apiNameHistory);
190189
} catch (err) {
191190
return null;
192191
}
193-
if (!res) return null;
194-
let limit = this.config.api['max-name-history'];
195-
if (res.length < this.config.api['max-name-history']) {
196-
limit = res.length;
197-
}
198-
for (let i = 1; i <= limit; i += 1) {
199-
history.push(res[res.length - i]);
200-
}
192+
if (!history) return null;
193+
// The order of the response data from Mojang API is uncertain,
194+
// so manually sort it (to descending order) for making sure.
195+
history.sort((a, b) => (b.changedToAt || 0) - (a.changedToAt || 0))
201196
return history;
202197
}
203198

web/src/assets/lang.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@
386386
"nyaa.general.search_placeholder": "Search player by name / UUID",
387387
"nyaa.general.go_random_player": "Feel lucky",
388388
"nyaa.general.go_random_player_again": "One more luck",
389-
"nyaa.general.loading_hint": "Loading...",
390389
"nyaa.app_menu.section_title.others": "Others",
391390
"nyaa.home.explore_link_label": "Explore",
392391
"nyaa.home.starring_number.uptime": "Uptime",
@@ -782,7 +781,6 @@
782781
"nyaa.general.search_placeholder": "按名称 / UUID 搜索玩家",
783782
"nyaa.general.go_random_player": "随机查看",
784783
"nyaa.general.go_random_player_again": "再随机一次",
785-
"nyaa.general.loading_hint": "加载中…",
786784
"nyaa.app_menu.section_title.others": "其他",
787785
"nyaa.home.explore_link_label": "去看看",
788786
"nyaa.home.starring_number.uptime": "世界历时",

web/src/components/PlayerNameHistory.vue

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
<strong class="font-normal mr-3">{{ name }}</strong>
1010
<span class="ml-auto text-gray-500 font-tnum">{{ formatDate(changedToAt) || t('nyaa.player_name_history.first_name') }}</span>
1111
</li>
12-
<li v-if="isLoadingNameHistory" class="p-3 border-t first:border-t-0 border-gray-300 bg-gray-100 text-gray-500 flex items-center">{{ t('nyaa.general.loading_hint') }}</li>
1312
</ul>
1413
</PlayerAsidePanel>
1514
</template>
1615

1716
<script>
18-
import axios from 'axios'
19-
2017
import PlayerAsidePanel from '@/components/PlayerAsidePanel.vue'
2118
import {normalizeDate} from '@/common/utils'
2219
@@ -37,7 +34,6 @@
3734
data () {
3835
return {
3936
names: this.player.data.names,
40-
isLoadingNameHistory: true,
4137
}
4238
},
4339
@@ -53,24 +49,7 @@
5349
},
5450
},
5551
56-
created () {
57-
this.loadNameHistory()
58-
},
59-
6052
methods: {
61-
async loadNameHistory () {
62-
if (this.names.slice(-1)[0].changedToAt) {
63-
const {data} = await axios(
64-
process.env.NODE_ENV === 'development'
65-
? `/mojang-api/user/profiles/${this.player.data.uuid_short}/names`
66-
: `https://mojang-api.silent.land/${location.host}/user/profiles/${this.player.data.uuid_short}/names`
67-
)
68-
this.names = data.reverse()
69-
}
70-
71-
this.isLoadingNameHistory = false
72-
},
73-
7453
formatDate (val) {
7554
return val && normalizeDate(val, 'short')
7655
},

0 commit comments

Comments
 (0)