Skip to content

Commit

Permalink
fix(MDU): Level Requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
fzlins committed Jul 31, 2023
1 parent 8e0aeb7 commit 820c19d
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 7 deletions.
4 changes: 3 additions & 1 deletion resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
"bonus": "Bonus",
"seedingPoints": "Seeding Points",
"seedingTime": "Seeding Time",
"averageSeedtime": "Average Seedtime",
"bonusPerHour": "Bonus per hour",
"joinTime": "Join time",
"lastUpdateTime": "Update at",
Expand All @@ -230,7 +231,8 @@
"classPoints": "Class Points",
"uniqueGroups": "Unique Groups",
"perfectFLAC": "\"Perfect\" FLAC",
"alternative": "Alternative"
"alternative": "Alternative",
"days": "Days"
},
"tip": "N/A means no support",
"nodata": "You have not added a site, please go to [Sites] to add a site."
Expand Down
4 changes: 3 additions & 1 deletion resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
"seeding": "做种数",
"seedingSize": "做种体积",
"seedingTime": "做种时间",
"averageSeedtime": "平均做种时间",
"bonus": "魔力值",
"seedingPoints": "做种积分",
"bonusPerHour": "时魔",
Expand All @@ -225,7 +226,8 @@
"classPoints": "等级积分",
"uniqueGroups": "独特分组",
"perfectFLAC": "“完美”FLAC",
"alternative": "择一"
"alternative": "择一",
"days": ""
},
"tip": "N/A 表示暂不支持",
"nodata": "您还没有添加站点,请前往『站点设置』添加站点。"
Expand Down
5 changes: 5 additions & 0 deletions resource/schemas/UNIT3D/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
"selector": ["a[href$='unsatisfieds']:first"],
"attribute": "href",
"filters": ["query ? new URL(query).pathname : null"]
},
"averageSeedtime": {
"selector": ["table.table-condensed.table-striped.table-bordered:first td:contains('Average Seedtime') + td", "table.table-condensed.table-striped.table-bordered:first td:contains('平均做种时间') + td", "table.table-condensed.table-striped.table-bordered:first td:contains('平均做種時間') + td",
"dt:contains('Average Seedtime') + dd", "dt:contains('平均做种时间') + dd", "dt:contains('平均做種時間') + dd"],
"filters": ["query.text().trim().timeToDays()"]
}
}
},
Expand Down
24 changes: 20 additions & 4 deletions resource/sites/monikadesign.uk/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,41 @@
"name": "SuperUser",
"interval": "8",
"uploaded": "2TB",
"privilege": ""
"privilege": "访问邀请区"
},{
"level": "3",
"name": "ExtremeUser",
"interval": "12",
"uploaded": "5TB",
"privilege": ""
"privilege": "自动通过候选;访问邀请区"
},{
"level": "4",
"name": "InsaneUser",
"interval": "18",
"uploaded": "10TB",
"privilege": "自动通过候选"
"privilege": "自动通过候选;访问邀请区"
},{
"level": "5",
"name": "Veteran",
"interval": "36",
"uploaded": "15TB",
"privilege": "个人全局双倍上传"
"privilege": "个人全局双倍上传;自动通过候选;访问邀请区"
},
{
"level": "6",
"name": "Seeder",
"interval": "4",
"seedingSize": "3TB",
"averageSeedtime": "30",
"privilege": "自动通过候选;访问邀请区"
},
{
"level": "7",
"name": "Archivist",
"interval": "12",
"seedingSize": "10TB",
"averageSeedtime": "60",
"privilege": "个人全局免费;自动通过候选;访问邀请区"
}],
"collaborator": "fzlins",
"searchEntryConfig": {
Expand Down
6 changes: 5 additions & 1 deletion src/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ export interface LevelRequirement {
seedingPoints?: number;
// 做种时间要求
seedingTime?: number;
// 平均保种时间要求
averageSeedtime?: number;
// 保种体积要求
seedingSize?: number;
seedingSize?: string | number;
// 分享率要求
ratio?: number;
// 等级积分要求
Expand Down Expand Up @@ -591,6 +593,8 @@ export interface UserInfo {
seedingPoints?: number;
// 做种时间要求
seedingTime?: number;
// 平均保种时间
averageSeedtime?: number;
// 时魔
bonusPerHour?: number;
// 积分页面
Expand Down
39 changes: 39 additions & 0 deletions src/interface/types.expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,42 @@ String.prototype.sizeToNumber = function() {
}
return 0;
};

/**
* @return {number}
*/
String.prototype.timeToDays = function() {
const timeMatch = this.match(/\d+[天周月年DWMY]/g);
let length = 0;
if (timeMatch == null)
return 0;

timeMatch.forEach(time => {
const timeMatch = time.match(/(\d+)([天周月年DWMY])/);
if (timeMatch == null)
return 0;

const number = parseInt(timeMatch[1])
const unit = timeMatch[2]
switch (true) {
case unit === 'D':
case unit === '天':
length += number;
break;
case unit === 'W':
case unit === '周':
length += number;
break;
case unit === 'M':
case unit === '月':
length += number * 30;
break;
case unit === 'Y':
case unit === '年':
length += number * 365;
break;
default:
}
})
return length;
};
56 changes: 56 additions & 0 deletions src/options/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
nextLevel.bonus | formatNumber
}} 
</template>
<template v-if="nextLevel.seedingSize">
<v-icon small color="blue darken-4">dns</v-icon>{{
nextLevel.seedingSize | formatSize
}}&nbsp;
</template>
<template v-if="nextLevel.seedingPoints">
<v-icon small color="green darken-4">energy_savings_leaf</v-icon>{{
nextLevel.seedingPoints | formatNumber
Expand All @@ -137,6 +142,11 @@
nextLevel.seedingTime | formatNumber
}}&nbsp;
</template>
<template v-if="nextLevel.averageSeedtime">
<v-icon small color="green darken-4">timer</v-icon>{{
nextLevel.averageSeedtime | formatNumber
}}{{$t("home.levelRequirement.days")}}&nbsp;
</template>
<template v-if="nextLevel.uploads">
<v-icon small color="green darken-4">file_upload</v-icon>{{ nextLevel.uploads
}}&nbsp;
Expand Down Expand Up @@ -196,6 +206,9 @@
formatInteger
}};
</template>
<template v-if="levelRequirement.seedingSize">
<v-icon small color="blue darken-4" :title="$t('home.levelRequirement.seedingSize')">dns</v-icon>{{ levelRequirement.seedingSize }};
</template>
<template v-if="levelRequirement.seedingPoints">
<v-icon small color="green darken-4" :title="$t('home.levelRequirement.seedingPoints')">energy_savings_leaf</v-icon>{{ levelRequirement.seedingPoints
| formatInteger
Expand All @@ -206,6 +219,11 @@
| formatInteger
}};
</template>
<template v-if="levelRequirement.averageSeedtime">
<v-icon small color="green darken-4" :title="$t('home.levelRequirement.averageSeedtime')">timer</v-icon>{{ levelRequirement.averageSeedtime
| formatInteger
}}{{$t("home.levelRequirement.days")}};
</template>
<template v-if="levelRequirement.classPoints">
<v-icon small color="yellow darken-4" :title="$t('home.levelRequirement.classPoints')">energy_savings_leaf</v-icon>{{ levelRequirement.classPoints
| formatInteger
Expand Down Expand Up @@ -251,6 +269,9 @@
formatInteger
}};
</template>
<template v-if="option.seedingSize">
<v-icon small color="blue darken-4" :title="$t('home.levelRequirement.seedingSize')">dns</v-icon>{{ option.seedingSize }};
</template>
<template v-if="option.seedingPoints">
<v-icon small color="green darken-4" :title="$t('home.levelRequirement.seedingPoints')">energy_savings_leaf</v-icon>{{ option.seedingPoints
| formatInteger
Expand All @@ -261,6 +282,11 @@
| formatInteger
}};
</template>
<template v-if="option.averageSeedtime">
<v-icon small color="green darken-4" :title="$t('home.levelRequirement.averageSeedtime')">timer</v-icon>{{ option.averageSeedtime
| formatInteger
}}{{$t("home.levelRequirement.days")}};
</template>
<template v-if="option.classPoints">
<v-icon small color="yellow darken-4" :title="$t('home.levelRequirement.classPoints')">energy_savings_leaf</v-icon>{{ option.classPoints
| formatInteger
Expand Down Expand Up @@ -662,7 +688,19 @@ export default Vue.extend({
}
user.nextLevels = [] as LevelRequirement[];
let userLevel = -1;
for (var levelRequirement of site.levelRequirements) {
if (user.levelName?.trim() == levelRequirement.name?.trim())
{
userLevel = levelRequirement.level as number;
break;
}
}
for (var levelRequirement of site.levelRequirements) {
if (levelRequirement.level as number < userLevel)
continue;
if (levelRequirement.alternative)
{
for (var option of levelRequirement.alternative)
Expand Down Expand Up @@ -779,6 +817,15 @@ export default Vue.extend({
}
}
if (levelRequirement.seedingSize) {
let requiredSeedingSize = this.fileSizetoLength(levelRequirement.seedingSize as string);
let userSeedingSize = user.seedingSize ? user.seedingSize : 0 ;
if (userSeedingSize < requiredSeedingSize) {
nextLevel.seedingSize = requiredSeedingSize - userSeedingSize;
nextLevel.level = levelRequirement.level;
}
}
if (levelRequirement.seedingTime) {
let userSeedingTime = user.seedingTime as number;
let requiredSeedingTime = levelRequirement.seedingTime as number;
Expand All @@ -788,6 +835,15 @@ export default Vue.extend({
}
}
if (levelRequirement.averageSeedtime) {
let userAverageSeedtime = user.averageSeedtime as number;
let requiredAverageSeedtime = levelRequirement.averageSeedtime as number;
if (userAverageSeedtime < requiredAverageSeedtime) {
nextLevel.averageSeedtime = requiredAverageSeedtime - userAverageSeedtime;
nextLevel.level = levelRequirement.level;
}
}
if (levelRequirement.uploads) {
let userUploads = user.uploads ? user.uploads as number : 0;
let requiredUploads = levelRequirement.uploads as number;
Expand Down

0 comments on commit 820c19d

Please sign in to comment.