Skip to content

Commit

Permalink
feat: new user model (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaoNeng-wWw authored Feb 24, 2024
1 parent 2e01848 commit d8d2a01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
27 changes: 12 additions & 15 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,23 @@ export default function Page() {

function updateInfo() {
UserAPI.getExtendedInformation().then((r) => {
if (r == undefined) {
if (!r) {
router.push("/authenticate");
return;
}
let user = r;
let price = getGroupPrice(r!.extend!.userGroup);
setUsed(Number((user.extend!.storageUsed / 1024 / 1024).toFixed(2)));
let price = getGroupPrice(r!.level!.level);
setUsed(Number((user.used_space / 1024 / 1024).toFixed(2)));
setTotal(Number(price.allSpace.substring(0, price.allSpace.length - 3)) * 1024);
setGroup(price);
setGroupColor(getPriceColor(r!.extend!.userGroup as "free" | "started" | "advanced" | "professional"))
if (user.extend!.groupStartDate != undefined || user.extend!.groupEndDate != undefined) {
if (user.extend!.groupStartDate != 0 && user.extend!.groupEndDate != 0) {
let startDate = user.extend!.groupStartDate!;
let endDate = user.extend!.groupEndDate!;
let now = new Date().getTime() / 1000;
let validDate = new Date(endDate * 1000);

setTimeLeft(100 - (now - startDate) / (endDate - startDate) * 100);
setTimeDescription(validDate.toLocaleDateString() + " 过期");
}
setGroupColor(getPriceColor(r!.level.level as "free" | "started" | "advanced" | "professional"))
const {start, end} = user.level;
const [startDate, endDate] = [new Date(start).getTime(), new Date(end).getTime()]
if (start || end){
const now = new Date().getTime() / 1000;
const valideDate = new Date(endDate * 1000);
setTimeLeft(100 - (now - startDate) / (endDate - startDate) * 100);
setTimeDescription(valideDate.toLocaleDateString() + "过期");
}
})
PictureAPI.getPicturesList().then((r) => {
Expand Down Expand Up @@ -225,4 +222,4 @@ export default function Page() {
{!certify && <Cert/>}
</div>
)
}
}
23 changes: 16 additions & 7 deletions interface/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ export interface Extend {
groupEndDate?: number;
}

export interface Level {
level: string
start: string
end: string
}

export interface UserModel {
uid: number;
username: string;
email: string;
createTime: string;
updateTime: string;
extend?: Extend;
cert?: boolean;
id: number
username: string
phone: string
email: any
available: boolean
level: Level
root: number
used_space: number
create_time: string
update_time: string
}

export interface LoginData {
Expand Down

0 comments on commit d8d2a01

Please sign in to comment.